Arduino bootloader at 20mhz

I’ve been attempting to setup a 3pi and Baby Orang (both with 328p’s) to program from the Arduino IDE using a bootloader. The standard Arduino bootloader (optiboot, which is for 16mhz) does not work. Someone on this forum had recommend a 20mhz bootloader which I’ve tried. It works for one download after being burned, but requires being burned again to work again. I would guess that the auto-reset is part of the problem. I have a .1uf cap from my DTR line to the reset pin, which is how the Arduino auto-resets. I’ve also tried a 1uf cap, to attempt to extend the reset time. However, the 3pi and Baby Orang have a .1uf cap going to ground, which could be causing trouble.

So does someone have a working bootloader or hardware work-around?

If you’re wondering why I can’t just use the AVR ISP programmer, it’s because I’m testing the Baby Orang for educational purposes, and students can’t be trusted as well to check the batteries before programing. The possibility of bricking a chip because of low voltage really bothers my friend who is teaching robotics courses for middle/high schoolers.

Hello, Darth Maker.

To use a 16MHz bootloader with a MCU running at 20MHz, you have to adjust your upload baud rate in the boards.txt file. For example, if your bootloader is expecting a baud rate of 19200 bps, you have to multiply by 20 and divide by 16, which gives a baud rate of 24000 bps. Depending on what baud rate your bootloader runs at, this might get too quick for the serial connection to handle. Here is the boards.txt file that I’ve used to flash a bootloader on the 3pi Robot (it should also work for the Baby Orangutan but I haven’t tested it):

orangutan328.name=Pololu Orangutan or 3pi robot w/ ATmega328 via Bootloader

orangutan328.upload.protocol=stk500
orangutan328.upload.maximum_size=14336
orangutan328.upload.speed=72000

orangutan328.bootloader.low_fuses=0xF6
orangutan328.bootloader.high_fuses=0xDA
orangutan328.bootloader.extended_fuses=0x05 
orangutan328.bootloader.path=atmega
orangutan328.bootloader.file=ATmegaBOOT_168_atmega328.hex
orangutan328.bootloader.unlock_bits=0x3F
orangutan328.bootloader.lock_bits=0x0F

orangutan328.build.mcu=atmega328p
orangutan328.build.f_cpu=20000000L
orangutan328.build.core=arduino

The reset problem is a little trickier. Because the Baby Orangutan has a capacitor between RESET and GND, the circuit doesn’t go low enough to trigger a reset. To get it to work you need to make a circuit that can drive the RESET line low directly, perhaps by using some transistors.

- Ryan

Hello.

I think an easier solution to your reset problem than the one Ryan mentioned would be to remove the capacitor between reset and ground (or cut the trace to it). It turns out that this capacitor is not necessary since the AVR’s reset circuit has built-in spike suppression that already performs the capacitor’s intended function, and we have stopped including this capacitor on our more recent Orangutan models with no observed negative consequences. Please let me know if you need a diagram showing you where this capacitor and the relevant traces are on the Baby Orangutan and the 3pi.

- Ben

I tried that code in the board.txt file, I got an error from the IDE:

avrdude: serial_baud_lookup(): unknown baud rate: 72000

I had tried a similar technique using the 16mhz optiboot bootloader and the baud rate set to 144000, which got me the same error.
I’ve been using IDE version 22, so I downloaded 1.0 and 23, and will test them.

I have cut the trace running to the cap and resistor on the Baby orang, but the diagram for the 3pi would be great.

Update:

I tried 23 and got the same error. 1.0 wont even compile it’s own example code.

EDIT:
I just got my 3pi and Baby Orang during you’re sale. Should they have the cap and resistor? And if not, I wonder what I cut…

I’ll let Ryan address the avrdude problems you’re having since it sounds like he might have already solved them, but a quick search of the error you received led to this page:

avrdude.sourcearchive.com/docume … ource.html

It seems that avrdude is restricting the baud rates to the values in this table:

static struct baud_mapping baud_lookup_table [] = {
  { 1200,   B1200 },
  { 2400,   B2400 },
  { 4800,   B4800 },
  { 9600,   B9600 },
  { 19200,  B19200 },
  { 38400,  B38400 },
  { 57600,  B57600 },
  { 115200, B115200 },
  { 230400, B230400 },
  { 0,      0 }                 /* Terminator. */
};

I also found a forum post where someone got past this limitation by rewriting the look-up function to just return the supplied argument.

The 3pi and Baby Orangutan both still have capacitors to ground and pull-up resistors on their reset lines. More recent Orangutans, like the Orangutan SVP no longer have these components. The following diagrams show the relevant components and have yellow marks where I suggest you cut the traces. Please note that cutting the traces elsewhere could cause pretty big problems, such as making in impossible to reprogram the AVR with an ISP programmer (the programmer needs to be able to hold the AVR in reset during programming).





Note that my suggested cutting point on the Baby Orangutan will also sever the reset line’s pull-up resistor, but the AVR has an internal pull-up on the reset pin, so this won’t hurt anything. If you already cut your traces elsewhere, you might need to repair the cut and try again.

Please let me know if you have any questions.

- Ben

I’m sorry, I forgot about the step that lets you get around this problem. What I did was download a never version of WinAVR and install it into my Arduino environment folder. I think I remember that using the newer version of WinAVR has some other side effects (unfortunately, I forget what they are), which makes it not work very well or at all with the default Arduino boards. Anyway, here are the steps to do it:

I downloaded WinAVR version 20100110, ran the installer, and installed it into

arduino-0022\hardware\tools\avr-new

Whenever I want to use it, I rename

arduino-0022\hardware\tools\avr

to

arduino-0022\hardware\tools\avr-old

then I rename

arduino-0022\hardware\tools\avr-new

to

arduino-0022\hardware\tools\avr

- Ryan

It did not compile until I moved a folder called “etc” containing avrdude.conf from the old avr folder. I’m still getting a not in sync error. This is the verbose output:

C:\Documents and Settings\Saber\Desktop\Programming\arduino-0023\hardware/tools/avr/bin/avrdude -CC:\Documents and Settings\Saber\Desktop\Programming\arduino-0023\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM3 -b72000 -D -Uflash:w:C:\DOCUME~1\Saber\LOCALS~1\Temp\build7100978771676229017.tmp\Fade.cpp.hex:i 

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Documents and Settings\Saber\Desktop\Programming\arduino-0023\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 72000
avrdude: serial_baud_lookup(): Using non-standard baud rate: 72000avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.

I have the connections correct between my modern devices USB BUB II and the Baby Orang. I’m powering from the USB BUB, with 5V going to the Vin pin, but it works (or rather, doesn’t work) the same if I provide unregulated power to it (2cell Lipo, ~7.4V).

I flashed the bootloader from AVR Studio 4, since the Arduino IDE wont recognize the Pololu AVR ISP. I used the bootloader .hex named in you addition to the boards.txt file.

I’m going to try a couple more things, but maybe you could try running through the steps yourself with starting with a fresh Arduino install, and new bootloader flash to the 3pi/Baby Orang?

I’m wonder is there could be some problem with how the fuses are set. In the board.txt, it shows 0xDA and 0xF6 for high and low. I wrote these to the device, but the extended fuses are supposed to be 0x05, and I wont allow me to write them (Pololu AVR ISP). So it has 0xFD.

I don’t know if that could be part of the problem.

Hello, Darth Maker.

With a fresh installation of Arduino 1.0, I was able to load Optiboot on a Baby Orangutan B-328 and then program it via the bootloader using these steps:

  1. Edit arduino-1.0/hardware/arduino/boards.txt and add the following to the bottom (this is different than what Ryan posted earlier):
orangutan328.name=Pololu Orangutan or 3pi robot w/ ATmega328

orangutan328.upload.protocol=arduino
orangutan328.upload.maximum_size=32256
orangutan328.upload.speed=144000

orangutan328.bootloader.low_fuses=0xF6
orangutan328.bootloader.high_fuses=0xDE
orangutan328.bootloader.extended_fuses=0x05 
orangutan328.bootloader.path=optiboot
orangutan328.bootloader.file=optiboot_atmega328.hex
orangutan328.bootloader.unlock_bits=0x3F
orangutan328.bootloader.lock_bits=0x0F

orangutan328.build.mcu=atmega328p
orangutan328.build.f_cpu=20000000L
orangutan328.build.core=arduino
orangutan328.build.variant=standard
  1. Edit programmers.txt in the same directory and add the following to the bottom:
avrispv2.name=AVR ISP v2
avrispv2.communication=serial
avrispv2.protocol=avrispv2

(This assumes that you are using our USB AVR programmer to load Optiboot on the Baby Orangutan. If you are using a different programmer, you can modify or skip this step as appropriate.)

  1. Cut the reset trace on the Baby Orangutan as indicated in Ben’s earlier post.
  2. Connect the Orangutan to the programmer and apply power.
  3. Open Arduino 1.0.
  4. In Tools > Board, select the entry for the Orangutan you added earlier.
  5. In Tools > Serial Port, select the USB AVR Programmer Programming Port.
  6. In Tools > Programmer, select the AVR ISP v2 entry you added earlier.
  7. Select Tools > Burn Bootloader. After this completes, you can disconnect the Orangutan from the programmer.
  8. Connect the Orangutan to your serial adapter. I used a 0.1 uF capacitor between DTR and the Orangutan’s RESET. (You should make sure the Orangutan is unpowered while you do this.)
    In Tools > Serial Port, select the port that your serial adapter is using. You should now be able to program the Orangutan using the bootloader with the Upload button.

For some reason, I did not run into the serial baud rate problem and did not have to replace WinAVR; maybe my different settings in boards.txt allowed me to avoid the problem. Let us know if these steps work for you.

- Kevin

Well, thank you for all your help. I think it would have been working a couple posts ago, but it turns out I cut into the Rx line trace while cutting the reset trace. It was small enough that I couldn’t see it (next time I know to check the traces around a cut), so I only found it after I decided to test the Rx line outside up uploading code.

Kevin, you instructions are very good, maybe they could be added to the official Pololu guide to getting Orangs and the 3pi working with Arduino. Along with the pictures ben used in his post.

So, it working now (after a quick trace repair.) Thank you all again!

EDIT:
It looks like your Orang and 3pi Arduino libraries will need to be updated to work with IDE 1.0.