Hello all,
My name is Pawel and this is my first post on this forum.
I would like to set up node, to take MQTT input and display on the MAX7219 device using Node-Red and Raspberry Pi4. I have python script downloaded from GitHub that working very well, but I would like to take message from MQTT node and display on the screen.
Please see below python script: I would like to replace msg = "Test Message"
with MQTT input.
So I have tried
msg = msg.payload
msg = msg
But no luck.
Working Script:
import sys
import re
import time
import argparse
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
def demo(n, block_orientation, rotate, inreverse):
# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=n or 0, block_orientation=block_orientation,
rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
# start demo
msg = "Test Message"
show_message(device, msg, fill="white", font=proportional(CP437_FONT))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='matrix_demo arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')
args = parser.parse_args()
try:
demo(args.cascaded, args.block_orientation, args.rotate, args.reverse_order)
except KeyboardInterrupt:
pass
[{"id":"d65ba77d.7a5d98","type":"python3-function","z":"c60843c1.d6316","name":"python3_LCD","func":"import sys\nimport re\nimport time\nimport argparse\n\nfrom luma.led_matrix.device import max7219\nfrom luma.core.interface.serial import spi, noop\nfrom luma.core.render import canvas\nfrom luma.core.virtual import viewport\nfrom luma.core.legacy import text, show_message\nfrom luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT\n\n\n\ndef demo(n, block_orientation, rotate, inreverse):\n # create matrix device\n serial = spi(port=0, device=0, gpio=noop())\n device = max7219(serial, cascaded=n or 0, block_orientation=block_orientation,\n rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)\n\n\n # start demo\n\n\n msg = \"Test Message\"\n\n show_message(device, msg, fill=\"white\", font=proportional(CP437_FONT))\n\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(description='matrix_demo arguments',\n formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n\n parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')\n parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')\n parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')\n parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')\n\n args = parser.parse_args()\n\n try:\n demo(args.cascaded, args.block_orientation, args.rotate, args.reverse_order)\n \n\n except KeyboardInterrupt:\n pass\n","outputs":1,"x":620,"y":180,"wires":[["365e3b6.71afcc4"]],"inputLabels":["payload"]},{"id":"365e3b6.71afcc4","type":"debug","z":"c60843c1.d6316","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":830,"y":180,"wires":[]},{"id":"fcefdc2e.ec1ae","type":"inject","z":"c60843c1.d6316","name":"","topic":"test","payload":"testpayload","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":180,"wires":[["d65ba77d.7a5d98"]]}]
Best regards
Pawel