Hello everyone,
I hope everyone is well. I am currently working with arduino due while going through its specifications I got to know that it doesn't have internal eeprom as other arduino boards. So, I planning to use sd card to store my six variables via microsd card adapter. I have used SD.h library successfully I can store the data in it. But, I want to read the last stored value.
Although Due does not have EEPROM, but this is not a problem. On the Due, EEPROM is emulated by storing non-volatile data to flash:
yes, I tried dueflashstorage example but I cannot store value more than 255.
yes, because 255 is maximum value for a byte
The controller operates only with bytes, all other data types - int, long, float... structure... can be represented as a sequence of bytes. All these types are written in Due as arrays of bytes.
See details in the DueFlashStorageStructExample.ino example
yes, after using struct I can store values but after switching off arduino that variables I stored becomes zero. is this normal? for this reason I chose sd card.
No, it is wrong
What about the storing of one byte values in the dueflashstorage example you mentioned in post#3 ? It also becomes zero after reset or still contain stored values?
yes, it is working fine I can get the stored values
so in the case of structures the problem in your code. Please show the complete sketch how you try to write and read structures to the flash..
This the example I am using for structure and the same thing I tried with dueflashstruct
// FILE: I2C_eeprom_struct.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library store /retrieve struct
//
// uses a 24LC256 (32KB) EEPROM
// as this test writes a lot it might wear out EEPROMs eventually.
//
#include "Wire.h"
#include "I2C_eeprom.h"
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
uint32_t start, duration;
struct
{
float temperature;
float humidity;
float pressure;
} measurement;
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for Serial to connect.
Serial.println(__FILE__);
Serial.print("VERSION: ");
Serial.println(I2C_EEPROM_VERSION);
Serial.println();
ee.begin();
if (! ee.isConnected())
{
Serial.println("ERROR: Can't find eeprom (stopped)...");
// while (1);
}
Serial.print("size: \t");
Serial.println(sizeof(measurement));
// clear EEPROM part
ee.setBlock(0, 0, sizeof(measurement));
// make measurement here
measurement.temperature = 22.5;
measurement.humidity = 53.1;
measurement.pressure = 1000.9;
// store it in EEPROM
start = micros();
ee.writeBlock(0, (uint8_t *) &measurement, sizeof(measurement));
duration = micros() - start;
Serial.print("write: \t");
Serial.println(duration);
delay(10);
// clear measurement struct
measurement.temperature = 55.23;
measurement.humidity = 30.23;
measurement.pressure = 253.1;
// retrieve old measurement
start = micros();
ee.readBlock(0, (uint8_t *) &measurement, sizeof(measurement));
duration = micros() - start;
Serial.print("read: \t");
Serial.println(duration);
delay(10);
Serial.print("temp:\t");
Serial.println(measurement.temperature);
Serial.print("hum:\t");
Serial.println(measurement.humidity);
Serial.print("pres:\t");
Serial.println(measurement.pressure);
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE
After upload this code the value for the temperature,humidity,pressure is stored right? but when I am using the following code to read the variable it shows as zero.
#include "Wire.h"
#include "I2C_eeprom.h"
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
uint32_t start, duration;
struct
{
float temperature;
float humidity;
float pressure;
} measurement;
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for Serial to connect.
Serial.println(__FILE__);
Serial.print("VERSION: ");
Serial.println(I2C_EEPROM_VERSION);
Serial.println();
ee.begin();
if (! ee.isConnected())
{
Serial.println("ERROR: Can't find eeprom (stopped)...");
// while (1);
}
Serial.print("size: \t");
Serial.println(sizeof(measurement));
// retrieve old measurement
start = micros();
ee.readBlock(0, (uint8_t *) &measurement, sizeof(measurement));
duration = micros() - start;
Serial.print("read: \t");
Serial.println(duration);
delay(10);
Serial.print("temp:\t");
Serial.println(measurement.temperature);
Serial.print("hum:\t");
Serial.println(measurement.humidity);
Serial.print("pres:\t");
Serial.println(measurement.pressure);
Serial.println("\ndone...");
}
void loop()
{
}
Sorry, but we discussed about the using of DueFlashStorage library. Why do you show me these sketches?
Please show the code how you try to use the DueFlashStorage
Addition:
The tests of storing and reading data to/from the flash MUST be done in the same code, because the flash is erased when you upload the new firmware.
this one struct example for the 24lc512 eeprom chip. I think I dont want to use storage of arduino due because of some reasons like when the storage is filled we cant erase it like in eeprom.
so the problem is solved?
No,can you show me a way either using 24lc512 chip or from sd card.
Do you have any problem with code from your post #9 ? Please describe it
yes, I can store the variable when I am reading from it the variables are becoming zero.
as i see the code in the post #9 is the unchanged example from the I2C_eeprom library?
If so - it can be hardware/connectivity problems. Are you sure that your EEPROM chip is operational and has the address 0x50 ? Show your connections
yes, I have verified it with i2c addres scanner.
it gives address 0x50
Did you try store and read one byte to your EEPROM ?
yes, for values upto 255 I works fine.
Can you provide more info about your EEPROM - full model/label, link to the seller, clear foto of the chip?