i2c import / export from 24c01

:relaxed: hello…i starting on i2c interface with arduino…

something i 'not understood in red below :

about this code:

#include <Wire.h>

void eeprom_i2c_write(byte address, byte from_addr, byte data) {
Wire.beginTransmission(address);
Wire.send(from_addr);
Wire.send(data);
Wire.endTransmission();
}

byte eeprom_i2c_read(int address, int from_addr) {
Wire.beginTransmission(address);
Wire.send(from_addr);
Wire.endTransmission();

Wire.requestFrom(address, 1);
if(Wire.available())
return Wire.receive();
else
return 0xFF;
}

void setup() {
Wire.begin();
Serial.begin(19200);

for(int i = 0; i < 10; i++) {
eeprom_i2c_write(B1010100, i, ‘f’+i);
delay(100);
}

Serial.println(“Writen to memory!”);
}

void loop() {
for(int i = 0; i < 10; i++) {
byte r = eeprom_i2c_read(B1010100, i);
Serial.print(i);
Serial.print(" - “);
Serial.print(r);
Serial.print(”\n");
delay(1000);
}
}

what is the ‘f’ from " eeprom_i2c_write(B1010100, i, ‘f’+i) " ? where it came from ?
cause we use “r” in serial .print (r), not “f” …
some can explain it ?

many thanks to all :grin:

'f' + i

is simply the ASCII characters 'f' ('f' + 0), 'g', 'h' ... 'o' ('f' + 9)

:blush: understood ! but what is the value B1010100 ? and why after reading from my memory, it send me from Serial.print(r) thoses numbers like 102,103,104,105 instead of the ascii value of f+i ?

:.(i gona do again the test to be shure wath i wrote here....i gone see tonight, but if you can tell....)

best..

but what is the value B1010100

0x54.

:astonished: yeah ! what it is ? code for write or read in memory ?

void eeprom_i2c_write(byte address, byte from_addr, byte data)

Device address, memory address, data.

XD ok…many thanks to u AWOL…
it’s became clearly now…
i gona read again my notes…
:zipper_mouth_face:

XD great ! ok... it's working..this is the real ascii code and the device is well called.. :astonished: thanks very much...

where it came from ?

You should read the device datasheet against the code, then you will know why the code is coded that particular way.