Arduino NG loosing code from memory

I have two Arduino NG that seem to be loosing the code stored on them, either after a period of time or when the machine is turned off, I can't be sure. I'm also wondering if it has anything to do with over heating.

So I have code compiled and loaded that turns leds on/off when you send it a serial message. Then after a day or two of use it just stops working. I use the Arduino terminal to send it the start led message, and nothing happens. If I upload the code again it works fine.

If you have any ideas what might be causing this I'd be grateful to hear them,

I had some strange poblems after I defined a huge array. Maybe your code is filling up memory after a few days? You don't have a lot of space for you variables, only 1kbytes. If I am not mistaken 128 are already in use for the serial buffer.

No, unfortunately its not that. Hmm.

Turning off the Arduino and unplugging it from the computer doesn't help? You need to upload the code again?

Turning off the Arduino and unplugging it from the computer doesn't help? You need to upload the code again?

Yes exactly.

Can you post your code?

when you send character A, it starts fading the led up and down, when you send it B it stops.

// led values
int ledpin = 9;
int ledval = 0;
int ledtarget = 0;
int ledon = 0;
int incomingByte;

void setup() {
  beginSerial(9600); 
  
  pinMode(ledpin, OUTPUT);
  
}

void ledLoop(){
  
    if(ledval < ledtarget){
      ledval = ledval + 40;
    }else if(ledval > ledtarget){
      ledval = ledval - 40;
    }
  
    if(ledval > 254){
      ledval = 255;
      ledtarget = 0;
    }else if(ledval < 1){
      ledval = 0;
      if(ledon){ ledtarget = 255; }
    }

      analogWrite(ledpin,ledval); 
  
  
}


void loop(){
  
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  
  }
  
  switch (incomingByte){
    case 97: // a
      ledon = 1;
      break;
    case 98: // b
      ledon = 0;
      break;
    }
  
  ledLoop();
  
  delay(100);

}

Hmm, any ideas anyone? I'm completely baffled.

did you get my email?

massimo

No I didn't Massimo, thats strange.

Last night I uploaded the PWM example program (LED fade) to my new arduino board (Mega8) and it worked okay. After a while I tuned it off. I turned it back on again and it did not came back on. I connected led to pin 13 and told me that the boot loader was cycling again and again. :o

Maybe it has to do with the PWM as OP's application also involved PWM! strange :exclamation

I'll check if the program is there in the chip by using a parallel programmer.

/me

Connected the board to the parallel port flash programmer and dumped the flash contents. Figured out that the application flash was corrupted :o

Following was downloaded from the corrupted code:

S0080000666C617368E9
S1130000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC
S1130010FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC
S1130020FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC
S1130030FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC
S1130040FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC
S1130050FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAC
S1130060FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C
S1130070FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8C
S11300800E750E750E750E750E750E750E750E7554
S11300900E750E750E750E750E750E750E750E7544
S11300A00E750E5F0E5F0E5F0E5F0E5F00010E7524
S11300B00E750E750E750E750E750E750E750E7524
S11300C0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3C
.
.
.

Uploaded the "Fading" sketch again and it started working again.

Got the following dump:

S0080000666C617368E9
S113000038C051C050C04FC04EC04DC04CC04BC092
S11300104AC097C048C047C046C045C044C043C05A
S113002042C041C040C000000000000000000003C6
S11300300405000000000000000001020408102074
S11300404080010204081020010204081020040466
S1130050040404040404020202020202030303036C
S113006003030000363330000038353200003734E3
.
.
.

Looks like either the flash got corrupted (silicon problem) or boot loader messed it up. ;)

/me

Another experiment:

After flashing (uploading in Arduino terms) the fade sketch, it worked ok. Then after a few power on off cycles, the flash got corrupted again. Here is what I got from the dump…

S0080000666C617368E9
S1130000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC
S1130010FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC
S1130020FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC
S1130030FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC
S1130040FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC
S1130050FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAC
S1130060FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C
S1130070FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8C
S1130080FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7C
S1130090FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C
S11300A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5C
S11300B0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4C
S11300C070E080E090E079D08091620090916300CC
S11300D00396909363008093620060916200709134
S11300E063006C34710544F38BE490E00DC080919F
S11300F06000CAD06CE370E080E090E05ED0809154
S11301006200909163000397909363008093620070
.
.
.

I have used 78L05 on the Bare-Bones Aurdino board “Rev C”. 0.1 and 47uf caps on both end of 78L05. Board is being powered by a 9V battery. The xtal and Mega8 are not installed in the picture. Have omitted the diodes. In the picture the board is being powered from the 78l05 on the breadboard.
http://www.bhargavaz.net/arduino/bbarduino-06262007.jpg

hi

Do you have anything else connected? The one thing I notice is the regulator: the 78L05 you're using is only good for 100ma. This is cutting it a bit close in terms of current... The one Paul Badger specifies is in a T0-92 case but puts out more current. As it is, you're eating up almost half the current just for the Arduino and the LED, so connecting much more is going to starve the processor and lead to flakiness.

D

PS: if you use a crystal and not a resonator, you have to put 22pf capacitors from each crystal contact to ground... they make the oscillator start up.

hi

Do you have anything else connected? The one thing I notice is the regulator: the 78L05 you’re using is only good for 100ma. This is cutting it a bit close in terms of current… The one Paul Badger specifies is in a T0-92 case but puts out more current. As it is, you’re eating up almost half the current just for the Arduino and the LED, so connecting much more is going to starve the processor and lead to flakiness.

Nothing else connected, just Mega8 and LED

I measured the actual current drawn by the board and max was 41ma when the LED @ pin9 was bright.

I don’t think that the active current of mega 8 would be more than 30ma @ 16MHz. And LED would consume about 30ma max! so IMHO 100ma would be enough for it.

BTW TO-92 reg can only deliver 100ma it is the TO-220 version that delivers current up to 500ma.

I have updated the pictures here:
http://www.bhargavaz.net/arduino

PS: if you use a crystal and not a resonator, you have to put 22pf capacitors from each crystal contact to ground… they make the oscillator start up.

Good observation :-). Look at the picture here: http://www.bhargavaz.net/arduino/Arduino-Caps.jpg
You will find two 22pf 0602 caps at the back. :sunglasses:

hey

well then I'm not sure what the problem could be! Could the crystal case be shorting to the pads it's soldered to?

D

PS The regulator PB specifies for the Barebones actually does put out 300ma in a little tiny T0-92 case.. it's an L4931 by ST Microelectronics.

hey PS The regulator PB specifies for the Barebones actually does put out 300ma in a little tiny T0-92 case.. it's an L4931 by ST Microelectronics.

I doubt that arduino board would draw 300ma just by itself! Only active device on my board is ATMega8 and the ATMEGA8 datasheet specifies 3.6ma active current @ 4MHz and I doubt that it will rise to 300 ma @ 16MHz ;)

Paul uses regulator L4931CZ50 and according to ST datasheet (below) the maximum current delivered out is 250ma. But that doesn't mean that Arduino baord draws 300ma all the time ;D

Look at page number 23 of the data sheet. http://www.st.com/stonline/products/literature/ds/4340/l4931abxx15.pdf

Regards,

/me

ok!

Unrelated to cbhargavas problem.

It seems like we might be drawing too much power from the Arduino, reseting the memory.

We had 1.5ohms resistors, but then we changed the LEDs but not the electronics (because they are encased). Now we are using 50mA ultrabright LEDs: http://www.maplin.co.uk/module.aspx?ITAG=SPEC&ModuleNo=45937&doy=29m6#spec

Massimo mentioned that each pin can deliver 20ma, and that we should use a capacitor. Can you recommend which capacitor to use and the best way to wire it up.

Arduino 1 is running 1 led, Arduino 2 is running 3 leds (one at a time), an ultrasound and an IR ranger.

Thanks

hello

i've mentioned a transistor... a capacitor will help but only very minimally

if you draw 50ma from a pin that is desiged to provide 20ma that's more than 100% overload

even a simple bc547 would do the trick or use mosfet to save some time (one less resistor to solder)

1.5 ohm seems quite small the datasheet says 50ma at 2.3v typical , this means the resistor will have to drop 2.7v while 50ma are going through it 2.7/0.050 = 54 , nearest resistor 56 ohm

masssimo