* Project: Minor_Project_I2C_24LC08_eeprom
* Author: Lewis Loflin:
for the original software & other details go to
http://www.sullivan-county.com/ele/arduino_24lc08.htm
* Date: Tuesday 23/02/2010 (Lewis's post)
* Modified: Jane-Maree Howard
* Comments: Jane-Maree is using this as a Minor Project,
with the following differences:
* The Arduino Duemilanove is based on the ATmega328 microcontroller.
* The Fritzing diagram of the circuitry employing this software shows
two 24LC08 serial EEPROM chips in tandem on the same 2-wire interface.
* The software does not use all of the 2048 bytes available,
but it could be modified to do this e.g. to write the word "Arduino"
repeatedly until it fills the available EEPROM space.
* The word "Arduino" has seven characters; by counting the characters,
of your stored message/data, you can arrive at the number of bytes
the external EEPROM will send on request, since 1 byte stores 1 character.
You could retrieve all or part of the stored message/data as desired.
Note the modification to the original.
* Platform: Arduino 18
* Purpose: 24LC08 Demo with the ATMEGA128
This is an 8-pin DIP serial EEPROM.
It will store 1024 bytes. (0x3FF)
It uses I2C or "two wire" interface.
* Operation: On power up or reset the "setup" is executed once,
setting up the hardware and writing the text message "Arduino" to the EEPROM.
Then the "loop" section will run over and over.
Whenever sw0 is pressed the text message "Arduino" is read from the EEPROM
and sent via the serial port to a computer running for example Hyper Terminal.
This demonstrates the use of the Wire.h library,
serial ports, and an external switch tied to an input.
Pin designations for the 24LC08:
Pins 1, 2, 3:
if tied to VCC (5 volts) address = 0x54;
if tied to VSS 0x50.
Only two can be used in a single circuit.
Pin 4 VSS or ground.
Pin 5 SDA or serial data. Tied to Arduino analog pin 4.
Pin 6 SCL or serial clock. Tied to Arduino analog pin 5.
Pin 7 WP or write protect. VCC disables write, VSS enables write.
Pin 8 VCC or +5 volts.
*/
#include
byte sw0 = 12; // digital pin for switch connected to ground.
int position_pointer = 0x3f0; // address in 24LC08. Values from 000 hex to 3FF hex.
void setup()
{
pinMode(sw0, INPUT);
digitalWrite(sw0, HIGH); // turn on internal pull up
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // setup serial for output
// send test message "Arduino"
Wire.beginTransmission(0x50); // connect to 24LC08 device address
Wire.send(position_pointer); // beginning address within EEPROM (0x3f0)
Wire.send("me");
//Wire.send("Arduino");
Wire.endTransmission();
}//end setup()
void loop()
{
//digitalWrite(sw0, HIGH); // turn on internal pull up
while (digitalRead(sw0) == 1)
{} // wait here until switch is pushed.
Wire.beginTransmission(0x50); // link to 24LC08
Wire.send(position_pointer); // must act as a position pointer
Wire.endTransmission();
Wire.requestFrom(0x50, 5); // request 7 bytes from slave device 24LC08
// below will loop until 5 bytes are received.
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.receive(); // receive a byte as character
Serial.print(c); // print the character
}//while()
Serial.print("\n"); // next line
delay(2000); // wait one second.
}//end loop()
//*****************************************************SEE VERY IMPORTANT COMMENT BELOW