24LC256 EEPROM on Arduino

November 8, 2011

About: I picked up a few 24LC256 eeproms to get some more external memory for future projects. These eeproms hold around 32Kbytes which is more than enough for a basic data-logger or for storing specific values. You can hook up to 4 of these chips together to get a whopping total of 128Kbytes of external memory. These chips are great not only for the memory but also because they are I2C. Don’t let this scare you, there are many libraries for I2C eeprom chips. I2C is also great because it only uses 2 analog pins of your arduino. The I2C pins on the arduino are analog pin 4 and analog pin 5. For this tutorial I followed Hkhijhe example and his functions.

Objective: To connect a I2C eeprom to the Arduino Uno.

Instructions: For the breadboard schematic below for how to connect the 24LC256 to the Arduino.

24LC256 Connections
Pin Connection
1 GND
2 GND
3 GND
4 GND
5 Analog Pin 4
6 Analog Pin 5
7 GND
8 5V

Arduino Code: The following code will write a string to the eeprom and keep repeating it every 2 seconds to the serial port. Hold your mouse over the source code to copy it.

#include <Wire.h> //Include the Arduino I2C Library</pre>
<p style="text-align: left;">
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();
}

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;
}

void setup() {
char somedata[] = "dayzlab.wordpress.com"; //Data
Wire.begin(); //Start I2C connections
Serial.begin(9600);
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM

delay(10); //add a small delay

Serial.println("Memory written");
}

void loop() {
int addr=0; //EEPROM Address 0
byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

while (b!=0) {
Serial.print((char)b); //print content to serial port
addr++; //increase address
b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
}

Serial.println(" ");
delay(2000);
}</p>
<p style="text-align: left;">

Basic Standalone Arduino

October 18, 2011

About: When you are done with your arduino projects and are ready to make them more permanent you have to take your arduino off its programmer and built it on a breadboard or PCB. This makes the circuit more final and permanent. It is very simple to build the standalone arduino and it shouldn’t be intimidating at all. You just need a few basic parts that you might already have laying around. This tutorial will not include a serial connector so you will have to continue to burn new code to the arduino on the programmer and transfer the chip to your breadboard or PCB. You should always use a dip socket so you don’t solder your arduino to the PCB allowing you easy access to swap programs or chips.

Objective: To build a basic bone-dry standalone arduino on a breadboard or PCB.

Material:

  • ATMega168/ATMega328 (Your Arduino Microcontroller)
  • 16Mhz Oscillator Crystal
  • 7805 Voltage Regulator (5V Voltage Regulator)
  • 2x 22pF Capacitors
  • 2x 10uF Capacitors

Instructions: Follow the schematic in the reference section. That will show you how to build a basic standalone arduino. Reference to the pin mapping diagram after you are done to connect your pins. Remember this wont let you upload code to the arduino. You will have to continue to use your arduino programmer and place the chip in the circuit.

Reference:

Taken from main arduino site. Shows pinout of each pin

Basic schematic of standalone arduino

About: The LM335 is a simple thermometer with only 3 pins. It can be easily interfaced to the arduino or any other microcontroller. The LM335 is pretty much just a diode in a TO-92 case. The voltage rises 10mv for every degree in Kelvins. You will pretty much need to convert the kelvin temperature to Celsius or Fahrenheit using simple calculations.

Objective: To build a simple digital thermometer using a LM335 and an Arduino.

Material: You will need the following:

  • Arduino Uno
  • LM335
  • 2x 1Kohm resistors

Instructions: The connections are very simple you will only need to use 2 of the 3 pins on the LM335. Pins 2 and 3 will only be used. Refer to the breadboard diagram below for connections. The resistors connect to the middle pin of the LM335. The middle pin then connects to the arduino analog0. Pin 3 of the LM335 is connected to ground.

Calculations: The calculations are based off the Wikipedia for Kelvin. To calculate the Kelvin we read the analog0 pin on our arduino. We multiply that value by .004882812. Why .004882812? We get that by dividing our 5v (Power Supply) by 1024 (10bits based off arduino analog). After we get our Kelvin we – 273.15 to get our Celsius. To get our Fahrenheit we multiply our Kelvin value by 9/5 and then subtract 459.67.

Arduino Code:

/*************************************************
* Temperature Sensor LM335 and Arduino
* -----------------
* Objective: To build a simple digital thermometer
*                 using a LM335 and an Arduino.
*
* https://dayzlab.wordpress.com
*************************************************/

float tempK=0, tempC=0, tempF=0;

void setup(){

Serial.begin(9600);    //Setup serial to 9600 bps
}

void loop(){

tempK = analogRead(0) * 0.004882812 * 100;    //Read temperature in Kelvins first

tempC = tempK - 273.15;    //Convert from Kelvin to Celsius

tempF = ((tempK) * 9 / 5) - 459.67;    //Convert from Kelvin to Fahrenheit

//Print all the values to Serial
Serial.print("Kelvin: "); Serial.println(tempK);
Serial.print("Celsius: "); Serial.println(tempC);
Serial.print("Fahrenheit: "); Serial.println(tempF);
Serial.println();    //Print Blank Line

delay(1000);    //Delay 1 second
}

Hello World

September 25, 2011

Hey Now!

Decided to start up a wordpress and check it out. Wanted a site to keep a log of all my tutorials and projects for future reference for myself. Just something to play around and see if I can keep up with it and actually post on a regular basis. Hope you enjoy the tutorials and projects I make and I hope they can help you out in some way.