text.skipToContent text.skipToNavigation
Black Friday Sale

Star Spangled Beanie

Download Project Resources View on Github

Put some LEDs in your BEANIE

hero

With some of our wearable devices; the wearable LEDs and ESP32 Wearable we've made a flashing Beanie. WiFi and Bluetooth compatibility means you can control it with your phone, and for an extra bit of interest, we've patched the wires into the battery compartment on the beanie, so it is all powered by a 3.7V USB-rechargable lithium battery that you can still use as a head torch if needed.

Bill of Materials

Qty Code Description
1 ST3214 Beanie
1 KM1058 Power pad slide switch
1 XC3810 Wearable ESP32 board
1 PT4452 2 Pin JST connector
1 KM1036 Wearable Green LED
1 KM1038 Wearable Red LED
1 WW4100 Conductive steel wire

You will also need to get needles and sewing utensils if you don't have any around, A quick and easy solution is to also use the KM1080.

Bluetooth connectivity

We use bluetooth in this ESP32 program that can be controlled with any SerialBluetooth compatible app. On android, we used the Bluetooth Switches app by yashx. This provides us with a series of buttons that we can use to turn on and off the LED arrays.

appstore

Setting up the powerpack

The LED light / powerpack that comes with the ST3214 beanie is a nice little rechargable battery pack. To modify it for this project, we' attached a little power plug out to the ESP32.

battery

To do this, all you have to do is pry the two halves of the case open and access the circuit board inside. We did but unfortunately we broke the clips, so we had to glue it shut pretty well.

solder

Keep an eye out for the polarity of the battery, you can mark this with a permenant marker if you want.

Firstly, remove the battery: use a soldering iron and very carefully remove each tab of the battery. Important to remove only one battery tab at a time, as the battery will always be "live" and should not short out. It's so important that it's worth repeating:

Remove only one battery tab at a time, until the battery is completely removed. Do not short the battery terminals.

Once the battery is removed, you can drill out a little bit behind the battery to poke two wires out. We used WH3032 as solid core wires as well, as they provide a bit of structure to the entire build.

circuit Solder the battery terminals back in place, matching the same polarity as before. and attach the wires that are poking through, so you have access to the battery from the outside of the case.

The added benefit of pulling apart the battery pack is that you can remove the silver plate that sits around the LEDs, which allows the little recharge light to show through.

recharging

Once you're finished and the wires are all connected, connect back up the battery pack, using some superglue if you need to keep it together.

Do not short-circuit the two battery leads. but connect up the PT4452 connector

Setting up the power switch

Use some solder to make the connections as shown:

battery

We want the connections to be solid and secure for the entirety of the project, so we will use proper solder connections. Be sure to leave enough room to place the ESP where you want it to be. We put it right next to the cutout for the LED powerpack, with the switch just above the cutout.

positioning

Sewing the beanie

Once you have the beanie and the sewing kit, it's just some simple circuits that you connect up by stitching up with the steel thread.

The "diagram" is simple:

connecting up the leds

Depending on how you want things to be connected, this is the general idea of what you can do. Connect up a few of the green and red LEDs in parallel to each other and connected to a certain pin number on the wearable ESP.

You'll want to loop each loop connection a couple of times to ensure a good connection, as you can see in the picture below.

sewing

Keep the "exposed" wires short. It's much easier to wire up the beanie by only exposing small little loops of wire, before going into the fabric and running a longer length of conductive thread.

beanie

If you get the Sparkle Stitch Kit You'll find plenty of great tips in the included booklet, plus some extra patterns and ideas to use.

Programming

there's a few aspects to programming the kit:

1. Write down what LED pattern connects where:

For example:

LED String Connects to Flashing?
Around brim 26 Slow
On crown 12 Fast

In the code, we've made an array of structured data to store this information and manage the LED's for you.

It is defined like this:

typedef struct
{
    char letter;         // a - z to designate this Led strip
    uint8_t pin;         // what pin it is connected to
    long delay_time; //set to negative for always on
    long lasttime;   //used internally
} PinMap;

The delay_time is just the amount of time between each blinking of the LED's in milliseconds. If you wanted the LED to blink once every second, you'd set this to 1000L or if you wanted it to flash rapidly, say: 10 times a second, you would set this to 100L

the letter is used by the app. The app we are using is the Bluetooth switches app. This sends a A to turn something on, and a to turn something off, through the serial monitor.

2. Build a mapping of the pins in code:

That is the definition of the pin mapping, but how do we actually use it?

Have a look in the source code for lines that look like this:


PinMap bindings[] = {
        {'a', 26, 500L, 0}, // 'a' is around brim, flashing twice a second.
        {'b', 12, 100L, 0}, // 'b' is on crown, flashing 10 times a second.
};

Here we use what we had defined previously to set up new mappings. The letter doesn't matter, as long as it is unique and can be remembered in the app. You can set which letter, pin, and flash rate is for each of your strings of LEDs. Keep the last value as 0, as that will be used by the program.

3. Program the ESP

If you haven't done ESP32 boards before, you must set up the IDE to generate ESP32 code.

Here's a quick rundown:

  1. Open up the arduino IDE.
  2. Open the preferences window.
  3. Add the following to Additional Board Manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  4. close the preferences window
  5. Open board manager from Tools > Board > Board Manager and search for and install the esp32 library by Espressif Systems

Then Select "WEMOS LOLIN32" from the Tools > Board menu, and select the right port that you have connected to. If you can't see the board, you might need to install the CH340G drivers.

You should find the code can upload to the device successfully. Open up the serial monitor and change baud rate to 115200.

4. Use the app

Use the Bluetooth Switches app, or similar "Bluetooth Serial" compatible app if you have an iphone, to send data to your device. You should be able to:

  1. Turn the ESP on.
  2. Find it in your phone's BT connections, and pair with the ESP ( called "Beanie").
  3. Open up the Bluetooth Switches app, and select the "Beanie" ESP.
  4. Turn on and off some switches in the app.

If you have the Serial Monitor open it should look something like this:

serial monitor

in this example we set {'a', LED_BUILTIN, 200L, 0}.