This repo is a snapshot of all files and python script needed to have time and messages displayed on a MatrixPortal. This project uses an MQTT broker for obtaining the time as well as displaying custom messages. There is also support for using Bitmap Pixel Art and Animation. If you rather use a PyPortal, check out the pyportal_station project.
Adafruit_CircuitPython_MiniMQTT: Using commit 407bb4f
Adafruit_CircuitPython_MatrixPortal: Baseline from commit 6f1d9d4 and removing all the code I did not need.
Besides the 2 libraries above, this project uses the following awesome libraries from the bundle 7.x 20220730:
Found device at /Volumes/CIRCUITPY, running CircuitPython 7.3.2.
- adafruit_bitmap_font==1.5.8
- adafruit_bus_device==5.2.0
- adafruit_display_shapes==2.5.1
- adafruit_display_text==2.22.7
- adafruit_esp32spi==5.0.0
- adafruit_logging==4.1.3
- adafruit_minimqtt==0.0.0-auto.0
- adafruit_pixelbuf==1.1.5
- adafruit_requests==1.12.4
- neopixel==6.3.3
But you can probably use newer versions of the 7.x bundle.
The key components are the Adafruit Matrix Portal and the 64x32 RGB LED Matrix - 6mm pitch from Adafruit.
Plugging the MatrixPortal directly on the HUB 75 socket made it stick out and that was not well suited for this project. I had to come up with an adaptor. Take a look at thingiverse 4850550 for info on the brackets I made and printed for the clock, as well as the accessories used.
Make sure to create a file called secrets.py to include info on the wifi as well as the MQTT broker you will connect to. Use secrets.py.sample as reference.
# NOTE: Do not do this before backing up all files!!!
>>> import storage ; storage.erase_filesystem()
# First, get to the REPL prompt so the board will not auto-restart as
# you copy files into it
# Assuming that MatrixPortal is mounted under /Volumes/CIRCUITPY
$ cd ${THIS_REPO_DIR}
$ [ -d /Volumes/CIRCUITPY/ ] && \
rm -rf /Volumes/CIRCUITPY/* && \
(tar czf - *) | ( cd /Volumes/CIRCUITPY ; tar xzvf - ) && \
echo ok || echo not_okay
Once MQTT is connected, this code expects an MQTT message to be sent to it -- at least once -- so it can learn what the local time is. See _parse_localtime_message() for an example of what that looks like
topic: /aio/local_time payload: 2021-05-18 23:23:36.339 015 5 -0500 EST
These are the MQTT topics you can publish to the clock:
mqtt_topic = secrets.get("topic_prefix") or "/matrixportal"
mqtt_pub_status = f"{mqtt_topic}/status"
mqtt_subs = {
f"{mqtt_topic}/ping": _parse_ping,
f"{mqtt_topic}/brightness": _parse_brightness,
f"{mqtt_topic}/neopixel": _parse_neopixel,
f"{mqtt_topic}/blinkrate": _parse_blinkrate,
f"{mqtt_topic}/msg": _parse_msg_message,
f"{mqtt_topic}/img": _parse_img,
"/aio/local_time": _parse_localtime_message,
"/sensor/temperature_outside": _parse_temperature_outside,
}
Example commands
PREFIX='matrix_portal'
MQTT=192.168.10.238
# Subscribing to status messages
mosquitto_sub -F '@Y-@m-@dT@H:@M:@S@z : %q : %t : %p' -h $MQTT -t "${PREFIX}/status"
# Request general info
mosquitto_pub -h $MQTT -t "${PREFIX}/ping" -r -n
# Turn screen on/off
mosquitto_pub -h $MQTT -t "${PREFIX}/brightness" -m on
mosquitto_pub -h $MQTT -t "${PREFIX}/brightness" -m off
# Neopixel control
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0 ; # off
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff ; # blue
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff00 ; # green
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff0000 ; # red
# On board led blink
mosquitto_pub -h $MQTT -t "${PREFIX}/blinkrate" -m 0 ; # off
mosquitto_pub -h $MQTT -t "${PREFIX}/blinkrate" -m 0.1 ; # 100ms
# Messages
mosquitto_pub -h $MQTT -t "${PREFIX}/msg" -m foo
mosquitto_pub -h $MQTT -t "${PREFIX}/msg" -m \
'{"msg": "hello", "text_color": "#0x595dff", "timeout": 40, "x": "center"}'
mosquitto_pub -h $MQTT -t "${PREFIX}/msg" -m \
'{"msg": "hi", "no_scroll": "True", "x": -10}'
mosquitto_pub -h $MQTT -t "${PREFIX}/msg" -m '{"msg": "hi scroll"}'
mosquitto_pub -h $MQTT -t "${PREFIX}/msg" -n ; # clear
# Animations
mosquitto_pub -h $MQTT -t "${PREFIX}/img" -m 'parrot'
mosquitto_pub -h $MQTT -t "${PREFIX}/img" -m '{"img": "sine.bmp" }'
mosquitto_pub -h $MQTT -t "${PREFIX}/img" -m '{"img": "bmps/rings.bmp", "timeout": 10 }'
for x in cat fireworks hop parrot rings ruby sine ; do \
mosquitto_pub -h $MQTT -t "${PREFIX}/img" -m $x
sleep 10
done
mosquitto_pub -h $MQTT -t "${PREFIX}/img" -n ; # clear