Uno EEPROM Get Returns -59536

I develop my application with a Nano then put it on a ATMEGA chip via a ELEGOO UNO R3 Board as a programmer setup. Then this chip I put into hardware instead of the Nano which i develop the hardware with. Everything works fine with the Nano (On computer with USB and on hardware), that is uploading a sketch to first write the eeprom using PUT and then check it with the GET. Then loading another program onto the NANO that uses the eeprom value. Life is good...

Then, having it working on the Nano, tried to do the the same on the chip on the Elegoo R3. The chip always returns -59536. Quite sure I have the UI settings right, board,etc. The main program works fine when uploaded...just seems the Elegoo . atmel chip combo does not work for writing the EEPROM, yet the other main program uploads fine and works. with no PUT and GET.

In summary Elegoo R3 will not read or write EEPROM using PUT and GET. Another non EEPROM program works fine, and shows the -59536 where it should show 6000 first written with the PUT.

IT all works fine on the Nano...A hardware issue on the Uno, but what and how to solve?

Any suggestions? Thank you

From UI:
Tools / Board:"Arduino Uno"
Programmer:AVRISP mkII (tried different ones, no good)

chip atmel 35473D, atmega328P U, 21135PG (tried 2 different chips)

from ELEGOO Get Board Info from UI..

BN: Arduino Uno
VID: 2341
PID: 0043
SN: 7593231303935171F151

To write value (works fine on nano but not on uno)
#include <EEPROM.h>
void setup() {
// put your setup code here, to run once:
//delay(1000);
EEPROM.put(0, 6000);
}
void loop() {
// put your main code here, to run repeatedly:
}

to check it...(works fine on nano but not on uno)

#include <EEPROM.h>
void setup() {
Serial.begin (9600);
// put your setup code here, to run once:
long LongVar;
EEPROM.get(0, LongVar);
Serial.println(LongVar);
}
void loop() {
// put your main code here, to run repeatedly:
}

output..
16:33:01.856 -> -59536 (should be 6000)

Oddly enough the examples all here work...

saw this in the examples...

while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
//}
just adding that, it was still unhappy on a different chip...

initialize the chip with this, clear the eeprom...

#include <EEPROM.h>

void setup() {
// initialize the LED pin as an output.
pinMode(13, OUTPUT);

for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}

// turn the LED on when we're done
digitalWrite(13, HIGH);
}

void loop() {
/** Empty loop. **/
}

Now it works as expected.....

For some reason the EEPROM had to be written to to initialize it... any idea why?

Anyhow, now it works

EEPROM.put() and get() write and read from the EEPROM based on the size of the variable being used.

So...

int x = 10;
EEPROM.put(0, x);   // Will store 2 bytes, because an int is 2 bytes long

In your case you are using a literal value "6000", so the Arduino will assume a 2 byte int value by default.

But when you read back using get(), you use a long variable... 4 bytes... so it's gunna read passed where you stored the value.

If you use...

long x = 6000;
EEPROM.put(0, x);   

It should work as expected.

Hi @aethermedium

or "EEPROM.put(0, 6000L);" may be work too.....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.