Port of the SmartMatrix Library to the ESP32. FastLED patterns and Animated GIFs on large LED matrix panels, now with WiFi!
Big progress today in reducing the amount of DMA RAM used by the SmartMatrix Library: the RAM required for holding the I2S data is cut in half by changing I2S to 8-bit mode and storing each clock's data in 8 bits instead of 16. For a 64x64 32-bit panel, the refresh buffer used to take 99kB of RAM, and now takes 49.5kB. This only works with the SmartMatrix Shield (circuit) as there's an external latch used to reduce the number of GPIO needed for the I2S data down to 8.
This DMA RAM savings should hopefully allow for more applications that use WiFi and other peripherals to work with the SmartMatrix Library. I have a sketch that uses WiFi to get the time and the SD library to play Animated GIFs, and it was too much RAM to drive a 64x64 panel even with only 24-bit color before. Now it works with 64x64 and 36-bit color.
I was trying to track down some memory issues, that turned out to be cache access errors from the ISR accessing memory it's not supposed to. After dramatically simplifying the ISR and creating a new task to handle calculating the data sent to the panel, that error - which was seen when trying to work with more Arduino libraries - is gone and I was able to put together a quick demo of SmartMatrix Library working with WiFi.
I took Jason Coon's awesome ESP32 FastLED Web Server sketch, stripped out the FastLED driver code (as it uses WS2812 LEDs) and merged in the FastLED_Functions sketch from the SmartMatrix Library examples. Even after initializing SmartMatrix at the end of the sketch, it requires ~30kB memory free for mallocs used by the WiFi and web server portions of the code.
The sketch is here. If you want to try this, make sure you have the latest code downloaded from the SmartMatrix Library github (TeensyLC branch), and follow the instructions in Jason's README:
I pushed some ESP32 updates over the last few days:
There's still some things being worked out, see the ESP32 section at the top of the README on GitHub. Biggest issue is probably dealing with memory management on the ESP32. When adding other libraries to the project, e.g. SD or WiFi, memory issues can lead to the other libraries not working, or getting into a rolling reboot situation. Moving matrix.begin() later in the sketch, so the SmartMatrix mallocs are the last things called is a decent workaround for now.