Hello readers! Last time I got my Adafruit HalloWing badge working with the SD Card Shield under Arduino. But that's a lot of naked electronics to have dangling around my neck. Let's make a case for it!

Someone already remixed the Hallowing badge case to fit a battery, so I had a go at remixing it further. I brought the model into Windows 3D Builder, cut, and extruded the depth of the case to 2cm. Which it turns out fits everything nicely! Except, the SD card is a bit squished against the edge of the case (you might need to put the SD card in after fitting the badge into the case). If I do this again next time I'd widen that bottom opening just a smidgen.

Slight complication )


HolloWing badge wearing 3D printed case, with lanyard attached. Regular front view, badge displaying my mastodon account avatar and details (@chebe@choas.social).

Finished badge case
Photo by [personal profile] chebe

I 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;
#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 [personal profile] chebe






Front of the badge, displaying an image with overlay, and NeoPixel backlit
Photo by [personal profile] chebe



Messy code dump cobbled together from various tutorials )
I got myself a HalloWing a few weeks back. I'd had the idea a few years ago of adding an LCD to a microcontroller as a reusable convention/conference badge, but didn't get far with it. So when I saw the HalloWing I knew it was everything I wanted all wrapped up in a gothic bow.

Arduino:
I get my HalloWing, install all the libraries, and play around with displaying a simple image. It turns out the process to do this is a bit convoluted.

First, open up Gimp, scale down your image to 128x128. Export as X BitMap Image (xbm).

Open the xbm file in a text editor. Add;
#include <avr/pgmspace.h>
to the top of the file, and replace;
static unsigned char image_bits[] = {
with
static const uint8_t PROGMEM image_bits[] = {
Save as .c format.

Include your image.c in your .ino sketch;
#include "image.c"

Include the screen library, declare and initialise your screen, then you can draw your image.

The drawXBitmap() functions exists with arguments; starting at x=0, y=0, image bits, 128, 128, a colour;
tft.drawXBitmap(0, 0, image_bits, image_width, image_height, ST77XX_GREEN);

All together the sketch looks like;
code )

The interesting thing with this is that it is monochrome. You can pick a colour (like red, green, etc), but it is a simple on-off map.

photo )

Which isn't quite right. I looked around and it seems that while you can write log files to the SPI Flash memory through Arduino it is wiped upon restart, so leaving a small image file to be loaded later doesn't work. At least, not without an SD card shield. I have one ordered, so I'll let you know if I can get it to work.


CircuitPython:
Until then, I guess it's time to CircuitPython it up with the HalloWing. Bonus; no need to install an IDE.

First, use Gimp to create 128x128 BitMap (bmp) images, making sure they are saved as 24-bit. Plug your HalloWing in over USB, press the Reset button twice, drag the UF2 file onto the device. Copy your bmp images, and your code.py file, to the root of the device. Done.

photo )

Profile

chebe: (Default)
chebe

Syndicate

RSS Atom

July 2025

M T W T F S S
 1 23456
78 910111213
14151617181920
21222324252627
28293031   

Expand Cut Tags

No cut tags

Style Credit