SmartMatrix APA102 Library / Open Hardware Photon APA102 Shield

I haven’t posted a real update in over a month, but the project hasn’t stopped. The first item on my testing checklist was: “Test microSD and driving the LEDs simultaneously”, and I started by trying to port the AnimatedGifs sketch. It’s taken me probably about 20 hours longer than I expected.

  • AnimatedGIFs is now a lot more stable, I was seeing crashes when trying to play large GIFs on the small 16x16 APA102 matrix I have.
  • I had a difficult time trying to figure out what SD libraries were available for the Photon and which library to use. There’s not an up to date port of Arduino’s SD Library, the most recent is this user-contributed port which was out of date and doesn’t compile for the Photon, but can be fixed with a one-line change. There’s a port of SdFat, but I wanted the sketch to maintain compatibility with the Arduino SD Library which comes bundled with the Arduino IDE. I’m really hoping Particle dedicates some time to make their build tools compatible with the Arduino 1.5 library spec as right now it’s not a lot of fun to be a library maintainer or library user with Particle tools.
  • I refactored a lot of the AnimatedGIFs sketch to turn it into a GifDecoder class that doesn’t care where the GIF is stored and how you access it. There are callback functions for the file operations, so you could fairly easily port the sketch to use SdFat instead of sd-card-library if you wanted, or store your GIF in EEPROM or a SPI flash chip instead and use another library to access it.
  • I made the class templated so you can set the max GIF size and max LZW decoding complexity (managing memory usage) in the sketch. Before these were hardcoded inside the decoder.
  • AnimatedGIFs had it’s own while(1) loop inside of loop(), and the ProcessGIF() function didn’t return until the GIF had finished playing. This doesn’t work well with Particle firmware which expects to get to the end of loop() to keep the cloud connection alive. Now there’s a startDecoding() method, and you can call decoder.decodeFrame() once per loop and it doesn’t block.

You can try the AnimatedGIFs sketch yourself if you want. I tested it building locally and with Particle Build in the cloud, but not with Dev. Change kMatrixWidth/kMatrixHeight to whatever you’re using. I’ve tested it with 16x16, but it fails at 32x32 on the Photon (I’ll investigate). You can use larger GIFs (e.g. the 32x32 and 64x64 examples included with the library), it will just show the upper left corner of the GIF and throw out the rest during decoding.

For Particle Build you’ll need to import this version of the sd-card-library so it compiles (and delete the original one if you’re using it to avoid a name conflict). Hopefully the author merges my one-line pull request soon.

2 Likes