read errors
K0rkunc opened this issue · 12 comments
only this variable gives �������D
I2C_eeprom ee(0x51, I2C_DEVICESIZE_24LC512);
if (request->argName(i) == "setname")
{
if (strcmp(cihaz_adi, request->arg(i).c_str()) != 0)
{
strcpy(cihaz_adi, request->arg(i).c_str());
pass_len1 = strlen(cihaz_adi);
ee.writeBlock(670, (uint8_t *)&cihaz_adi, sizeof(pass_len1));
ee.writeByte(350, pass_len1);
}
}
I do not understand the problem you have.
You make a statement about "only this variable gives �������D"
and provides some uncompilable code.
Please provide a minimal sized sketch that shows the problem.
Hello
I am writing eeprom a char variable in uint8_t format as in the codes below.
then I read this data at boot and it gives irrelevant values.
**I don't have this problem in other reading and writing areas, but I'm having this problem in "device_name" variable, **
please can you help me with this?
I get the device name from the esp32 async web server interface and save it.
by the way, the recording function returns a value of 4.
if (request->argName(i) == "setname")
{
if (strcmp(cihaz_adi, request->arg(i).c_str()) != 0)
{
snprintf(cihaz_adi,sizeof(cihaz_adi),"%c",request->arg(i).c_str());
pass_len1 = strlen(cihaz_adi);
ee.writeBlock(600, (uint8_t *)&cihaz_adi, 4);
ee.writeByte(350, pass_len1);
}
}
then I try to read this value at device startup.
pass_len1 = ee.readByte(350);
ee.readBlock(600, (uint8_t *)cihaz_adi, pass_len1);
but this is how the value I read comes in. �������
Please provide a minimal sized sketch that shows the problem.
Are you sure that
- there is a value written to EEPROM?
- it is the right value?
by the way, the recording function returns a value of 4.
such remark does not tell me anything if I do not have a complete minimal sketch to verify
full project codes https://www.paste.tc/code-84118
yes after transferring the values I get from the interface to the char variable
I am reading with serial print the value is correct
but unfortunately when i save and restart, bad value comes
minimal sketch
...
#include "I2C_eeprom.h"
char cihaz_adi[50]={"TwinsLED"};
I2C_eeprom ee(0x51, I2C_DEVICESIZE_24LC512);
Setup()
{
Wire.begin();
Wire.setClock(400000);
ee.begin();
strcpy(cihaz_adi, request->arg(i).c_str());
pass_len1 = strlen(cihaz_adi);
cihaz_adi[5]='\0';
ee.writeBlock(600, (uint8_t *)&cihaz_adi, 4);
ee.writeByte(350, pass_len1);
pass_len1 = ee.readByte(350);
ee.readBlock(600, (uint8_t *)cihaz_adi, pass_len1);
}
Not tested code, no time today to elaborate on this, but should get you started how to store a text in EEPROM
// FILE: I2C_eeprom_store_text.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library
// uses a 24LC256 (32KB) EEPROM
// might need adaptions for other EEPROMS (page size etc)
#include "Wire.h"
#include "I2C_eeprom.h"
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for Serial port to connect.
Serial.println(__FILE__);
ee.begin();
if (! ee.isConnected())
{
Serial.println("ERROR: Can't find eeprom\nstopped...");
while (1);
}
Serial.print("I2C_EEPROM_VERSION: ");
Serial.print(I2C_EEPROM_VERSION);
Serial.println("\n");
Serial.println("\nwrite string");
ee.setBlock(600, 0, 128);
dumpEEPROM(600, 128);
char data[] = "hello world";
ee.writeBlock(600, (uint8_t*) data, strlen(data) + 1); // add the \0 char to be sure <<<<<<<<<<<<<<<
dumpEEPROM(600, 128);
Serial.println("\nread string");
char dataRead[100];
memset(dataRead, 0, 100);
ee.readBlock(600, (uint8_t*)dataRead, 12);
Serial.println(dataRead);
Serial.println("\tDone...");
}
void loop()
{
}
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
{
const int BLOCK_TO_LENGTH = 10;
Serial.print("\t ");
for (int x = 0; x < 10; x++)
{
if (x != 0) Serial.print(" ");
Serial.print(x);
}
Serial.println();
// block to defined length
memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
length = (length + BLOCK_TO_LENGTH - 1) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
byte b = ee.readByte(memoryAddress);
for (unsigned int i = 0; i < length; i++)
{
char buf[6];
if (memoryAddress % BLOCK_TO_LENGTH == 0)
{
if (i != 0) Serial.println();
sprintf(buf, "%05d", memoryAddress);
Serial.print(buf);
Serial.print(":\t");
}
sprintf(buf, "%03d", b);
Serial.print(buf);
b = ee.readByte(++memoryAddress);
Serial.print(" ");
}
Serial.println();
}
// END OF FILE
#include "I2C_eeprom.h"
char cihaz_adi[50]={"TwinsLED"};
I2C_eeprom ee(0x51, I2C_DEVICESIZE_24LC512);
Setup()
{
Wire.begin();
Wire.setClock(400000);
ee.begin();strcpy(cihaz_adi, request->arg(i).c_str());
pass_len1 = strlen(cihaz_adi);
cihaz_adi[5]='\0';
ee.writeBlock(600, (uint8_t *)&cihaz_adi, 4);
ee.writeByte(350, pass_len1);pass_len1 = ee.readByte(350);
ee.readBlock(600, (uint8_t *)cihaz_adi, pass_len1);}
Does not compile
Why
Why
It does not compile because the code you posted is an incomplete half sketch.
Please provide a minimal sketch that shows the problem.
(or if it is solved you may close the issue)
As there is no answer I assume the problem is solved, therefor I close the issue. If the issue still exists you can reopen the issue, or better ask on https://forum.arduino.cc/ for help on your sketch as your problem does not appear to be a library problem.