Adafruit HalloWing M0 displaying images from SD card through Arduino
2022-Oct-19, Wednesday 08:05 pmI went to an event at the weekend. Which meant I needed an event badge. Time to dust off my HalloWing badge. I finished the last post saying I would update once I got the badge reading images from the SD card shield. Well, dear reader, I was pleasantly surprised to discover that at some point I had gotten it working! At least to the point of auto-rotating through all the images on the card.
I don't really remember what I did to get the SD card working, but from the code the main bits are;
But I wanted more. First thing you need to know is that Adafruit have moved on and really want us to use the Arcada library to work with the badges in Arduino. But if I wanted a simple life I would have gone with the CircuitPython option. I travelled the frustrating path instead.
I set up two of the buttons to 'scroll' left/right through the images. The images have overlays that display matching usernames. One of the buttons toggles on/off the tft backlight, and the other button toggles on/off the on-board NeoPixel. For a while things weren't working, and after a lot of digging I discovered that Adafruit had made breaking changes, including deprecating a function they had used in the examples I was working from.
to;
needs to be replaced with;
For the buttons a library is required;
Then you need to create each of the four buttons (A2, A3, A4, A5);
Each of which you
The backlight and NeoPixel parts were straight-forward. And the only other thing I did was add an extender to the battery JST connector so it's easier to reach. I wrapped the leads around the shield, and tucked the battery between the shield and board.
( Messy code dump cobbled together from various tutorials )
I don't really remember what I did to get the SD card working, but from the code the main bits are;
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10;
File root;
void setup(void) {
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// List files on the SD card
root = SD.open("/");
printDirectory(root, 0);
root.close();
}
printDirectory(root, 0)
uses dir.openNextFile();
which sorts through your files alphabetically. bmpDraw(...)
(see code below) is what what reads the bmp file and translates it into what the tft wants. Nice.But I wanted more. First thing you need to know is that Adafruit have moved on and really want us to use the Arcada library to work with the badges in Arduino. But if I wanted a simple life I would have gone with the CircuitPython option. I travelled the frustrating path instead.
I set up two of the buttons to 'scroll' left/right through the images. The images have overlays that display matching usernames. One of the buttons toggles on/off the tft backlight, and the other button toggles on/off the on-board NeoPixel. For a while things weren't working, and after a lot of digging I discovered that Adafruit had made breaking changes, including deprecating a function they had used in the examples I was working from.
setAddrWindow(...)
was changed, from (start_x, start_y, end_x, end_y) to (start_x, start_y, width, height). So the change was from;tft.setAddrWindow(x, y, x+w-1, y+h-1);
to;
tft.startWrite();
tft.setAddrWindow(x, y, w, h);
tft.endWrite();
pushColor(...)
is deprecated. After experimentation I discovered that;tft.pushColor(tft.color565(r,g,b));
needs to be replaced with;
tft.startWrite();
tft.writePixel(col, row, tft.color565(r,g,b));
tft.endWrite();
For the buttons a library is required;
#include <Adafruit_FreeTouch.h>
Then you need to create each of the four buttons (A2, A3, A4, A5);
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A2, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Each of which you
qt_1.begin();
in setup(void)
, and then read with qt_1.measure()
as in;if (qt_1.measure() > 700) { /* do stuff */ }
The backlight and NeoPixel parts were straight-forward. And the only other thing I did was add an extender to the battery JST connector so it's easier to reach. I wrapped the leads around the shield, and tucked the battery between the shield and board.
Back of the badge, with SD card shield in place, and battery tucked between
Photo by chebe
Front of the badge, displaying an image with overlay, and NeoPixel backlit
Photo by chebe
( Messy code dump cobbled together from various tutorials )