EEPROM in a library

Naively I have tried to use EEPROM in a library I'm writing.

EEPROM.read always returns 0, even though I can read the same memory address from setup and echo out the real, non zero, value.

Apart from including #include <EEPROM.h> into the library file, what else is required ?

(I'm using an Uno R4 Minima )

Please show a sketch that demonstrates the issue. To my knowledge the Uno R4 series does not have EEPROM.

Tutorial on using the EEPROM: https://docs.arduino.cc/tutorials/uno-r4-minima/eeprom/

I'll post a simplified sketch in a minute. In the meantime there is 8kB of Flash emulated EEPROM on the RA4M1 chip used as the mcu.

Description
The Arduino® UNO R4 Minima is the first UNO board to feature a 32-bit microcontroller. It features a RA4M1 series microcontroller from Renesas (R7FA4M1AB3CFM#AA0), which embeds a 48 MHz Arm® Cortex®-M4 microprocessor. The UNO R4 Minima's memory is larger than its predecessors, with 256 kB flash, 32 kB SRAM and 8 kB data memory (EEPROM).

Yes that works. I am writing a separate library to control a CAN bus. I have written some values to the EEPROM and can read them back via the Setup function.
However if I read the same address space in my library it is zero.

I will post a simplified example ... soon.

Then there are errors in your code. For help, please read and follow the instructions in the "How to get the best out of this forum" post.

Here is the sample I have prepared. Please help me isolate the errors in my code.
EEPROM_test.zip (1.3 KB)

I've just uploaded a simple example.

I think I have found the issue ....

my declaration of the class instance should be

VelbusNode* node;

and then I need to create the instance

 node = new VelbusNode();

outputs

16:19:44.764 -> initialising EEPROM
16:19:44.764 -> reset local var, should be 0
16:19:44.764 -> 0
16:19:44.764 -> Read from EEPROM, should be 1
16:19:44.764 -> 1
16:19:44.764 -> Read from node, should be 1, not 0xFF
16:19:44.764 -> 1
16:19:44.764 -> write other node member value, should be 0x10
16:19:44.764 -> 16

You don't learn if you don't make mistakes !

I've figured it out now. I did not realise I was on SO.
Apparently some on this forum have forgotten the original ethos of Arduino.
https://www.google.com/search?channel=fs&client=ubuntu&q=arduino+purpose

What in the current discussion force you to think that?

Glad you found the errors!

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