Saturday, January 30, 2010

Bootloader woes!

I have some AVR 328s that I'd like to upgrade to LadyAda's bootloader. Which has a couple of features for homemade arduino boards:

1. Three flashes on reset. Her bootloader flashes pin 13 when reset occurs.
2. Upload flicker on pin 13.

Although not absolutely necessary, it sure is nice to get the positive feedback that things are working when any number of things can go wrong with a home build duino.

The MegaISP seemed to work ok, but requires 2 arduinos to program a new Mega chip: one to run MegaISP, and one to house the chip to be programmed. I thought I could simplify things by buying this programmer, but it has been difficult to get this working.

Here is how I got it working on my Linux box.

1. Power the chip. The programmer does not supply the power to the chip as I discovered. So I was beating a dead horse for a day not knowing this simple fact.

2. Disconnect anything from the board. When I powered the board, I still got the same error. avrdude stk_500v2 not responding. I had an LED connected to pin 13 that I guess was sapping the signal from the micro back to the computer.

3. Plug programmer into usb port. You should see a device /dev/ttyACM0 or similar. That is the programmer. Green light on programmer should be on. If you are an avrdude guru, you probably already know to use the -P /dev/ttyACM0 option. I had trouble getting avrdude to write the efuse, so I tried using Arduino IDE to write the bootloader.

4. Unplug arduino from usb, power it with a 9v or otherwise through VIN. We are going to program the chip through /dev/ttyUSB0 and we don't want to figure out if USB0 is the programmer or the duino. Just unplug it from the usb all together and use external power.

5. Arduino IDE expects to see the programming sitting at /dev/ttyUSBX and it is actually at /dev/ttyACM0. The solution here is so simple I never thought it would work. Use a soft link. I don't remember where I found this solution, but it works.
> sudo ln -s /dev/ttyACM0 /dev/ttyUSB0

6. Select Tools->Burn Bootloader->w/AVRISP mkii. After a couple of minutes the bootloader is loaded.

7. Upload blink.pde. If this loaded congratulations. This worked for me with the standard bootloader: ATmegaBOOT_168_atmega328.hex.

8. Move standard bootloader for safekeeping, cd to Arduino/hardware/bootloaders/atmega/
> mv ... /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex-orig

9. Copy AdaBoot to expected bootloader location
>mv ATmegaBOOT_xx8_adaboot328.hex /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex

10. Tools->Burn Bootloader->w/AVRISP mkii (again)

11. Upload blink.pde. This is where I am stuck. Blink will not upload. I see this in the output window after I see the 3 blink reset (so I know adaboot is running):
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

Manual reset (at different delays from upload click) makes no difference.

UPDATE!
LadyAda suggested that perhaps the baud rate for the hex file I was using was 19200. This turned out to be the case. I modified */hardware/boards.txt by changing

atmega328.upload.speed=57600

to
atmega328.upload.speed=19200

and got blink.pde to upload and run. Thanks LadyAda! The real fix is to upload the 57600 hex adaboot file. Look for an uplate when I get this to run.

UPDATE:
I recompiled LadyAda's AdaBoot with the baudrate changed to 57600. Download the hex file here.

Or, to compile it yourself:

Download and unzip AdaBoot.

Change the baudrate in the C source code will do the trick. Line 90 of the source code reads:
#define BAUD_RATE 19200

Change this to
#define BAUD_RATE 57600

Then from the command line:
> make adaboot328

If you have all everything you need installed you will generate a hex file. Or you can use this 57600 hex file if you don't.

To upload with avrdude only try just talking to the chip first:
> avrdude -c stk500v2 -p m328p -P /dev/ttyACM0
(change -P as necessary)

If that works, this script will upload the hex file using only avrdude
#!/bin/sh
# change -P as necessary
#
# find extended, high, low, lock, and unlock bits on hardware.txt
OPTS="-c stk500v2 -p m328p -P /dev/ttyACM0"
avrdude $OPTS -U efuse:w:0x05:m
avrdude $OPTS -U
hfuse:w:0xda:m
avrdude $OPTS -U lfuse:w:0xff:m

avrdude $OPTS -U lock:w:0x3f:m
avrdude $OPTS -U flash:w:ATmegaBOOT_xx8_adaboot328.hex:i
avrdude $OPTS -U lock:w:0x0f:m



Here is a picture of the programming setup.  I had to stack several 2 x 14 DIL sockets to make room for the 6 pin programming cable.  The green socket has a lever that releases the chip... handy.

AdaBoot: Succeed!

6-22-2010 Update:
I am pleased to confirm that this process works with fresh ATMEGA 328 chips (no previous bootloader installed).

May 30, 2011 UPDATE:
I just got a new set of MEGAs from digikey with a different device signature.
The old signature that avrdude expected is
"0x1e950f".

The chips I received with the same part number had a signature of
"0x1e9514".

There are two ways to handle this.  The easiest is to use the -F option with avrdude to force it into action regardless of the signature.  The second is to change the device signature in avrdude.conf (mine was located in /etc/avrdude.conf).  Search for 328, then search again for signature.  I commented out the existing line and modified it like so
# signature = 0x1e950f
signature =0x1e9514

This works like a charm until you need to program older chips in which case you need to revert to the original version.


Tuesday, January 19, 2010

Good bye suburban ignorance...

Hello Urban Awareness!




Jacket finally arrived today, we were all dazzled by the glow of the coat and by our new found urban/youthy chicness.

This coat rocks.

Monday, January 18, 2010

First Draft SharkFin Layout!


Anool, turned around the sketch below into the layout seen here in 12 hours, and he has a real job to boot! I'm starting to think the SharkFin is going to become a reality. Priya has offered to help out with the enclosure, with her eye for design, we have a hit for sure.

Sunday, January 17, 2010

SharkFin Preliminary Layout

Here is a rough layout for the SharkFin.

Notes:
1. The lower right hand corner is square. All components are aligned relative to this corner. The actual orientation will put the LEDs horizontal.
2. SparkFun and Pololu make the layouts for the three daughter boards available. It may save a lot of space and money to put those parts right on the motherboard. For know, routing can be done underneath of the daughter boards.
3. S1 is reset, S2 is for mode changing (night/day), S3 is power, and SEL is power select.
4. Note Power Down pin on Gyro is grounded. This stops spontaneous shutting down of the gyro.
5. I'm not sure if power select is required. I'm worried that I would be able to communicate through the USB at the 3.3V level provided by the power supply circiut.
6. The ATMega 328 is only rated at 12MHz for 3.3V. Not sure how this will impact serial connection. Might just fudge a little and try the 16MHz osc at 3.3V. Seems to work on the BEBL!
7. Routing may be tricky. Looks like a two sided board to me.
8. D5 is not an LED, but a Zener Diode as for programming feedback ala LadyAda's supped up boot loader.
9. The two large circles are through holes for mounting the board to the helmet.

Thursday, January 14, 2010

Anool's Brake Light: Succeed

Anool has completed his brake light and it looks awesome! He started by prototyping on the Duemilanove. Once he understood the circuit, he designed a printed circuit board. Finally he designed and built this elegant project enclosure. The aluminium mount doubles as a power jumper, eliminating the need for a separate switch.


Great job Anool!

The central blue LED was too bright and had to be turned off to capture this video.

Tuesday, January 12, 2010

Brake Light Mod!



Instructables reader, Anool, has printed up some PCB's from the BEBL schematic. This larger 5-light version will be mounted on the seatpost. He was generous enough to send me a couple of the boards. I'll be looking forward to receiving them.

If all goes well, Anool and I will have the SharkFin boards ready soon!

Thanks Anool!

Wednesday, December 30, 2009

Scopy




To debug the gyro voltage on the SharkFin, I made a simple Arduino based oscilloscope. Single channel, no triggers, no frills.

Python, pylab, and gtk are required.

1. upload scope.pde to arduino
2. edit scopy.py to point to your Arduino (see Tools->Serial Port in Arduino IDE)
3. run scopy.py on computer
4. if you improve either, please send me the update.

Tuesday, December 15, 2009

BEBL Takes "Light Up the Night" Grand Prize!



WOW, Instructables just announced that the BEBL won the Light Up the Night Contest! They are shipping out the sweet Grand Prize "Urban Awarness Jacket" from Cordarounds.

I entered the contest on a lark when I entered the Arduino Contest. Who would have guessed?

Thanks for all the support!

Thursday, December 03, 2009

BEBL Instructable takes 2nd Prize

The BEBL instructable took 2nd prize in the instructables Arduino contest. Thanks to everyone who voted!

Saturday, October 31, 2009

Take the BEBL Challange!

In order to encourage people to make the BEBL, I am offering $35 to the first person to build and demonstrate a functioning BEBL system. That should be enough to cover the cost of the electronic components.

To claim the prize, post a video on line of your accomplishment demonstrating functionality both on and off the bike. The video should include close-ups of the completed hardware. I will address any assembly questions posted here or at Instructables.

Good luck!


The Bar End Brake Light instructions have been made into an instructable and entered into the Arduino Contest.

Sunday, October 25, 2009

Jack-o-duino

Elizabeth and I were inspired this entry in the Instructables Arduino contest. We replaced the servo with a relay to the same effect. It's loud. If we were bomb makers, we'd be dead several times over. Source code can be found here.

Tuesday, October 13, 2009

Arduino contest at Instructables!

Keep an eye out for BEBL on Instructables.com. I'll be entering it into the Arduino contest.

Saturday, September 19, 2009

BEBL: Updated schematic

Here is the latest schematic for the Bar End BrakeLight BEBL. Got in the first test ride and it performs amazingly well. The response time seems almost clairvoyant. Ahhh, it feels so good when it stops hurting.

The main change is the power supply fix mentioned in the previous post. The 6V battery I used is this one from RadioShack, but you can find it cheaper on the web. Other changes to note are the power select jumper and the power switch.

The power select jumper allows switching power between the regulated 3.3v from the accel and 5V USB power. This allows the unit to be programmed. The 5V from the USB only powers the micro controller. The 3.3V sensors are therefore protected from the extra voltage. AREF remains connected to 3.3V. I found the switch S2 at Radio Shack. It is perfect. You can access the switch and it stays concealed under the bar. Sweet.

Friday, September 18, 2009

Duh, use the 3.3 Volt regulator on the accel!

So there was a current issue with running directly off of the battery. I was getting variable readings on the accel when no accelerations were being applied. I'm no EE, so power supplies are a mystery to me. May be the unregulated power was experiencing boom and bust cycles like Wall Street.

Then I remembered the 3.3V regulator on the accel breakout from pololu. Now I run the power right into Vin on the accel and power the rest of the circuit off of the 3.3V regulated output-- fixed. I'd appreciate any better explaination if you know have one.

Now back to the software.

Monday, August 31, 2009

Bar End Brakelight Working... kinda.

So the hardware on the bar end brake light prototype is complete.


I need to work on the software to get the sensitivity right (solution posted here). The initial code only used one axis of accel data. Better to use two and compare against a floating reference. If an absolute reference (say horizontal) is used, stopping on a hill might trigger the brake light. So more work to come.

I was definitely pleased with the package which slides right into the bar snuggly. I had to shave off some plastic on the DIP socket to get the oscillator to fit. The chipped part above (upper left of IC) is a testament to the snug fit. I used an unregulated 6V mini battery to power the circuit which is the max voltage rating for the Mega. The accel has its own 3V regulator. The accel reading seems to be coupled with the LED on/off state. Maybe I need larger caps on the digital and analog pins. Any ideas welcome.

I use the arduino environment to program the Mega. Below is my development board with the same accel plus a gyro that will eventually go on the SharkFin. After I program the chip, I pop it into the socket on the bar end unit.

Dev Env


This picture shows the unit installed. I found the perfect switch at Radio Shack (see bottom of picture).

Saturday, August 22, 2009

Bar End Brakelight

I've been making progress on integrating the gyro with the accel. When the electronics are done there is still the whole question of packaging! I decided to put togethere a simple bar end break light to get the most bang for the buck early on. Need to add the oscillator and a switch and I'll be up and running.

Here is a pic with a wine cork for size comparison.


And simplified schematic.

Friday, July 17, 2009

SharkFin

Here is the schematic for a new helmet mounted break light I've been working on. The idea is to measure acceleration and rotation enough to detect breaking from any head angle. Working on the filter now. The prototype is based on the Boarduino from ladyada.net with two breakout boards available from pololu.com.


Saturday, July 04, 2009

Improved brake light

So the brake light was acting a little flaky, turning on over bumps at random. Before, I was using a moving average filter, with ad-hoc checks. I decided to try out a IIR filter because they can produce good results with few taps. This is my first implementation of such a filter.

Infinite impulse response or IIR filters combine measured (feed forward) data and filtered (feed back) data. They get their name because a single non-zero input sample followed and preceded by all zeros can cause the filter to oscillate indefinitely as opposed to a finite impulse response or FIR filter which will return to zero after at most N measurements where N is the number of filter coefficients.

The problem with the brake light was that high frequency jitters were tripping the braking threshold. The only information I really car about is sustained braking, which is low frequency information. I needed a low pass filter, a filter that passes low frequency information and attenuates high frequency information. The Butterworth filter is a low pass IIR filter that is working great for this application.

The filter coefficients are determined by the sample interval, the cutoff frequency, and the number of filter coefficients to use. I chose 2 Hz to be the cutoff frequency. Any lower frequency would delay brake indication, any higher frequency could let in unwanted jitter. I wanted to keep the number of filter coefficients small so that the micro could keep up, It is having no trouble with that; I could probably get away with more filter coefficients, but that delays response time as well.

I was pleased to see how well this filter performed!
I captured this acceleration data riding up and down the street without braking and with. In each image, the raw data is pictured in blue, the filtered data is in yellow, and braking threshold (on the top plot) is indicated in red. As you can see, the raw data is very noisy. The noise is actually bumps on the side of the road, so don't blame the pololu 3-axis accelometer ($17.95!!) breakout I'm using. I purposely aimed for them to make sure the threshold was not set to high which could set of the brake lights every time you hit a bump. With the unfiltered data, it is impossible to set a consistent threshold for turning on the brake lights. The filtered data works though!

The above image just was captured with out braking. I just rode up and down the street without touching the brakes. The threshold was set near the minimum filtered acceleration in the X direction.

This data was collected getting up some speed and braking to various degrees. The X direction is in the velocity direction. Deceleration is indicated by lower X values. You can see the braking go below the threshold even for mild braking.

The Y and Z axis will be used for a future helmet mounted version.

Here is a snap of my data capture setup, thanks to the wave shield from ladyada, and battery and dual proto board from liquidware.com








Here are the filter coefficients, they should work with any IIR filter implantation. The complete BikeLight5 code can be found here.

// feed forward coefficients
double ff[] = {
1.93545410516e-06,
5.80636231547e-06,
5.80636231547e-06,
1.93545410516e-06
};
// feed back
double fb[] = {
1.0,
-2.94973583971,
2.90072698836,
-0.950975665016
};

Sunday, June 07, 2009

Arduino on a bread board.

I've got a couple of ideas for AVR chips freed from the arduino board. Below is my scratch built* arduino. Thanks to LadyAda for posting the schematic for the BoardDuino. Schematic to come.



* By "scratch built" I mean, assembled from the contents of the boardduino kit.