I want to add an external EEPROM to store some simple values between 0 and 255. I'm using an AT24C256 external EEPROM board. So for example, I want to specify memory space 1, and store, say 217. Memory space 2, store the number 45. I found the following sketch, and I'm getting errors, which I can see why, but not sure how to correct them. It's saying "writeI2CByte was not declared in this scope." I'm not sure how to declare it.
As a side note, I added MODE and the subsequent if statement for it. This is just for testing purposes so it's not constantly writing to the EEPROM.
I'm sure there's other errors, and I might also be whizzing up the wrong tree in the first place altogether.
So, this is a sketch that you have not created. Why not you try to create your own sketch from the following tips to write/read data byte 0x23 into/from location 0x1234?
1. Build connection diagram between UNo and EEPROM as per Fig-1 given below.
Figure-1:
2. Upload the following sketch in UNO.
#include<Wire.h>
byte myData = 0x23; //data byte to be stored at location 0x1234 of EEPROM
int eepromAddress = 0x1234; //EEPROM location that will hold data byte 0x23
void setup()
{
Serial.begin(9600);
Wire.begin();
//--- wrieitng 0x23 at location address 0x1234
Wire.beginTransmission(0x50); //EEPROM's i2C address
Wire.write(highByte(eepromAddress)); //pointing beginning address of EEPROM
Wire.write(lowByte(eepromAddress));
Wire.write(myData);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("EEPROM is not found...!");
while (1); //wait for ever
}
Serial.println("EEPROM is found.");
delay(5); //write cycle delay
//---reading back the data--------------
Wire.beginTransmission(0x50);
Wire.write(highByte(eepromAddress)); //pointing target location address of EEPROM
Wire.write(lowByte(eepromAddress));
Wire.endTransmission();
//--------------------------------------------
byte n = Wire.requestFrom(0x50, 1); //reading 1 bytes data from location 0x1234
byte recData = Wire.read();
Serial.print(recData, HEX); //Serial Monitor should show: 23
}
void loop()
{
}
After looking into things further, I found info to put me on the right track. Being new to all of this, I didn't catch that I needed to define the operation in the setup and not the loop. But I'm now able to write and read to the EEPROM.