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:
Everything securely attached underneath the car:
Glowing:
The finished car after the race:
Flashy Pinewood Derby Car
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88092
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flashy Pinewood Derby Car
Nice looking car!
- Cuzzi23
- Posts: 6
- Joined: Mon Jan 12, 2015 3:25 pm
Re: Flashy Pinewood Derby Car
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.
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.
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
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();
}
- Cuzzi23
- Posts: 6
- Joined: Mon Jan 12, 2015 3:25 pm
Re: Flashy Pinewood Derby Car
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.
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.
- gerber1725
- Posts: 2
- Joined: Tue Jan 20, 2015 3:28 pm
Re: Flashy Pinewood Derby Car
Would you be willing to share a simple wiring diagram for this project? I'm fairly new to this sort of thing.
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
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: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
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.
- Cuzzi23
- Posts: 6
- Joined: Mon Jan 12, 2015 3:25 pm
Re: Flashy Pinewood Derby Car
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'
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'
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
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
#include <TinyWireM.h>
#include <Adafruit_TinyLSM303.h>
#include <Adafruit_NeoPixel.h>
Here are links to the libraries:
TinyLSM303
TinyWireM
NeoPixel
- Cuzzi23
- Posts: 6
- Joined: Mon Jan 12, 2015 3:25 pm
Re: Flashy Pinewood Derby Car
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!!!!
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!!!!
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
Excellent! I'm glad you got it figured out and I'm looking forward to seeing the photos.
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
I put the code into github for sharing purposes so here's the link if anyone's interested.
PinewoodCar
PinewoodCar
- eagleeye2e
- Posts: 12
- Joined: Thu May 02, 2013 9:46 am
Re: Flashy Pinewood Derby Car
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.
Please be positive and constructive with your questions and comments.