Flashy Pinewood Derby Car

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eagleeye2e
 
Posts: 12
Joined: Thu May 02, 2013 9:46 am

Flashy Pinewood Derby Car

Post by eagleeye2e »

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

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashy Pinewood Derby Car

Post by adafruit_support_bill »

Nice looking car!

User avatar
Cuzzi23
 
Posts: 6
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

Post by Cuzzi23 »

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.

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

#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();
}

User avatar
Cuzzi23
 
Posts: 6
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

Post by Cuzzi23 »

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.

User avatar
gerber1725
 
Posts: 2
Joined: Tue Jan 20, 2015 3:28 pm

Re: Flashy Pinewood Derby Car

Post by gerber1725 »

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

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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.
Wiring Diagram
Wiring Diagram
PineWoodCar_schem.png (98.32 KiB) Viewed 2251 times

User avatar
Cuzzi23
 
Posts: 6
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

Post by Cuzzi23 »

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'

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

User avatar
Cuzzi23
 
Posts: 6
Joined: Mon Jan 12, 2015 3:25 pm

Re: Flashy Pinewood Derby Car

Post by Cuzzi23 »

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!!!!

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

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

Re: Flashy Pinewood Derby Car

Post by eagleeye2e »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”