Back in 2016 one of my projects on Hackaday won me a 32x32 RGB LED matrix from Adafruit. At the time I didn't quite know what to do with it. It came with a Raspberry Pi shield to control it, however I thought it would be overkill to dedicate a whole Raspberry Pi for such a simple task.
Fast forward to now, the ESP32 Arduino support has come a long way. I was looking to make a project using Arduino IDE, Node-RED and MQTT (to add to my ever growing home-made IoT devices) and learn to do some more "complex" things on the ESP32. For the hardware this project technically only needs a LED matrix, ESP32 breakout, prototyping cables and a power supply.
I wanted to use my Raspberry Pi-based Node-RED server and MQTT to generate and stream the display, the reason being that it's much easier and faster to edit and add new animations on the server side, also more memory is available and processing is faster.
On my LED matrix I could display the outside temperature/humidity data thanks to OpenWeatherMap API, it simply reads a sensor somewhere near my location which I trust to be correct and calibrated. However, I have never been able to get the conditions inside the apartment. The way this project was designed allows the RPi to be connected yet to another sensor/service and display the data on the LED matrix without modifying it or its firmware.
I was able to get my hands on an SHT31 development module. It's a small board, powered by a coin cell, containing the SHT31 temperature/humidity sensor, a screen displaying the data and, perhaps most importantly, a Bluetooth LE module which can be used to retrieve data over the air.
There are some temperature/humidity sensors that use the ESP8266 to convey the data directly over WiFi, I have some as well, the issue with the ESP8266 is its power consumption and the proximity to the sensor, the local heating tends to bias the sensor values. Therefore, Bluetooth LE is a perfect candidate for more accurate readings, for an over-the-air, battery-powered device. On the image above you can see the trouble the PCB designer went though to make sure the sensor is affected as little as possible by the other electronics, by making a cutout around the sensor.
I set myself to get the the SHT31 development board connected to the RPi server and interface it with Node-RED. First, I replaced my RPi 2 server with a RPi 3B+ to have access to the integrated Bluetooth. Then I found this nice project on GitHub that did exactly want I wanted: get the data out of the SHT31 development module using GATT.
This project wouldn't be complete with instructions on how to set up your own MQTT broker. The MQTT broker is a piece of software, running on a server somewhere in the world (ideally in your own house) where the RGB LED Matrix connects to. The server generates a 32x32 pixel image and sends it to the matrix which displays it.
This log summarises how I set up my server. If you want to learn more about the MQTT protocol I highly suggest this website. However, as far as this project is concerned, you don't need any other prior knowledge than the ability to follow a numbered list:
I used a Raspberry Pi 2 (RPi) to set up the MQTT broker, the RPi hardware version does not really matter for this project as any version can handle the software we're about to install. The purpose is to have an "always-on" tiny computer to update the display.
I like to set up my headless RPis with Diet-Pi distribution in favour of Raspbian. It offers some advantages over the Raspbian Lite (memory, tuning, responsiveness, space usage...). Diet-Pi also makes it easy to install optimised versions of the required packages.
Once the RPi is installed and configured to connect to the local access point it's ready to get the Mosquitto broker and the Node-RED front end:
Type dietpi-software into the command line to get access to the RPi optimised software packages.
Select "Software Optimised".
Check the Node-Red and Mosquitto packages with space bar:
Press "Enter" to get back to the main menu.
Scroll down to "Install" and wait for the system to finish installing the packages.
You now have a fresh install if Node-RED that is ready to talk to your Mosquitto broker and exchange messages. Using your web browser navigate to the IP of your RPi on port 1883, for me it is 192.168.1.253:1883. You should see something resembling the following:
You should see the following new flow in the Node-RED front end:This flow will publish a new message every minute with a topic named "display", this is the topic name the ESP32 should be configured to listen to for this system to work. Click the "Deploy" button for the flow to start.
If you have properly configured your RGB LED Matrix, with the proper access point credentials, IP of the RPi and topic name of the message, then it should be able to receive the messages published by this flow:
You can modify, explore, add all sorts of flow items. Even make flows send messages between themselves. Node-RED is very versatile and graphic aspect allows to visually organise the message flows. Have fun displaying your own data.
I wanted to display some logos on the RGB LED Matrix in view of the MacroFab Design Contest: Blink an LED. I decided to show the Hackaday Jolly Wrencher, the MacroFab logo and Mouser Electronics logo. I found all of these with a simple search, resized and edited them slightly:
I found this nice website that converted PNG images to XLSX files with the RGB pixel values from 0 to 255. The formatting wasn't quite right, so I applied some regex-fu and voilà: an illegible stream of numbers that, when sent to the RGB LED Matrix, would display the following logos:
I couldn't take a video as the update rate of the LED display gave a large black scan line when using my phone camera. That's not visible to the human eye though.
The RGB LED matrix has been functioning for a couple of months now and I have noticed a few bugs. Overall checking this display has become part of my daily routine. I especially like the full control aspect of it (software-wise).
Thanks to its versatility I was able to decide exactly what to show according to my needs, this is how I use it:
I show the time and date, the outside weather, temperature and humidity (To = temperature outside, Ho = humidity outside).
When the ESP loses connection to the MQTT broker on the RPi it struggles to connect again, it will display "MQTT CONNECT" indefinitely. I don't quite understand why this happens and I need to investigate it. I did foresee that happening and prepared it to reconnect in case of loss of communication, but I've learned that the ESP and its WiFi stack are not as reliable as I hoped.
The double buffering sometimes gets corrupted, the screen starts to flash random stuff or flickering. I believe this is due to some corner case, this is extremely rare and difficult to reproduce.
For both of these cases a power cycle helps to put things back in order.
Another issue is that the OTA update does not work, I am not sure why that is, but I cannot upload code over the air as the ESP does not show up in Arduino IDE.
That being said these problems are rare and the hardware is solid. If you want to build one please do and send a picture of how you use it :)
In line of making this project as complete as possible I list in this log the components, where I got them, how much they cost and possible alternatives.
To build this project, while buying all the components, the cost comes down to $40 for the version with the prototyping cables, with the PCB and components it's about $50, this does not include the Node-RED/MQTT server.
RGB LED Matrix
I won my RGB LED matrix and technically got it for free, it was from Adafruit and is sold for $40. That was the one on all the pictures here. I bought a second matrix to build another one, this time from Aliexpress and it works just as well, but is half the price (including shipping).
The matrix comes with the power supply cable. It has screw-terminal connectors on the input and two JST-VH 4-pole female connectors on the output.
If one is inclined to use the adapter PCB then only the 15-pin version is suited. Otherwise, with prototyping cables, any ESP32 breakout should be compatible, as long as 11 GPIO pins are available (careful: not all GPIO are usable on the ESP32).
Mouser: €8.50 (footprint not compatible with the adapter PCB)
These can be bought from eBay/Aliexpress. I cannot provide a source for this one as I salvaged mine from an old appliance. As long as it can output 5V at 2A minimum it should be fine. I would avoid using a phone charger as they can often supply only up to 1A and may overheat and be unreliable. I estimate the cost of this part to about $5.
Note that you need some kind of adapter, crimps, or just plain solder to connect the power supply cable to the matrix power cable.
If you want to use prototyping cables then those can also be bought from eBay/Aliexpress for very cheap, the result might be messy, but it'll work.
However, Digikey has a minimum order price of about $50 before the shipping becomes free (shipping is about about $20). It might be cheaper to buy from eBay or JLCPCB sister company LCSC (I have no experience with them though).
I rounded the cost of the four 3D printed corners to about $1. This is about 21g of PLA plastic (0.021kg * $30/1kg = $0.63) and 2h or printing time on my slow 3D printer (0.05kW * 2h * $0.2/kWh=$0.02). Of...
Since this project requires an MQTT server and knowledge on how to set it up it makes the building/coding curve a bit steep at first.
I wanted to make this project more accessible and set up my own Node-RED server to publish, once a minute, the english word clock display to a public MQTT broker (HiveMQ) where one can point the matrix to test it:
I updated the dummy configuration file in GitHub repository so this will be the default setting. The time is UTC+1 (Swiss time), so unless one is in the same timezone the clock will be wrong… but good enough for a test.
The other issue with unprotected public MQTT brokers is that anybody can send data to the broker with the same topic name and then the matrix will behave strangely. I simply expect fair usage.
The wires inside the frame were bothering me, it was messy and unreliable. Any movement of the frame might have made the device inoperable and it was easy to make connection mistakes. On the other hand the ESP32 module needed so many passives and soldering without an oven was impossible.
I decided to make a breakout for a breakout. I designed a board around the ESP32 devkit board that had the footprint for the RGB matrix connector, the ESP32 devkit module and also for the 5V power input connector. The devkit breakout of the ESP32 module already had a voltage regulator from 5V to 3.3V and all the bits for programming (USB-UART, Micro-USB connector…).
I rolled my PCB:
Looks good right? But...
This was a pretty hard fail, the board was so easy to make that I didn’t even double check the ESP32 devkit footprint. I did however succeed in testing it before I reordered a corrected batch:
My second try worked out well (traces are on the other side):
1x, 4 pin, JST-VH, male connector, 3.96mm pitch, part number: B4PS-VH(LF)(SN)
The 15 pin connectors are not really needed, the ESP32 devkit module can be soldered directly to the board. The female connectors are handy so, but they make the ESP32 module touch the backside of the frame...
This was the insides before:
The power cable came with the matrix. It has two outputs, presumably to power a second screen.
Recently, while moving and getting some furniture from IKEA, I found the perfect frame to host the RGB matrix, the RIBBA frame:
The matrix is 190.5mm x 190.5mm x 14mm, the frame is 230mm x 230mm x 45mm, plenty of space for the matrix and the electronics. The frame has a white cardboard insert that can be cut to the matrix size:
However the matrix will not be centred...
So I 3D printed some corners to center the matrix in the frame and push it against the front face:
The electronics are not looking very professional though, I need to rethink that, wires are pretty unreliable...
Writing the ESP32 firmware, with all its timing critical constraints, was only half of the job, the actual image generation happens on an MQTT server (hosted on a Raspberry Pi). I've made one of my most complex flows:
It does the following things:
Fetch the data from different sources (weather data, public transport, Bitcoin value)
Parse the data according to selected display
Evaluate the screen update rate (the ESP32 sends back a "heartbeat" message every time it is updated)
Ping the matrix to make sure it is present
Send the data to MQTT only if the pixels have changed and the matrix has been successfully pinged
Apply a "brightness filter" to set the pixel intensity level according to the user settings
Compress the data to a binary stream for efficient transport (as efficient as it can be made with this framework...)
Update the Node-RED user interface
In the user interface one can:
See the preview of what is currently displayed
Select the matrix display
Set the LED brightness
Change the display every minute (selects the next one in the list)
Turn off the LED matrix (send a black screen and then stop sending updates)
Having highly limiting restrictions is a fun way to practice problem solving and creativity. In the case of the 32x32 pixel matrix I wanted to have lots of information on the display, but were challenged by the resolution. Despite this limitation it was possible to achieve very interesting things.
This project being an Internet-of-Things device I wanted to fetch interesting and relevant information off the internet and local sensors and display them.
Super tiny font
I searched for a small font to display human-readable letters to convey information. I found the TomThumb font which squeezed latin characters in a 5x3 area, if you think about it it's pretty amazing how our brain can distinguish them at such low resolution (context helps a lot though):
I had to adapt some letters, as not all of them perfectly fitted the 5x3 area (g, j, p, q, y). This amazing font allowed 32/4=8 characters per line and 32/6=5 lines of text:
The first thing that I wanted to display was time. My ultimate goal was to replace my dad's wall clock:
Here are the animations I came up with:
This one was pretty easy, simply evaluate the angle from the hours, minutes and seconds and draw lines from the center to the edges. I liked the way the hands extend up to the very edges of the matrix. One can tell which hand is which by the intensity of the hands.
I also tried to use red, green and blue colours to distinguish the hands, but it was atrocious.
The digital clock only took the topmost line, so I added some more information on the next 4 lines: date, inside temperature, inside humidity and outside temperature which I got from openweathermap and update every 10 minutes.
The temperature colour is blue under 10C, cyan between 10-20C, green between 20-25C, yellow between 25-30C and red above 30C. The humidity is green between 40-60%, yellow between 20-40% and 60-80% and red otherwise.
This one was for the sake of the exercise, completely useless for its function as it's not easily human-readable. The numbers are defined by 6 bits, so maximum value of 2^6-1=63. The most significant bit was on the left side, first line is hours, then minutes and then seconds.
This example shows a time of 16+2:16+8+4+1:32+16+4+1: 18:29:53.
Reading the time and getting your head around the powers of two usually meant that by the time you understood the time it had already changed.
English word clock
Since there was enough space I wanted a clock that spells out the time in plain English. This is called a "word clock", there are many similar projects on Hackaday.io. Very human-friendly.
I tried to use only Katakana to tell the time, but there wasn't enough space as there was a hard limit of 4 characters per line and 4 lines with this font (16 symbols total). Also using only Katakana characters didn't look very nice.
Using Kanji fixed that and I must say I like it a lot:
今は午後六時二十六分です means "it is now 6:26 in the afternoon", although I doubt my dad can read it.
This animation was just a "why not" idea: a Bitcoin ticker that updates itself every minute. The data is taken from Blockchain ticker...