Sewing with LEDs and Raspberry Pi Pico

It’s been a while since we’ve seen a wearable tech project, despite loving them so much that we previously worked with maker/designer extraordinaire Sophy Wong to publish a Wearable Tech Projects book. This comprehensive tutorial by Nicola King, featured in issue #154 of Raspberry Pi Official Magazine, shows you how to bling up a handy storage pouch with some light-emitting silicon.

Nicola had some ‘circuit’ fabric that seemed highly appropriate here

Incorporating LEDs into a sewn project is easy to do, and we’re not just referring to wearable tech here. You can also craft items that you can actually use for a functional purpose and, at the same time, add a little Raspberry Pi and LED luminescence to your design. This tutorial takes a look at how to add some LEDs to a simple storage pouch, which we are also going to make. In fact, these zipper pouches — which can be made in absolutely any size you want — are so uncomplicated that we’ve whipped up quite a number in order to house various components, as well as our general odds and ends that need a home.

Sew straightforward

We decided that we wanted a decent-sized pouch, so we first cut out two 25 cm by 35 cm rectangles in our main fabric. Now, a quick word on your choice of base fabric before we move on: your base is important, so we’ve used a cotton-backed fabric with a medium-weight fusible interfacing to give it some structure. Cotton is generally a great choice because it is lightweight, flexible, and highly suitable for sewing with electrical components. If your fabric is difficult to sew through, you will have issues, so give this some thought. If you have some lightweight denim on hand, some calico, or even faux leather, they might also be good alternatives.

Testing the LED circuit and program on a breadboard before wiring everything directly to Raspberry Pi Pico

If you want to add a backing to strengthen your base fabric, cut out two pieces of fusible interfacing in the same size and adhere with an iron. Then cut out a ‘pocket’ in a different-coloured fabric — we cut a 10 cm by 15 cm rectangle — and back that with interfacing too. The reason we are adding a pocket is so that all of our Pico/LED workings can sit inside it comfortably and separately from whatever else we choose to keep in the pouch. To attach the pocket, fold in the bottom and the two short sides of the small rectangle by about 0.5 cm and pin the pocket to the interior side of one of your pouch pieces. Use your sewing machine to sew the pocket to the main fabric, keeping a consistent seam — 0.5 cm works well. As our fabric was dark in colour, the dark thread we used to sew the pocket blended well into the fabric and is barely visible on the right side of the pouch.

Next, take your zip and place it along the top of one side of the pouch, right side facing out, and pin it. Then, sew it with a zipper foot on your sewing machine (if you have one). Attach the other side of the pouch to the other side of the zip and sew. Press the seams that you have just sewn out, then top-sew along the length of the zip on the right side of the fabric to give it a neat finish. Open the zip halfway, turn the fabric pieces so that the plain inner sides are on the outside, and pin them together. Sew around all three pinned sides in one go, carefully removing the pins as you sew. 

Make the pouch as large as your want… in fact, the larger the better if you are looking to store cables etc. — we’ve found that A3 or A2 sizes are perfect, but you will need slightly more fabric

Finally, trim any loose threads and excess zip fabric, and use pinking shears to remove excess from the seams to help minimise fraying. Because you left the zip halfway open, you should now be able to turn the pouch right side out. Press it flat with an iron — you now have a complete storage pouch ready for use.

Note that we have purposely created a very simple design here for the sake of speed and ease, so we can concentrate on the electronics; if you have time, you can line the pouch with another fabric to make the inside tidier.

Pico programming

For this simple example project, we’re going to light three LEDs in sequence. So, in essence, we just need a program to turn the GPIO pin for each LED on (and off) in turn.

We’re using MicroPython for our program — flash it to Raspberry Pi Pico by downloading the latest UF2 file, making sure it’s the correct one for your particular Pico model. Then, while holding its BOOTSEL button, connect Pico to a computer via USB to mount Pico as a drive. Now drag the UF2 file onto the Pico drive to install it.

We’re using the Thonny IDE to program Pico. In Thonny, click ‘Local Python 3’ at the bottom right of the window, then select ‘MicroPython (Raspberry Pi Pico)’.

We start the program by importing two modules we need.

import machine, time

We define variables for our three LEDs, assigning them to their GPIO pins and setting them as outputs.

led1 = machine.Pin(11, machine.Pin.OUT)
led2 = machine.Pin(12, machine.Pin.OUT)
led3 = machine.Pin(13, machine.Pin.OUT)

We then create a list of these:

leds = [led1, led2, led3]

Finally, we make an infinitely repeating while loop with a for loop nested within it. The latter takes each value from the leds list in turn, starting with led1, and switches the respective LED on with led.value(1). We set a time.sleep delay for how many seconds it will stay on, then turn it off with led.value(0).

while True:
    for led in leds:
        led.value(1) # Turn LED on
        time.sleep(0.5) # Delay for 0.5 seconds
        led.value(0) # Turn LED off

With the LEDs connected on a breadboard, as shown in the wiring diagram (Figure 1), try running the program to see them light up in sequence. To make the program run automatically whenever Pico is connected to a power supply, save it as main.py (selecting Raspberry Pi Pico as the location).

Figure 1: The wiring diagram for testing — once you’ve got it all working, you can dispense with the breadboard and connect everything directly to Pico’s pins

Once everything is working as expected, you can reconstruct the circuit without the breadboard — position the LEDs where you want them in the fabric and poke their legs through towards the inside of the pocket. (Cotton is very easy to poke legs through.) Coiling the end of a resistor around the positive leg of an LED should hold it in place, or you may opt to solder it for a more secure connection. We plugged the other end of the resistor into a socket-to-socket jumper going to the respective GPIO pin on Pico; ditto for the negative leg of the LED, connected via a jumper to a GND pin. If your Pico doesn’t have pin headers attached, you could just solder the wires directly to the pin holes.

You can easily add extra LEDs to your circuit (and program), but you may need to join some ground wires together to connect them all to Pico’s GND pins if you run out of the latter. You could also create alternative lighting programs and perhaps fade the LEDs in and out using PWM to adjust the brightness.

Raspberry Pi Pico, a battery pack, and the wiring all fit in an interior pocket, keeping them separate from the bag’s main contents

We’re powering our circuit from a 3 × AA battery pack connected directly to Pico’s VSYS and GND pins, which supplies around 4.5V. Pico is fairly voltage tolerant, so this should work fine. If using a Raspberry Pi Zero computer instead, you may well want to use a mini voltage regulator board.

A twinkling tote

The aim of this tutorial has been to offer up a simple idea of how to combine some crafty sewing and LED programming into one project. There are many ways of doing this, so consider this a starting point — and please do take it further! Make a larger tote bag, introduce sewable LEDs such as a LilyPad, or try using some conductive thread. Why not take inspiration from our Wearable Tech Projects book and create your own textiles-based Raspberry Pi project?

The post Sewing with LEDs and Raspberry Pi Pico appeared first on Raspberry Pi.



from News - Raspberry Pi https://ift.tt/Xo0942H

Comments

Popular Posts