Reader small image

You're reading from  Wearable-Tech Projects with the Raspberry Pi Zero

Product typeBook
Published inJul 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781786468819
Edition1st Edition
Languages
Right arrow
Author (1)
Jon Witts
Jon Witts
author image
Jon Witts

Jon Witts has been working within the IT industry since 2002 and specifically within Educational IT since 2004. He was introduced to Linux back in 2001 through his collaboration with two German artists who were visiting the arts organisation he was then working with. Having studied Fine Arts and Educational Technology and sought to innovate with open and accessible digital technologies within his creative practice, Jon is happiest when deconstructing technology and finding its limits. Jon has embedded within his school the use of Raspberry Pi computers, as an integral part of the delivery of the school's Computer Science curriculum as well as to run various school clubs and projects. Jon is a Raspberry Pi Certified Educator and also helps to organise and run the Hull Raspberry Jam events. I would like to thank my wife, Sally and our three daughters for putting up with all the cables and compoents around the house, and not least for being so tolerant of the need to dodge the robots racing round the kitchen floor!
Read more about Jon Witts

Right arrow

A Tweet-Activated LED T-Shirt

In this project, we will use the skills that we learned in Chapter 3, Sewable LEDs in Clothing, and take them a little bit further. We are going to create our own personally designed t-shirt using sewable LEDs again but by combining them into our own personal design. We will use a slightly different technique so that the conductive thread is completely hidden, and finally, we will write a Python program that listens to Twitter-awaiting commands to activate our t-shirt!

If you are using the same Pi Zero for this project as you did for the previous project, desolder the four cables, which lead from the Pi Zero to Blinkt; but leave your off-switch and LED in place, as you may need to detach these from the case first. To deactivate the software running automatically, connect to your Pi Zero over SSH and issue the following command:

sudo systemctl disable...

What we will cover

In this chapter, we will cover the following topics:

  • What we will need to complete this project
  • Creating our t-shirt design
  • Adding our LEDs to our item of clothing
  • Testing our LEDs
  • Writing our main Python program
  • Connecting our Pi Zero to the internet
  • Making our program run automatically
  • Finalizing the garment modifications

Let's jump straight in and look at what parts we will need to complete this project.

The bill of parts

We will make use of the following things in this project:

  • A Pi Zero W
  • An official Pi Zero case
  • A portable battery pack
  • Inkjet iron-on transfer paper (A3/A4—two sheets)
  • The item of clothing to be modified, for example, a top or t-shirt
  • Four red sewable LEDs
  • Four green sewable LEDs
  • Four blue sewable LEDs
  • Conductive threads
  • Some fabric, the same color as the clothing
  • Thread of the same color as the clothing
  • A sewing needle
  • Pins
  • 15 small metal poppers
  • Some black, blue, red, and yellow colored cable
  • A mobile phone
  • Solders and soldering iron
  • Clear nail varnish

Creating our personal t-shirt design

We are going to use an inkjet iron on transfer paper to get our custom design from our computer onto our t-shirt. I will show the design that I have used, but by all means, use your own design here!

You will need to create your image for your t-shirt design in an image editing package. You could use Photoshop if you have access to a copy, but I am going to use GIMP (GNU Image Manipulation Program) for my design. There really is not much to worry about here apart from a few points to bear in mind:

  • Your final image will need to be reversed. This is especially true if you have any writing in it.
  • Think about how you will need to join your LEDs up. We are going to wire up 12 individual LEDs to our Pi Zero and the connections from each cannot cross at any point.
  • Your design should fit onto a sheet of A3/A4 paper so that it can be printed onto the...

Adding our LEDs to our fabric

In the same way that we stitched the ground or negative connections of our LEDs together in Chapter 3, Sewable LEDs in Clothing, we are going to use a common ground connection for all of the negative connections of each color LED. Starting with the red LED furthest from the poppers, place your LED on it's marker on the piece of the fabric and stitch it to the fabric using a long length of conductive thread stitching through the negative connection of the LED. Continue with the same piece of conductive thread, and stitch a running stitch along the marker line on your fabric, and then use this to attach the negative connection of the next LED. Continue doing so for all the red LEDs, and finally, run your conductive thread to a female half of a popper, and stitch this to its marker on the fabric. Finish attaching the popper to the fabric by stitching...

Testing our LEDs

We now need to attach the cables to the correct GPIO points on your Pi Zero. First, you should detach your cables from your LEDs by disconnecting the poppers. Gather all of the cables together and cut them, so they are all about the same length; make sure that you keep your identification markings on each cable! Now, you can cover them in some heat shrink and apply some heat. Each cable now needs to be stripped and tinned, ready to be soldered on to your Pi Zero.

The diagram here shows you which GPIO point to connect which cable to. Feed all the cables through the hole in the bottom of your Pi Zero case, and then carefully solder each one and snip any excess cable using side snips:

Once we have finished soldering all of your cables to your Pi Zero, we can write a short program to test if they all work. Reconnect your cables to your LEDs, ensuring that you press...

Writing our main Python program

As the title of this chapter suggests, we are going to connect our Python program to Twitter so that different Tweets can control the LEDs on our garment. There are a number of steps involved in doing this. We first need to prepare our Twitter account, so we can connect to it; then we need to install a new Python library and configure it with our Twitter access. Finally, we can write our Python program, which will listen to Twitter for our trigger hashtags.

Let's get started straight away!

Preparing your Twitter account

If you do not already have a Twitter account, you are going to want to sign up for one at https://twitter.com/signup. Even if you do already have a Twitter account, you...

Connecting our Pi Zero to the internet

So, we have our Pi Zero listening to Twitter and lighting up our LEDs on our desk at home, but what if we want to wear our t-shirt out and about and have it still work? To make this work, we are going to need to connect our Pi Zero to some form of mobile Internet connection. There are many ways in which we could do this, but the easiest, by far, is to make use of the mobile data on our smart phone and create a mobile hotspot between our smart phone and our Pi Zero.

The method of doing this for each smart phone will vary slightly, and if you do not know how to do it with your type of phone, a quick Google search should yield the results you need. Once you have set up a mobile hotspot on your phone, you will need to take note of the network name or SSID of your hotspot and the password or key.

With those two pieces of information recorded,...

Making our program start automatically

As with our previous projects, we now need to make our program start as soon as we switch our Pi Zero on:

Now, we will create our service definition file; type this:

sudo nano /lib/systemd/system/twitterTshirt.service

Now, type the definition into it:

[Unit]
Description=Twitter TShirt Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/home/pi/WearableTech/Chapter5/ledTshirt.py

[Install]
WantedBy=multi-user.target

Save and exit Nano by typing Ctrl + O, followed by Enter, and then Ctrl + X. Now, change the file permissions, reload the systemd daemon, and activate our service by typing this:

sudo chmod 644 /lib/systemd/system/twitterTshirt.service 
sudo systemctl daemon-reload
sudo systemctl enable twitterTshirt.service

Now, we need to test if this is working, so reboot your Pi by typing sudo reboot, and then when your Pi Zero restarts...

Finalizing the garment modifications

The last thing we have to do now is to add our LEDs into our printed t-shirt design. Turn your printed t-shirt inside out, and then take your piece of fabric with your LEDs stitched into it and place it on top of the design of the t-shirt with the LEDs facing the t-shirt. Take some time to ensure that the two designs line up nicely and pin it in place. I then folded the fabric back over the back of the LED stitching so that none of the conductive thread would come into contact with the wearer's skin. With everything pinned in place, sew three sides of the design onto the t-shirt. I used a sewing machine to do this, but you could do it by hand if you do not have access to a sewing machine. Be sure to leave the side of the design closest to where your cables attach to the poppers open so that you can attach and detach the Pi Zero from your...

Summary

In this chapter, we have developed our skills of using sewable LEDs further, and also incorporated them with a printed design on our garment. You have also learned how to connect to Twitter using Python and make our programs react to different phrases or hashtags found on Twitter. Finally, you learned how to connect our Pi Zero to different Wi-Fi networks using the priority keyword in our wpa_supplicant file. This final step allows us to now take our wearable projects out and about with us when they need an Internet connection.

In our next project, we will be making a LED laptop bag. We will make use of a RGB addressable LED strip to create a matrix of programmable LEDs across the front of our bag. We will then create the necessary electronic circuits to control these with our Pi Zero and also write our Python program to control our LED bag design.

...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Wearable-Tech Projects with the Raspberry Pi Zero
Published in: Jul 2017Publisher: PacktISBN-13: 9781786468819
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jon Witts

Jon Witts has been working within the IT industry since 2002 and specifically within Educational IT since 2004. He was introduced to Linux back in 2001 through his collaboration with two German artists who were visiting the arts organisation he was then working with. Having studied Fine Arts and Educational Technology and sought to innovate with open and accessible digital technologies within his creative practice, Jon is happiest when deconstructing technology and finding its limits. Jon has embedded within his school the use of Raspberry Pi computers, as an integral part of the delivery of the school's Computer Science curriculum as well as to run various school clubs and projects. Jon is a Raspberry Pi Certified Educator and also helps to organise and run the Hull Raspberry Jam events. I would like to thank my wife, Sally and our three daughters for putting up with all the cables and compoents around the house, and not least for being so tolerant of the need to dodge the robots racing round the kitchen floor!
Read more about Jon Witts