IT Careers Camp #WearableWednesday

Tonight The Locals and some of our awesome volunteers were out at the IT Careers Camp hosted by UCA.  We had a great time getting students started on a wearable project.  You can check out a few photo highlights like this one by Dan Decker over on the AR Scene blog post.

The rest of this post is aimed at campers that are sitting down to continue to play with their Gemma and need a little more guidance. Read on for the nitty gritty details.

 

 

Tonight we just scratched the surface of what your wearable project is capable of.  Since we were limited on time and sewing takes a little bit to get the hang of, any of you are still stitching your project.  Some of you are probably tempted to say - sewing is too time consuming, I'll go find some wire and a soldering iron.  You can definitely do that.  I will say, however, that sewing these together gets a lot faster once you get the hang of it and it does allow you to do some things that wire may not - like have a nice circuit right there on your clothing item.

If you are still having trouble sewing - check out this video demonstrating a running stitch.

Your Gemma has the basic "strandtest" program loaded onto it, but it has the number of pixels in the strand set to 1.  This means that if you want the rest of your pixels to follow the same pattern as your first pixel you will need to dig into some code.

The important thing here -- even if you have never coded you must not be intimidated!! You do not need to know exactly what you are doing from the start, and you do not need to start from scratch.  You can learn as you go by experimenting and building off of other examples.

Important public service announcement:  if you get stuck, do a search for gemma, neopixel, and any keyword associated with your problem. There are tons of helpful resources.

Setup Your "Development Environment" for Gemma & Neopixel

You probably downloaded and installed the Arduino IDE during our session, if not go ahead and do that now.

Once you have the Arduino IDE installed, open it.  

The first thing we need to do is tell the Arduino software what board we are using. Under Tools hover over "Board" and choose the Gemma.  The, again under Tools, hover over "Programmer" and select Gemma.

Last thing (and we're all setup, forever)

We need to add the Neopixel library.  Go download the zip file here.  

To add the library go into your Arduino software, click on Sketch in the top menu, and under "Include Library" you will see "upload .zip library".  Find the file you downloaded above.

Start with an example!

The easy way to test your Neopixels and understand how they work is to start with an example.

Under File find "Examples" and you should see Adafruit Neopixel (if you do not, go back and check your setup above). Choose the example "strand test".

For our initial purposes the line of code we care about most is this one:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

If you look at the comments (comments are the helpful text that starts // and explains the code) you will see that the values in ( .. ) are Parameters 1, 2 & 3.  That means we need to change 60 to match the number of pixels we are actually using.

If we look at the next parameter PIN we see, again in the comments, that this is the "Arduino Pin" the Neopixels are connected to.  Remember that this is represented physically on the Gemma as D_ .  In our case we sewed to D1, so the pin is 1.

#define PIN 6

The example comes with it set as 6, but we need 1. Change that value.  Notice that in this bit of code the word PIN is being designated as the value 6.  If you use more pins on your Gemma later you can do this same thing, but give them different names (you'll see in the example I offer below).

Once you have made those two changes, plug in your Gemma (to USB on your computer) and click the arrow in the top bar of your Arduino software (it should say "Upload" when you hover over it).  Note: the little red light on your Gemma should be pulsing or you will get a programmer not found error.

What Next?

If you want to learn more about the code that makes your Gemma work start with a few basic questions, and experiment.  For example, ask yourself: 'based on my observation, what does colorWipe do?'. Then experiment with the colors and blink patterns. Upload your code and observe the results - did it work?

  colorWipe(strip.Color(0, 255, 0), 50); // Green

  // The above is the "function call".  Below you see the actual function.

void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}


The most important thing to keep in mind when you are learning to code with Arduino -- you do not need to understand every.single.thing in that code. Give yourself goal outcomes and work to make the changes you need to accomplish that specific goal, in the process you will learn to understand more and more code.

There are lots of possibilities. We talked about adding a zipper switch or an IR sensor so you can play tagIR with your friends. Ok, those are just two of our ideas - there are TONS more.

Resources

 There is a lot of information online about the Arduino. We didn't dig into what it means that your Gemma is an "Arduino" board of sorts. You can read more about what an Arduino is from them: www.arduino.cc.  You can also find a lot of info on your Gemma from Adafruit, the makers of this great little board.

If you want to know more about sewing your project Becky Stern has a great video with tips for sewing with conductive thread and making your project more durable.  Check that out if you want to make your wearable last, or make future wearables. 

Here is a video specifically about how to setup the zipper switch we mentioned.

Both Adafruit and the Arduino page have a lot of information to help you become a better programmer.  There is a great deal of innovation in the open source maker community, so dive in and get involved by sharing your own projects.  One great example of how you can connect and share is hackster.io

Here is a very basic sample that shows a program that will display different colors based on three events: a zipper switch being triggered (the zipper would need to rest on the pads), an IR receiver being hit with infrared (note: bright sun will trigger this as well), or nothing (any state not listed above). Sometimes it helps to start with a very simple 'test sketch' to make sure things are working (sewn in properly) and build from there.

#include <Adafruit_NeoPixel.h>

//These are the pin definitions, so make sure the numbers here match what things are connected

//to on your actual Gemma.

#define PIN 1
#define TOUCH 2
#define IR 0

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'

pinMode(TOUCH, INPUT_PULLUP); // this is how we tell the Gemma that the pin set as TOUCH is used as an input
pinMode(IR, INPUT);  // we do the same as above for the IR, but this time without activating the "pull-up resistor" 
}

void loop() {
int isTouched = digitalRead(TOUCH);
int isIR = digitalRead(IR);

//for the "zipper switch", will activate if medal is in contact with switch.
if (isTouched == 0) {
lightson(strip.Color(0,0,255), 10);
}
// for the infrared, will activate when the sensor is hit by IR (including sun's IR)
else if (isIR == 0) {
lightson(strip.Color(0,255,0), 500);
}
//otherwise it shows red.
else {
lightson(strip.Color(255,0,0), 10);
}

}

//simple function to turn on the leds for a designated amount of time.
void lightson(uint32_t color, uint8_t wait) {
for (int i =0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
}
delay(wait);
}

Do you like this post?

Be the first to comment