|
Using the ATMEGA168/Arduino with a 24LC08 Serial EEPROMby Lewis Loflin Explanation of program: On power up or reset the "setup" is executed once, setting up the hardware and writing the text message "Adrunio" 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. For the basic structure of an Arduino program see page 7 of Arduino Programming Notebook by Brian Evans For information on setting up switches and pull ups on the Arduino see pages 4-6 on Arduino Projects by Tod Kurt
24LC08 Demo with the ATMEGA128 Pin designations for the 24LC08:
#include Wire.h> // specify use of Wire.h library. byte sw0 = 12; // digital pin for switch connected to ground. // address in 24LC08. values from 000 hex to 3FF hex. int position_pointer = 0x3f0; 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 Wire.send("Arduino"); Wire.endTransmission(); } void loop() { 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, 7); // request 7 bytes from slave device 24LC08 // below will loop until 7 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 } Serial.print("\n"); // next line delay(1000); // wait one second. } You Tube Arduino Microcontroller Video Series March 2012:
Arduino demos:
» About me » Bristol VA/TN » E-Mail » Hobby Electronics » Arduino Microcontroller
General Electronics
Added January 2012: PICAXE Micro-controller Projects!The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.
|