Hello everybody, i have played around with the Arduino a little but there is one thing that has bothered me a lot. I can't seem to find a good I2C eeprom demo. I have tried so many and it never works. I have successfully interfaced eeproms with other micros, but never with the Arduino. Is there a good demo that actually works? I hope this is the right forum to post in for help...... Thanks in advance. ;D
Have you looked at the examples here: Arduino Playground - InterfacingWithHardware
Andrew
I tried that and it had a compile error. I tried copying and pasting it several times to no avail. Maybe i am doing it wrong....
Yeah, i have tried most every demo and it just doesn't seem to work. Having the ability to communicate with external memory is very important and it is very frustrating that it is not working.
Anybody?
Yeah, i have tried most every demo and it just doesn't seem to work.
That's not very informational. Do they compile? If so what results do you get? Really you should post your code so we can see what you are trying. I've used the built in Arduino EEPROM functions and they worked fine for me: http://arduino.cc/en/Reference/EEPROM
Lefty
I've never used an external EEPROM specifically, but I have used a DS1307 RTC. It has some memory space on it that I have been able to access (read and write). The DS1307 speaks I2C.
Ah, finally some help. ALL of the demos i tried did NOT compile, but i will try the one you said.
Oh, Sorry i meant to say that i am using an external EEPROM. A 24lcxxxx series chip. I am sure that getting the inboard memory to work is probably easier. But i need a lot more storage space. I need something, An i2c eeprom or perhaps a uSD card(if the Arduino can handle it).
Couldn't you just start up a write session, and then use wire.send() to send your data? Or would that be too easy
Well maybe a part of my sketch will help you get started. It's just a support sketch to load data for my 5x5x5 led cube:
// This preloads a LED cube pattern into a external I2C EEPROM chip type 24LC256
// write pattern data to external I2C eeprom memory (device address 0x50)
// added saving pattern length in first two bytes.
// pattern = internal diagnal
#include <Wire.h>
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
delay(5);
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
const int I2Caddress = 0x50;
unsigned int address = 2;
byte datalow = 0;
byte datahigh = 0;
void setup() {
Wire.begin();
Serial.begin(57600);
Serial.println ("Hit a key to start"); // signal initalization done
while(Serial.available() == 0){} // wait for user
Serial.println ("Writing to EEPROM starting at address = 2"); // signal initalization done
// step 1
// Row 1 bottom
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamp 25 = 0x01
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 24-17
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 16-9
i2c_eeprom_write_byte(I2Caddress, address++, 0x01); // lamps 8-1
// Row 2
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 3
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 4
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 5 Top
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
//Serial.println (address);
Serial.print ("."); // send row data complete mark
// step 2
// Row 1 bottom
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamp 25 = 0x01
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 24-17
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 16-9
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 8-1
// Row 2
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x40);
// Row 3
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 4
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 5 Top
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
Serial.print (".");
//Serial.println (address);
// step 3
// Row 1 bottom
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamp 25 = 0x01
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 24-17
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 16-9
i2c_eeprom_write_byte(I2Caddress, address++, 0x00); // lamps 8-1
// Row 2
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 3
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x10);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 4
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
// Row 5 Top
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
i2c_eeprom_write_byte(I2Caddress, address++, 0x00);
@graymalkin....Uh, i have pretty much tried everything, Why can't somebody just make a simple test program....Nothing fancy, just something that works.
@retolefty.... I am still kinda new to Arduino and that program looks pretty intense. Thank you for the thought....
I don't know what i am doing wrong.
Uh, i have pretty much tried everything, Why can't somebody just make a simple test program....Nothing fancy, just something that works. I don't know what i am doing wrong.
Yet you have not posted any of your coding attempts here yet, so how can we tell what you have tried, let alone what might be wrong?
Generally people get the best help showing us their attempts with any error codes they get and people then give hints or suggestions.
Also keep in mind when dealing with I2C devices (such as the 24LC256 eeprom) that bad wiring can be a problem also, so posting your schematic drawing is sometimes needed also.
Lefty
I can't find some of the ones that i used, but i did try the ones in the examples section of the Arduino IDE. They were called master-reader/ master-writer.... Can you recommend a easy one?
I take it you tried to compile this code which failed, I think I know the reason for this...
#include <Wire.h>
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddresspage >> 8)); // MSB
Wire.send((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.receive();
}
Ah the sweet sound of forum face-palm slaps drifts across the air as one realises you never read the code to see that it was a set of methods to connect to an EEPROM, but just assumed it would work
Add a damn setup and loop you twit. :@
I don't think calling a newbie a "twit" is a particularly good way to start off, but i can overlook it. As previously stated, i am not very good with the arduino. I am still learning the basics(Blinking leds, learning the new language..ect) Could you please explain yourself a little more?
Well a newbie should crawl before walking, did you even look at any of the tutorials in general? I suggest you look at the structure of the arduino program, each program needs a setup and loop method. Look up the blink tutorial and build from there. I feel entitled to call someone who bought a EEPROM before doing blink a twit.
I have blinked several LED's(including a tri color LED) and have interfaced the Arduino to a serial LCD all without a single problem. I didn't BUY a EEPROM just for the ARDUINO... I have used it before on a Propeller and a Picaxe. I2C on the Arduino appears to be a lot more complicated than on any other one so far.....I can take constructive criticism, but calling me a "Twit" is only going to tick me off. You are just plain rude AND your sarcasm/ blatant bashing isn't going to solve anything.... People are so much nicer on the Parallax forum... I have read over the tutorials several times and sometimes, you gotta run before you can walk.
Right, not wanting to start a flame war then, it would be easy done, I shall point out that he four functions there are for reading and writing data to an EEPROM but don't do anything on their own.
Add
void setup(){
// Startup code to run once
}
void loop(){
// Code to use the EEPROM and other things you want to do again and again
}
Future referance, all arduino programs need a loop and a setup method, because Main is hidden from us, we get the ties onto the important parts of the program start like that.
Hey, Greymalkin I think we got off on the wrong foot. After thinking it over a little i will do as you instructed. I will learn more about the Arduino and the C++ structure., before moving on to more complicated interfacing. Apparently, the Arduino is a good/ fast micro controller and i want to learn how to use it(And learn to program in C++) While i still don't endorse name calling, i will apologize for my brashness. I tend to get ahead of myself only to realize i am not ready for the harder stuff....Forgive and forget(On both of our parts).... What do you say?