Thanks heaps mate, that helped me out a lot, especially since i had some code to look at as well, I'm trying to get the reading part done too but I seem to be having a bit of problems with that as well. I attempted the following code:
long EEPROMReadlong(int deviceaddress, unsigned int address )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
//Read the 4 bytes from the eeprom memory.
long four = Wire.read(address);
long three = Wire.read(address + 1);
long two = Wire.read(address + 2);
long one = Wire.read(address + 3);
//Return the recomposed long by using bitshift.
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}
Which is pretty much just changing the eeprom.read to wire.read() but I keep getting an error saying that no matching function call to TwoWire::Read(unsinged int&). I'm assuming it has something to do with the unsigned int address but since I used that in the write I don't quite understand why it doesn't work here?
Also if I write to address 1 in the code from what I understand it writes the long over address 1, 2, 3 and 4 right? So If I wanted to store another long value, I should place it at address 5 right? and not at 2 since then it will rewrite over 2, 3, 4 and also write 5?
----------edit--
Okay so I had another go at it with the following reading code:
long EEPROMReadlong(int deviceaddress, unsigned int address )
{
long four, three, two, one;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
//Read the 4 bytes from the eeprom memory.
Wire.requestFrom(deviceaddress, address);
if (Wire.available()) four = Wire.read();
Wire.requestFrom(deviceaddress, (address + 1));
if (Wire.available()) {
three = Wire.read();
}
Wire.requestFrom(deviceaddress, (address + 2));
if (Wire.available()) {
two = Wire.read();
}
Wire.requestFrom(deviceaddress, (address + 3));
if (Wire.available()) {
one = Wire.read();
}
//Return the recomposed long by using bitshift.
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}
But unfortunately it doesn't print anything on the screen when I call
void setup()
{
Wire.begin();
Serial.begin(57600);
Serial.print("init");
delay(5000);
for (int i = 0; i < 10000; i += 4)
{
Serial.println(EEPROMReadlong(disk1, i));
delay(10);
}
}