Citi Bike Helmet

Sunday, 23 June 2013

Citi Bike Helmet

 

Overview 

Improve your visibility with style! Mod up this bike helmet with LED strip, a FLORA GPS, and find your way to the nearest Citi Bike station with ease. We used a Carrera foldable helmet, which has grooves between the protection, perfect for NeoPixel strip.

Before you begin this project, we recommend reading the following guides:
Do not affix electronics to the outer smooth surface of your bike helmet! Helmets are designed to be smooth for your safety.
This project was created in collaboration with Tyler Cooper & Justin Cooper, with major video help from Risa Rose and JM Imbrescia.

Tools & Supplies 

For this project, gather up:

Any entry level 'all-in-one' soldering iron that you might find at your local hardware store should work. As with most things in life, you get what you pay for.
Upgrading to a higher end soldering iron setup, like the Hakko FX-888 that we stock in our store, will make soldering fun and easy.

Do not use a "ColdHeat" soldering iron
! They are not suitable for delicate electronics work and can damage the Flora (see here).

Click here to buy our entry level adjustable 30W 110V soldering iron.

Click here to upgrade to a Genuine Hakko FX-888 adjustable temperature soldering iron.

Learn how to solder with tons of tutorials!

You will want rosin core, 60/40 solder. Good solder is a good thing. Bad solder leads to bridging and cold solder joints which can be tough to find.

Click here to buy a spool of leaded solder (recommended for beginners).

Click here to buy a spool of lead-free solder.

You will need a good quality basic multimeter that can measure voltage and continuity.

Click here to buy a basic multimeter.

Click here to buy a top of the line multimeter.

Click here to buy a pocket multimeter.

Don't forget to learn how to use your multimeter too!

Don't forget your wire strippers, pliers, and flush snips!

Wiring Diagram 

Repeat the process above with the GPS module, connecting corresponding TX/RX pads to FLORA (remember that TX goes to RX and RX goes to TX).

Sugru insulates the back of the GPS module from the LSM303 and FLORA main board, and also provides a semipermanent sticky situation. The silicone is not quite an adhesive, though it will remain affixed unless you choose to carefully peel it off.

The lithium polymer battery slides behind the elastic of the head brace. We sewed a small fabric pouch around the battery, which in turn was stitched to the elastic. 

Build Circuit 


Wrap a long piece of NeoPixel strip throughout the grooves in the Carrera "foldable" helmet. Start at one back edge, shifting the strip so that four LEDs are visible to the rider along the front brim.

Cut the strip to length at the opposite back edge and tack the LED strip to the nylon webbing in the grooves of the helmet with a needle and clear thread. We didn't affix to every piece of webbing, just in enough spots to secure the LED strip.
Do not affix electronics to the outer smooth surface of your bike helmet! Helmets are designed to be smooth for your safety.

Using a needle and more clear thread, affix the FLORA main board to the back head brace of the helmet through two unused pins (we used the 3.3v pad next to the USB port and the GND pad next to the JST connector).

Strip and tin three wires, then solder them to the input side of the LED strip.

Cut to length, strip and solder these wires to VBATT, D6, and GND, referring to the wiring diagram on the previous page if necessary.

Solder small flexible wires to the LSM303 accelerometer/compass module, then apply a small piece of Sugru to cover the back of the module. Stick it in the middle of the FLORA main board, making sure not to cover the on/off switch or reset button. We are making a circuit sandwich!

Solder the wires to 3.3v, SCL, SDA, and GND on FLORA, referring again to the wiring diagram.

Program it

Created by Becky Stern
The Citi Bike Helmet code takes the FLORA to the limit. The code is used to drive LEDs, the FLORA GPS module, and the FLORA compass/accelerometer module. It looks at a long list of all Citi bike sharing stations in NYC (over 300!) and determines which coordinate is closest to you. It then uses the GPS module, and the compass module to navigate you there. Click the button below to download the code.
Download the Citi Bike Helmet Arduino Sketch
This code example requires the following Arduino libraries:
Adafruit GPS library which can be downloaded from https://github.com/adafruit/Adafruit-GPS-Library
Adafruit NeoPixel library which can be downloaded from https://github.com/adafruit/Adafruit_NeoPixel
Pololu LSM303 library which can be downloaded from https://github.com/pololu/LSM303
Learn how to install libraries here.
Right near the top of the sketch, you are going to see a long list of GPS coordinates that look like this:


float lat_lon[LAT_LON_SIZE][2] PROGMEM = {
{40.767272, -73.993928},
{40.719115, -74.006666},
{40.711174, -74.000165},
These coordinates were copied and pasted using a bit of node.js (learn more here). This also means that if you live in a city other than NYC that has a bike sharing program, you can use our code to get your own list of coordinates. If you live in NYC, all of the current bike share stations are loaded into the sketch.
The next piece of important code is this:


Adafruit_NeoPixel strip = Adafruit_NeoPixel(45, 6, NEO_GRB + NEO_KHZ800);
int FarRight = 9;
int CenterRight = 10;
int CenterLeft = 34;
int FarLeft = 35;
int HeadsUp[] = {35, 34, 10, 9};
int RightStrip[] = {8, 7, 6, 5, 4, 3, 2, 1, 0};
int RightCenterStrip[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
int LeftCenterStrip[] = {33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23};
int LeftStrip[] = {36, 37, 38, 39, 40, 41, 42, 43, 44};
int counter = 0;
This is where we set up which LEDs on our helmet are used. This will likely need to be updated to fit your own bike helmet project. Learn more about how the FLORA NeoPixels work here.

In the setup function, you will find a section that deals with calibrating the FLORA compass module.


// Calibration values. Use the Calibrate example program to get the values for
// your compass.
compass.m_min.x = -581; compass.m_min.y = -731; compass.m_min.z = -1097;
compass.m_max.x = +615; compass.m_max.y = +470; compass.m_max.z = 505;
Included with the Pololu LSM303 library is a little sketch that will get you these values. Run the sketch and view the serial monitor. Then tilt your helmet/sensor in every possible direction. When done, dump the values in the serial monitor into the above bit of code (replacing our values).

Thats about all you need to know to get started. Upload the code to your FLORA, and you are ready to hit the road.
To test out your animations inside, try the following code that reacts to just the compass:


#include <Adafruit_NeoPixel.h>
#include <LSM303.h>
// Test code for Adafruit Flora GPS modules
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Flora GPS module
// ------> http://adafruit.com/products/1059
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

Adafruit_NeoPixel strip = Adafruit_NeoPixel(45, 6, NEO_GRB + NEO_KHZ800);
int FarRight = 9;
int CenterRight = 10;
int CenterLeft = 34;
int FarLeft = 35;
int HeadsUp[] = {35, 34, 10, 9};
int RightStrip[] = {46, 8, 7, 6, 5, 4, 3, 2, 1, 0, 46};
int RightCenterStrip[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
int LeftCenterStrip[] = {33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23};
int LeftStrip[] = {46, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46};
int counter = 256*5;

#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();

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

// Calibration values. Use the Calibrate example program to get the values for
// your compass. M min X: -561 Y: -679 Z: -558 M max X: 232 Y: 109 Z: 224
compass.m_min.x = -561; compass.m_min.y = -679; compass.m_min.z = -558;
compass.m_max.x = 232; compass.m_max.y = 109; compass.m_max.z = 224;
}

void loop() {
compass.read();
int heading = compass.heading((LSM303::vector){0,-1,0});

//Use this part of the code to determine which way you need to go.
if ((heading > 348.75)||(heading < 11.25)) {
Serial.println(" N");
//Serial.println("Forward");
GoForward(strip.Color(0, 51, 20), strip.Color(255, 255, 0), 200);

}

if ((heading >= 11.25)&&(heading < 33.75)) {
Serial.println("NNE");
//Serial.println("Go Left");
GoForward(strip.Color(0, 51, 10), strip.Color(255, 255, 0), 200);
}

if ((heading >= 33.75)&&(heading < 56.25)) {
Serial.println(" NE");
//Serial.println("Go Left");
TurnLeft(strip.Color(11, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 56.25)&&(heading < 78.75)) {
Serial.println("ENE");
//Serial.println("Go Left");
TurnLeft(strip.Color(39, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 78.75)&&(heading < 101.25)) {
Serial.println(" E");
//Serial.println("Go Left");
TurnLeft(strip.Color(74, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 101.25)&&(heading < 123.75)) {
Serial.println("ESE");
//Serial.println("Go Left");
TurnLeft(strip.Color(74, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 123.75)&&(heading < 146.25)) {
Serial.println(" SE");
//Serial.println("Go Left");
TurnLeft(strip.Color(79, 61, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 146.25)&&(heading < 168.75)) {
Serial.println("SSE");
//Serial.println("Go Left");
TurnAround(strip.Color(79, 61, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 168.75)&&(heading < 191.25)) {
Serial.println(" S");
//Serial.println("Turn Around");
TurnAround(strip.Color(79, 32, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 191.25)&&(heading < 213.75)) {
Serial.println("SSW");
//Serial.println("Go Right");
TurnAround(strip.Color(79, 61, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 213.75)&&(heading < 236.25)) {
Serial.println(" SW");
//Serial.println("Go Right");
TurnRight(strip.Color(79, 61, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 236.25)&&(heading < 258.75)) {
Serial.println("WSW");
//Serial.println("Go Right");
TurnRight(strip.Color(74, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 258.75)&&(heading < 281.25)) {
Serial.println(" W");
//Serial.println("Go Right");
TurnRight(strip.Color(74, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 281.25)&&(heading < 303.75)) {
Serial.println("WNW");
//Serial.println("Go Right");
TurnRight(strip.Color(39, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 303.75)&&(heading < 326.25)) {
Serial.println(" NW");
//Serial.println("Go Right");
TurnRight(strip.Color(11, 79, 0), strip.Color(255, 255, 0), 200);
}

if ((heading >= 326.25)&&(heading < 348.75)) {
Serial.println("NWN");
//Serial.println("Go Right");
GoForward(strip.Color(0, 51, 10), strip.Color(255, 255, 0), 200);
}
}

void TurnLeft (uint32_t c, uint32_t stripe, uint8_t wait) {
strip.setPixelColor(CenterRight, 0);
strip.setPixelColor(CenterLeft, 0);
strip.setPixelColor(FarLeft, c);
strip.show();
for(uint16_t i=0; i<11; i++) {
strip.setPixelColor(LeftCenterStrip[i], strip.Color(0, 0, 0));
strip.setPixelColor(LeftStrip[i], strip.Color(0, 0, 0));
strip.show();
delay(30);
}
//delay(wait);
strip.setPixelColor(FarLeft, 0);
strip.show();
colorWipe(stripe, 30);
//delay(wait);
}

void TurnRight (uint32_t c, uint32_t stripe, uint8_t wait) {
strip.setPixelColor(CenterRight, 0);
strip.setPixelColor(CenterLeft, 0);
strip.setPixelColor(FarRight, c);
strip.show();
for(uint16_t i=0; i<11; i++) {
strip.setPixelColor(RightCenterStrip[i], strip.Color(0, 0, 0));
strip.setPixelColor(RightStrip[i], strip.Color(0, 0, 0));
strip.show();
delay(30);
}
//delay(wait);
strip.setPixelColor(FarRight, 0);
strip.show();
colorWipe(stripe, 30);
//delay(wait);
}

void TurnAround (uint32_t c, uint32_t stripe, uint8_t wait) {
strip.setPixelColor(CenterRight, c);
strip.setPixelColor(CenterLeft, c);
strip.show();
for(uint16_t i=0; i<11; i++) {
strip.setPixelColor(LeftCenterStrip[i], strip.Color(0, 0, 0));
strip.setPixelColor(RightCenterStrip[i], strip.Color(0, 0, 0));
strip.show();
delay(30);
}
//delay(wait);
strip.setPixelColor(CenterRight, 0);
strip.setPixelColor(CenterLeft, 0);
strip.show();
colorWipe(stripe, 30);
//delay(wait);

}

void GoForward (uint32_t c, uint32_t stripe, uint8_t wait) {
strip.setPixelColor(CenterRight, c);
strip.setPixelColor(CenterLeft, c);
strip.show();
for(uint16_t i=0; i<11; i++) {
strip.setPixelColor(LeftCenterStrip[i], strip.Color(0, 0, 0));
strip.setPixelColor(RightCenterStrip[i], strip.Color(0, 0, 0));
strip.show();
delay(30);
}
colorWipe(stripe, 30);
//delay(wait);
}

// Slightly different, this makes the rainbow equally distributed throughout
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<11; i++) {
strip.setPixelColor(LeftCenterStrip[i], strip.Color(255, 255/i^16, 255/i^16));
strip.setPixelColor(RightCenterStrip[i], strip.Color(255, 255/i^16, 255/i^16));
strip.setPixelColor(RightStrip[i], strip.Color(255, 255/i^16, 255/i^16));
strip.setPixelColor(LeftStrip[i], strip.Color(255, 255/i^16, 255/i^16));
strip.show();
delay(wait);
}
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

Wear it!

Created by Becky Stern

The sample code uses the LEDs at the right and left edge of the helmet's brim to signal you to turn, and uses the two LEDs in the center of your forehead to tell you "go forward" (solid blue) or "turn around" (blinking red). Customize to your own navigation style!


Oh hey! You weren't thinking of wearing this helmet in the rain, were you? The circuit isn't waterproof! We recommend removing the battery if you have to wear it in the rain, then waiting until it's completely dry before reconnecting.

   


Repeat the process above with the GPS module, connecting corresponding TX/RX pads to FLORA (remember that TX goes to RX and RX goes to TX).

Sugru insulates the back of the GPS module from the LSM303 and FLORA main board, and also provides a semipermanent sticky situation. The silicone is not quite an adhesive, though it will remain affixed unless you choose to carefully peel it off.

The lithium polymer battery slides behind the elastic of the head brace. We sewed a small fabric pouch around the battery, which in turn was stitched

Optional: Generating Coordinates

Created by Becky Stern
You may need to re-generate the coordinates for the bike stations from time to time, and this page will show you how to do that.

Another reason you may want to re-generate coordinates is so you can use the bike share system in your city with the helmet! It isn't limited to the NYC Citi Bike system.

The below code will parse the wonderful citybik.es api:


var request = require('request');
var BIKE_SHARE_URL = 'http://api.citybik.es/citibikenyc.json';
request(BIKE_SHARE_URL, function (error, response, body) {
if (!error && response.statusCode == 200) {
var comma = ",";
var locations = JSON.parse(body);
locations.forEach(function(l, i) {
if (i === locations.length-1)
comma = "";

console.log(" {" + (l.lat / 1000000).toFixed(6) + ", " + (l.lng / 1000000).toFixed(6) + "}" + comma);
});

console.log(locations.length);
}
});
Let's not get too far ahead of ourselves though. First, we need to install the dependencies to run that code.

To start with, you'll need node.js. It's a really easy install. Navigate to http://nodejs.org, and follow the installation instructions for your operating system (Windows, Linux, and OS X are supported).

Next, create a folder somewhere (mine is titled 'cityparser'). Then, create a file in that folder titled parser.js and copy and paste the above snippet of code into that file, and save it.

Now, open your favorite command line utility (Terminal.app, cmd.exe, etc) and navigate into the 'cityparser' folder.

Now, we need to install the one dependency that is required for the parser to run. Execute the following from within the cityparser folder:


npm install request
Now that you have request installed, you can (finally!) run the parser to generate the locations for your particular city bike share program.

Execute the following command to run the parser:


node parser.js
Great! It should have output a bunch of coordinates with a count at the end of it.

For example, these are the last few of my output:


{40.715348, -73.960241},
{40.741472, -73.983209},
{40.736502, -73.978094},
{40.744449, -73.983035},
{40.702550, -73.989402},
{40.698920, -73.973329},
{40.716887, -73.963198},
{40.734160, -73.980242},
{40.725500, -74.004451},
{40.705311, -73.971000},
{40.765909, -73.976341}
311
If your output is similar to the above, you'll now want to choose the correct BIKE_SHARE_URL for your city (NYC pre-loaded).

Open the citybik.es api page, and scroll down to the section titled "System" and "JSON". Choose your location from the dropdown, and then replace it in the parser.js file variable "BIKE_SHARE_URL" and re-run the program.

Ok, now to set up your sketch. The last number in the results is the count of locations in that bike share. Take that number and place it in the sketch for the size of the array:


#define LAT_LON_SIZE 311
Then, copy and paste all of the locations (not the number), and replace the existing locations in the Bike Helmet Sketch. It should look something like this:


float lat_lon[LAT_LON_SIZE][2] PROGMEM = {
{40.767272, -73.993928},
{40.719115, -74.006666},
{40.711174, -74.000165},
{40.683826, -73.976323},
{40.702550, -73.989402},
{40.698920, -73.973329},
{40.716887, -73.963198},
{40.734160, -73.980242},
{40.725500, -74.004451},
{40.705311, -73.971000},
{40.765909, -73.976341}
};
Now, compile your sketch, upload it, and start biking!








9 comments:

  1. It's amazing to go to see this web page and reading the views of all mates concerning this
    piece of writing, while I am also keen of getting knowledge.


    My web page: cheap road bikes reviews

    ReplyDelete
  2. This post provides clear idea in support of the
    new viewers of blogging, that actually how to do blogging and site-building.


    Have a look at my web page: best chef knife to buy

    ReplyDelete
  3. Hello, I think your website might be having browser compatibility issues.
    When I look at your blog site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, very good blog!


    Feel free to surf to my webpage; what is the best juicer for the money

    ReplyDelete
  4. Inspiring story there. What occurred after?
    Good luck!

    Feel free to visit my page :: best rowing machines reviews

    ReplyDelete
  5. If you are going for most excellent contents like myself, just pay a
    quick visit this web page all the time for the reason that it
    presents feature contents, thanks

    Feel free to surf to my page; best knife set on the market

    ReplyDelete
  6. It's very straightforward to find out any matter on web as compared
    to books, as I found this piece of writing at this web page.


    Have a look at my webpage; best road bikes under 3000

    ReplyDelete
  7. Hi there mates, its impressive piece of writing on the topic of teachingand entirely explained, keep it up all the time.


    Stop by my web page juicers reviews fusion

    ReplyDelete
  8. Hello! I've been following your web site for a long time now
    and finally got the bravery to go ahead and give you a
    shout out from Houston Tx! Just wanted to mention keep up the excellent work!


    Feel free to surf to my web blog ... best road bikes for 1000 pounds

    ReplyDelete
  9. I am not sure where you're getting your info, but good topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for fantastic information I was looking for this info for my mission.


    Here is my blog post ... best budget rowing machine reviews; ,

    ReplyDelete