Flashy Pinewood Derby Car
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Flashy Pinewood Derby Car

by eagleeye2e on Sun Mar 23, 2014 12:39 pm

We decided to add a little high-tech flash to my son's Pinewood Derby car this year. This project involved several Adafruit products including a 3.3v Trinket, a NeoPixel stick, a FLORA Accelerometer/Compass Sensor, and a Lithium Ion Polymer Battery. All of these components were chosen for their size and their light weight. The idea was to have a subtle yellow glowing effect under the car while it was at rest and while the car was in motion going down the track the pixels scroll from front to back with a brighter, different, color. The faster the car goes, the faster the pixels scroll. In addition, every time the car goes from scroll to rest, the color of the scrolling pixels changes to a new color for the next race. The car received many complements and oooh's and ahhh's. Thank you Adafruit for all of the great products that allowed us to add something fun and unique to our Pinewood Derby experience!

All of the components soldered together:
Image

Everything securely attached underneath the car:
Image

Glowing:
Image

The finished car after the race:
Image

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by adafruit_support_bill on Sun Mar 23, 2014 12:54 pm

Nice looking car!

adafruit_support_bill
 
Posts: 39252
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashy Pinewood Derby Car

by Cuzzi23 on Mon Jan 12, 2015 3:32 pm

Hey Great car!
Looking to do the same for my son.
Would you be so kind as to share the code?
I'm starting with arduino. No way that I can write this on my own yet.
Thanks in advance.

Cuzzi23
 
Posts: 4
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

by eagleeye2e on Tue Jan 13, 2015 10:59 am

This is essentially the code that I used but I cleaned it up a bit and added some more descriptive comments. Let me know if you have any issues or questions.

Code: Select all | TOGGLE FULL SIZE
#include <TinyWireM.h>
#include <Adafruit_TinyLSM303.h>
#include <Adafruit_NeoPixel.h>

#define MOVE_THRESHOLD 10000      // Adjust this threshold as needed to trigger led motion.
#define PIXEL_OUTPUT 1            // Trinket pin that the NeoPixel stick is connected to.   
#define NUM_PIXELS 8           
byte brightness = 40;             // Set to a low value to conserve power on the small LiPo battery.
int32_t DefaultColor = 0xffbf00;  // Set the "glowing" color for when the car isn't moving.
                                  // Note when the car is at rest, only every-other pixel will be on. This
                                  //   was done to conserve battery power.

int32_t  accelx = 0;              // I'm only interested in the x-direction accelerometer data.
                                  // Note that the X-axis arrow on the accelerometer points to the front of the car.
uint32_t color = 0xff0000;
boolean changeColor = false;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIXEL_OUTPUT, NEO_GRB + NEO_KHZ800);
Adafruit_TinyLSM303 lsm;

void setup(){
  pixels.begin();
  pixels.setBrightness(brightness);
  setColor(DefaultColor);
  lsm.begin();
}

void loop(){
  lsm.read();
  accelx = (int32_t)lsm.accelData.x;
  if(abs(accelx) > MOVE_THRESHOLD){
    if(changeColor){  // This section changes the color of the scrolling pixels after the car has gone from moving to rest.
      color >>= 8;    // Color progression is red -> green -> blue then start the color cycle over again.
      if(!color) color = 0xff0000;
      changeColor = false;
    }   
    setColor(pixels.Color(0, 0, 0));
    pixels.show();
    pixels.setBrightness(180);                     // Boost the pixel brightness during motion.
    for(int i=NUM_PIXELS-1; i>=0; i--){            // This loop controls the scrolling motion of the pixels.
      pixels.setPixelColor(i, color);
      if(i < NUM_PIXELS-1){
        pixels.setPixelColor(i+1,pixels.Color(0, 0, 0));
      }
      pixels.show();
     // The use of delay() below is not optimal. Future code improvement opportunity.
      if(abs(accelx) > MOVE_THRESHOLD+4000){       // If moving super fast make pixels scroll super fast. Adjust +xxxx as needed.
        delay(10);
      }
      else if(abs(accelx) > MOVE_THRESHOLD+2000){  // If moving fairly fast make pixels scroll fairly fast. Adjust +xxxx as needed.
        delay(20);
      }
      else{  // Default pixel scrolling speed.
        delay(30);
      }
    }
    pixels.show();
    setColor(pixels.Color(0, 0, 0));
  }
  else{
    changeColor = true;
    pixels.setBrightness(brightness);              // Reset to power-saving brightness.
    setColor(DefaultColor);                        // Reset to default pixel color.
  }
}

void setColor(uint32_t color){
  // This function sets the color for every-other pixel.
  // This was done as another way to conserve battery power.
 
  for (int i = 0; i < NUM_PIXELS; i+=2) pixels.setPixelColor(i,color);
  pixels.show();
}

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by Cuzzi23 on Wed Jan 14, 2015 2:12 pm

Well
Many, many thanks.
I'm going to order the parts and give it a shot.
My little guy will love it and hopefully I can get my older boy "hooked".
Again, thanks and I'll keep you posted.

Cuzzi23
 
Posts: 4
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

by gerber1725 on Tue Jan 20, 2015 4:03 pm

Would you be willing to share a simple wiring diagram for this project? I'm fairly new to this sort of thing.

gerber1725
 
Posts: 1
Joined: Tue Jan 20, 2015 3:28 pm

Re: Flashy Pinewood Derby Car

by eagleeye2e on Wed Jan 21, 2015 10:23 am

I don't have a wiring diagram readily available but I'll put one together and get it posted as soon as I can.

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by eagleeye2e on Wed Jan 21, 2015 11:08 am

Here is a simple wiring diagram. Note that the NeoPixel component in the schematic is labeled as a 16 pixel ring instead of the 8 pixel stick but the connections are the same. Also note that the battery size in the schematic isn't exactly the same one I used but it shows proper connections. One last note is that the switch is generic and the schematic doesn't represent the exact implementation that I used but any switch configuration will work as long as it connects and disconnects the battery from the rest of the circuit. I happened to have a dpdt switch that had leads almost the exact size to match the JST-connector on the battery so that's what I used.

PineWoodCar_schem.png
Wiring Diagram
PineWoodCar_schem.png (98.32 KiB) Viewed 375 times

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by Cuzzi23 on Mon Jan 26, 2015 9:31 am

Hey, thanks for all again.
I'm clueless over here, I'm getting the following error when trying to compile the sketch:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Adafruit Gemma 8MHz"
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp: In member function 'void Adafruit_TinyLSM303::read()':
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:43: error: 'class USI_TWI' has no member named 'write'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:50: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:51: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:52: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:53: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:54: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:55: error: 'class USI_TWI' has no member named 'read'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp: In member function 'void Adafruit_TinyLSM303::write8(byte, byte, byte)':
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:70: error: 'class USI_TWI' has no member named 'write'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:71: error: 'class USI_TWI' has no member named 'write'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp: In member function 'byte Adafruit_TinyLSM303::read8(byte, byte)':
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:80: error: 'class USI_TWI' has no member named 'write'
C:\Program Files (x86)\Arduino\libraries\TinyLSM303\Adafruit_TinyLSM303.cpp:83: error: 'class USI_TWI' has no member named 'read'

Cuzzi23
 
Posts: 4
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

by eagleeye2e on Mon Jan 26, 2015 11:21 am

Do you have all of the required libraries installed? It looks like you might be missing the TinyWireM library. These 3 includes are all external libraries that you'll need:

#include <TinyWireM.h>
#include <Adafruit_TinyLSM303.h>
#include <Adafruit_NeoPixel.h>

Here are links to the libraries:
TinyLSM303
TinyWireM
NeoPixel

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by Cuzzi23 on Mon Jan 26, 2015 11:51 pm

Well, thanks again.
I thought I had done it correctly, but not.
I deleted the libraries I had installed and used your links to re do it.
Worked beatifully
I think I had renamed one of the libraries incorrectly.
Many thanks again. I will post photos as soon as we build the car and squeeze all the wires in.
Looking gooooooood!!!!

Cuzzi23
 
Posts: 4
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

by eagleeye2e on Tue Jan 27, 2015 12:25 am

Excellent! I'm glad you got it figured out and I'm looking forward to seeing the photos.

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by eagleeye2e on Tue Jan 27, 2015 9:31 am

I put the code into github for sharing purposes so here's the link if anyone's interested.
PinewoodCar

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Re: Flashy Pinewood Derby Car

by eagleeye2e on Fri Mar 20, 2015 7:41 am

My son wanted to have a Lego Movie themed car so I suggested the Kragle and that became our mission. We put most of the same electronics on the car this year but upgraded to a bigger LiPo battery. I completely changed the code and made it so the LED's do a slow scanning effect. I had hoped to convert the acceleration data into velocity somehow to better represent the speed of the car but I kept running into the memory limit of the trinket so it's still not the way I want it but it's better than nothing. Here are some pictures of this year's pinewood derby car.

Image

Image

Image

Image

eagleeye2e
 
Posts: 9
Joined: Thu May 02, 2013 9:46 am

Please be positive and constructive with your questions and comments.