So today our final project was due and so far I completed the actual build, although it has a few changes. I attached a ribbon with conductive thread to a regular flower headband that I already owned. However, on my conductive ribbon, it had 4 different lines of conductive thread which I used one for ground, another power, and another as my dataline. Before anything, I had to connect the sew the Flora onto my conductive ribbon separated by a piece of non conductive fabric. Specifically, I connected one side of the thread to the ground thread and the other side to VBATT on the Flora, ground basically controls the flow of electricity Once I decided which threads would be used for what, I used conductive thread to connect the Flora Board to the color sensor. I had to connect SDA, which is a data pin that stands for serial data and SCL is a pin that stands for serial clock on both the Flora Board and color sensor. As well as connecting ground between the Flora and color sensor and the 3V to 3.3V. In order to seal the knots I used clear nail polish, which made it hard so it was easier to cut. Next, I started adding my neopixels by connecting D6 on the flora board to the top loop of the neopixel but making sure the arrows are going in the direction I want the power to run. After making sure it's connected to my dataline I proceeded to connect the rest of the neopixels. I originally was going to use 8 but decided to use 5 at the last minute. I wanted them to be about 2.5 inches apart. Once I connected all my neopixels to my dataline, i sewed down the the sides with conductive thread to power and the other to ground. Once my actually build was done I made sure all the knots were sealed correctly and not touching. I borrowed my code from an adafruit tutorial, the only trouble I had with this code was just making sure I had the correct libraries in the right place and changed the number of neopixels. However, the difficult part came when trying to power everything. Once I plugged my mini USB into both the flora and computer, the color sensor would come on but not the neopixels. In order to figure out the issue, I tested it with a multimeter to check the continuity to see if I had any possible shorts. Like I guessed, it did which resulted in me having to redo all the threading. (shoutouts to Muhammed, Brandon & Lisa for their help)
So as far as the coding goes, I had to make a couple of changes. Not only did I have to update the arduino but also had to add the neopixel library and the color sensor library. I only had problems with the actual downloads but Dawn helped me out (shoutouts to her). Overall I pretty much kept the coding the same.
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, 6, NEO_GRB + NEO_KHZ800);
// our RGB -> eye-recognized gamma color
byte gammatable[256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
Serial.println("Color View Test!");
strip.begin();
strip.show(); // Initialize all pixels to 'off'
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1); // halt!
}
// thanks PhilB for this gamma table!
// it helps convert RGB colors to what humans see
for (int i=0; i<256; i++) {
float x = i;
x /= 255;
x = pow(x, 2.5);
x *= 255;
gammatable[i] = x;
//Serial.println(gammatable[i]);
}
for (int i=0; i<3; i++){ //this sequence flashes the first pixel three times as a countdown to the color reading.
strip.setPixelColor (0, strip.Color(188, 188, 188)); //white, but dimmer-- 255 for all three values makes it blinding!
strip.show();
delay(1000);
strip.setPixelColor (0, strip.Color(0, 0, 0));
strip.show();
delay(500);
}
uint16_t clear, red, green, blue;
tcs.setInterrupt(false); // turn on LED
delay(60); // takes 50ms to read
tcs.getRawData(&red, &green, &blue, &clear);
tcs.setInterrupt(true); // turn off LED
Serial.print("C:\t"); Serial.print(clear);
Serial.print("\tR:\t"); Serial.print(red);
Serial.print("\tG:\t"); Serial.print(green);
Serial.print("\tB:\t"); Serial.print(blue);
// Figure out some basic hex code for visualization
uint32_t sum = red;
sum += green;
sum += blue;
sum += clear;
float r, g, b;
r = red; r /= sum;
g = green; g /= sum;
b = blue; b /= sum;
r *= 256; g *= 256; b *= 256;
Serial.print("\t");
Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
Serial.println();
Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" "); Serial.println((int)b );
colorWipe(strip.Color(gammatable[(int)r], gammatable[(int)g], gammatable[(int)b]), 0);
}
// Fill the dots one after the other with a color
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);
}
}
//loop is empty because it only takes the color reading once on power up! Turn the scarf off and on again to change the color.