Let's Make Robots!

Arduino project losing its mind

I'm using Ro-Bot-X's uservotino for my Venux robot. I recently had a problem where the sketch (program, for all you non-Arduino types) disappeared on me. The board would power up fine, but nothing would happen. Then I upload the sketch again and everthing is fine.

I thought it was an isolated incident, but it just happened again! Any thoughts on what would cause an Adruino to lose its mind?

EDIT: The issue turned out to be with the Brown Out Detection (BOD) settings on the Arduino bootloader. The BOD defined in the bootloader was disabled. When the power to the Arduino dips too low, it can wind up corrupting memory, including the stored code. The BOD feature tells the processor to reset if the power dips below a selectable threshold. Since my chip didn't have a BOD threshold set, I lost the program code.

To change the BOD setting, I'll need an ISP programmer, which I don't currently have. So I'll probably just live with this for now. Thanks for all the help figuring out what happened!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

IG, do you have another Arduino? Then you already have a hardware programmer! Arduino ISP! Use it! Hack your µBotino if no other option. Just unplug the Dtr wire from your FTDI cable to avoid the auto-reset of the µBotino (after you upload in it the Arduino ISP sketch). Then make the connections from one board to the other (you have to read more info about that, sorry I haven't yet...) and upload the bootloader to the µServotino from the Arduino IDE. Not sure if you can use the Arduino ISP from AVR Studio, but you can try. Let me know if it works!

I use an Arduino Nano as my Arduino ISP programmer. It works great but you need to use avrdude from AVRstudio4 and even then it usually fails the very first attempt. After that it works fine.

There is a shield to transform your regular Arduino board (not the Uno!) into a AVR ISP (hardware) programmer:

http://evilmadscience.com/productsmenu/tinykitlist/253

It has a ZIF (Zero Insertion Force) socket for the target microcontroller and it can also eliminate the auto-reset on the Arduino board by a jumper. You can also get a 6 pin ribbon cable to program external devices (like the µServotino). Cool!

I have occasionally had similar problems. I use the Arduino IDE and an Arduino Nano for the programmer. Sometimes it seems like I need to upload the program twice before it sticks and on rare occasions I need to reload the boot loader. It is as though the flash memory needs a kick in the pants. After that it is usually fine.

IG, here is how I set up the fuses in a blank microcontroller and upload the Arduino bootloader:

In AVR Studio 4, I click on Connect, select my ISP programmer and Auto COM port, (while the programmer is actually connected to the µBotino board and the board is powered by a USB-serial cable - so I have both programmers connected to the board at the same time, just to avoid hooking up batteries), then a window "STK 500 in ISP mode" appears. I click on the Main tab, select the ATmega328P microcontroller, click on Read Signature to make sure I have a correct connection with the microcontroller. Then, I click on the Fuses tab and I get the following manufaturer set fuses:

EXTENDED: 0xFF
HIGH: 0xD9
LOW: 0x62

BODLEVEL is set to Brown-out detection disabled  - I don't touch this.

I change the following fuses:

BOOTSZ - from 2048 to 1024 words
BOOTRST - check
CKDIV8 - uncheck
SUT_CKSEL - Ext. crystal 8.0... (the last position on the list)

The fuses values change to this:

EXTENDED: 0xFF
HIGH: 0xDA
LOW: 0xFF

I click on the Prgram button to write the fuses, then go to the next part.

Then I click on the Program tab, look in the Flash section and browse for the ATmegaBOOT_168_atmega328_pro_8MHz.hex file and click on Program.
To finish up I click on the Lock Bits tab, click on the BLB1 and choose from the list LPM and SPM prohibited in Boot Section and the LOCKBIT fuse changes from 0xFF to 0xFF. I click on Program and the bootloader is now protected by accidental programming until you do a Erase Device from the Main tab.
After all this, I disconnect the ISP programmer, go to Arduino and using the USB-serial cable I upload the Blink scketch to verify if all went well.

I don't have an ISP Programmer. Any recommendations?

Is AVR Studio 4 your recommendation for the IDE?

IG, if you shoot me an email with a shipping address I can send you some chips with the boot loader. Let me know \0/

That is a very kind offer, which I will take you up on!

Long time ago I got a AVR ISP programmer, but I could never use it directly under Arduino IDE. I don't think you can even find it anymore. But from other people's recommendations, I would get a Pololu AVR programmer because it also has a second serial connection and a slo-scope. You can read more about it here: http://www.pololu.com/catalog/product/1300

Ah! Well that explains it. If BOD is disabled, the symptoms fit what TinHead described. I assumed (incorrectly) that you would go with the BOD settings Arduino uses as the default.

I might want to re-flash the chip with a BOD level of 4.3V. If it goes below that, something is definitely wrong, since the regulator should keep things at 5V unless the battery level drops.