hi
I dont speak english very well, but i hope that i'll explain my problem understandable.
i want to write some words in eeprom but my idea doasn't work.
At beginning i tried write one letter
My code:
...
void eprom(){
EEPROM.write(10, 0);
delay(5);
int slowo;
slowo = EEPROM.read(0);
Serial.print(slowo);
...
But it doasnt metter wich nuber i write serial port monitor (i'm not sure this name in english) always shows 105 or letter "i" when slowo was a char.
than I wanted write all word and here is my code:
void eprom(){
EEPROM.write(109, 10);//mleko
delay(5);
EEPROM.write(108, 11);
delay(5);
EEPROM.write(101, 12);
delay(5);
EEPROM.write(107, 13);
delay(5);
EEPROM.write(111, 14);
delay(5);
char slowo3[16];
for (int i=10; i<15; i++){
slowo3*=(int)EEPROM.read(10+i);*
_ }*/_
int slowo;*
slowo = EEPROM.read(0);*
Serial.print(slowo3);* } and in this case serial port monitor shows just a trash Do you have any idea what am I doing bad ?
} and i wanted to see on serial port monitor words: maka cukier mleko greta ------------ in this order,but i see: maka mleko cukier hcukier hmleko cukier hgreta ----------- Do you have any idea ?
[tip : spent some time on the tutorials about usiong arrays]
It is difficult to write character arrays of unequal length to eeprom. See code below (not tested). If you make a reservation in the eeprom for each string e.g. you use 12 bytes for each name it is far easier to extract the names from eeprom as you can calculate the start address.
(code not tested)
#include <EEPROM.h>
void setup()
{
Serial.begin(9600);
int addr = put_in_eeprom(0, "maka");
addr = put_in_eeprom(addr, "cukier");
addr = put_in_eeprom(addr, "mleko");
// etc
char buf[24]; // big enough I hope
addr = get_from_eeprom(0, buf);
Serial.println(buf);
addr = get_from_eeprom(addr, buf);
Serial.println(buf);
}
void loop()
{
}
void put_in_eeprom(int addr, char *p)
{
int i = 0;
while (p[i] != '\0');
{
EEPROM.write(addr+i, p[i]);
delay(5);
i++;
}
EEPROM.write(addr+i, p[i]);
delay(5);
return addr + i + 1; // next free place
}
int get_from_eeprom(int addr, char *p)
{
int i = 0;
char c = EEPROM.read(addr);
while (c != '\0');
{
p[i++] = c;
c = EEPROM.read(addr);
}
p[i] = '\0';
return addr + i + 1;
}
// there might be an off by one error in this code