Wearable Computing

Introduction to Adafruit Flora

 

 

 

Arduino IDE
Setup & Installation

Getting Started with

Adafruit Flora logo courtesy of adafruit.com

The Adafruit Flora is a fun, easy to use wearable computer. Similar to the Arduino LilyPad--another popular e-textiles electronics platform--the Flora can be paired with sensors, NeoPixel & LED lights, and other modules to create a wide array of innovative clothing and fabric projects.

We'll be using the Arduino IDE we just installed to program our Flora. Code for many Flora projects is freely available on the web, and a good starting point to developing projects for the Flora is copying and adapting existing code to fit your needs.

For today's workshop, we'll be:

- Blinking the Onboard Flora LED & NeoPixel
- Linking additional NeoPixels
- Using these lights to visualize poetry

Blinking the Onboard LED & NeoPixel

First, we'll blink the onboard LED. Copy the following code into the Arduino IDE:

    // Pin D7 has an LED connected on FLORA.
    // give it a name:
    int led = 7;
     
    // the setup routine runs once when you press reset:
    void setup() {                
      // initialize the digital pin as an output.
      pinMode(led, OUTPUT);     
    }
     
    // the loop routine runs over and over again forever:
    void loop() {
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      delay(1000);               // wait for a second
    }

To light up the onboard Neopixel, copy the following code into the Arduino IDE:

#include <Adafruit_NeoPixel.h>

#define PIN 8

#define NUMPIXELS 1

// First, we need to tell the board to interact with the NeoPixel.
// Below we see Adafruit_NeoPixel() with three parameters inside the parenthesis
// Parameter 1 = number of pixels in strip, starting at 1.
// Parameter 2 = Arduino pin number, defined above (most are valid)
// Parameter 3 = pixel type indicators, added together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products with WS2812 LEDs)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// This is where you're putting in place parameters for the Flora to start from
  void setup() {

      pixels.begin(); // This initializes the NeoPixel library.
      pixels.setBrightness(75);
      pixels.show();
}

// This is where you're creating the looped command for the Flora
    void loop() {

      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
      pixels.setPixelColor(0, pixels.Color(100,0,100)); 

      pixels.show(); // This sends the updated pixel color to the Flora.
}

Blinking onboard LED code courtesy of Adafruit. Neopixel code courtesy of Andy Boyles Petersen.

Blinking Additional NeoPixels

Flora Pinout Diagram courtesy of Adafruit

Now that we've worked with the onboard Flora lights, we can move on to adding additional NeoPixels. Shown above is a pin display of the Flora. In addition to Ground (marked Ground) and Power pins (marked 3.3v and VBATT), the Flora has multiple pins (D10, D9, etc.) for building out your wearable projects.

Today we'll be using VBATT, D12, and GROUND.


Adafruit NeoPixel showing proper hook up of through-wires on negative, positive, and center terminals

Shown here is the proper hook-up of alligator clips (or thread) to a NeoPixel.

  • Red wire runs from your power pin (VBATT or 3.3v), forming a chain and connecting to the (+) terminal on each NeoPixel.
  • Black wire runs from your ground pin, also forming a chain and connecting to the (-) terminal on each NeoPixel.
  • The yellow wire is your command wire, telling each NeoPixel what to do. This runs from a buildout pin (D12 in the examples on the right) through to each NeoPixel.

Be sure to take note of the direction of the arrows, connecting each NeoPixel in series. Arrows should point away from the Flora, pointing to the next NeoPixel in the chain.

Now, we'll make a series of four NeoPixels slowly blink. Copy the following code into the Arduino IDE:

#include <Adafruit_NeoPixel.h>

#define PIN 12 //We'll be using pin D12 to build out our project

#define NUMPIXELS 4 

// Next, we'll tell the board to interact with the NeoPixels, as before

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// This time, we've added an integer we've named 'delayval'.

  int delayval = 500; // delay for half a second
  void setup() {

      pixels.begin(); // This initializes the NeoPixel library.
      pixels.setBrightness(50);
      pixels.show();
}

// In this loop, we've added a for statement, allowing us to write code for all pixels as opposed to individually
    void loop() {

    for(int i=0; i<NUMPIXELS; i++){
      for(int j=0; j<NUMPIXELS; j++) {
      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
      pixels.setPixelColor(i, pixels.Color(50,0,50)); 

      pixels.show(); // This sends the updated pixel color to the Flora.

      delay(delayval); // Delay for a period of time (in milliseconds). 

      pixels.setPixelColor(j, pixels.Color(0,0,0));
      pixels.show();
}
}
    }

Next, we'll add a bit more complexity by making NeoPixels cycle through a rainbow. Copy the following code into the Arduino IDE:

#include <Adafruit_NeoPixel.h>


#define PIN 12
#define NUMPIXELS 4

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

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

void loop() {
  rainbow(20);
}

//In the above loop we specified an action named 'rainbow'. This code is outlining what rainbow is. 
void rainbow(int wait) {
  int i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<NUMPIXELS; i++) {
      pixels.setPixelColor(i, Wheel((i+j) & 255));
    }
    pixels.show();
    delay(wait);
  }
}


// Rainbow references 'Wheel' to determine its color. For 'Wheel', this code commands the color specifications.
// The colors are a transition r - g - b - back to r.
int Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

NeoPixel Blink and Rainbow code by Andy Boyles Petersen, revised and adapted from Adafruit.

Visualizing Poetry

Now that we know how to work with NeoPixels and the Adafruit Flora, we're going to put our newfound skills to use visualizing poetry. Consider elements such as color, solid vs. blink, light duration, etc. and craft your code to best fit your reading and interpretation of the poem you choose. Four poems from Michigan writers are hyperlinked below; if you have a poem or piece of writing you'd prefer to use, feel free to work with that!

Not Forgotten - Toi Derricotte

Digger, Power, Speed - Jim Daniels

Driving Along Interstate 94 - Naomi Cornelia Long Madgett

Sky. Clouds. Apples - Nancy Willard


If you need further inspiration, or additional code sets, consider looking at Adafruit's sample Flora projects, as well as Flora user guides/tutorials.