{"id":22090,"date":"2018-01-20T22:13:38","date_gmt":"2018-01-20T15:13:38","guid":{"rendered":"http:\/\/tom.ji42.com\/?p=22090"},"modified":"2018-01-20T22:13:38","modified_gmt":"2018-01-20T15:13:38","slug":"i2c-eeprom-module-at24c256","status":"publish","type":"post","link":"https:\/\/tom.tomwork.net\/?p=22090","title":{"rendered":"I2C EEPROM Module- AT24C256"},"content":{"rendered":"<p>If you need to do some data storage in Arduino but found that the EEPROM in ATmega chip too limited, then this I2C EEPROM module is your best choice. This module is based on the EEPROM chip AT24C256, which has 256k bit capacity. It communicate with Arduino\u00a0using I2C bus.<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0**<a href=\"http:\/\/playground.arduino.cc\/code\/I2CEEPROM\">I2C EEPROM Introduction on Arduino<\/a><\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 **<a href=\"https:\/\/www.robot-r-us.com\/e\/978-at24c32test.html\">Test Code<\/a><\/p>\n<p dir=\"ltr\" align=\"left\">Specification<\/p>\n<ul dir=\"ltr\">\n<li>\n<div>Onboard chip AT24C256 chip<\/div>\n<\/li>\n<li>\n<div>Onboard the I2C communications required pull-up resistor<\/div>\n<\/li>\n<li>\n<div>All pins are leads and marked<\/div>\n<\/li>\n<li>\n<div>PCB board Dimensions : 36.5 (mm) x12 (mm)<\/div>\n<\/li>\n<\/ul>\n<p dir=\"ltr\" align=\"left\"><!--more--><\/p>\n<p dir=\"ltr\" align=\"left\"><strong>Demo Program<\/strong><\/p>\n<p dir=\"ltr\" align=\"left\">#include Wire.h<\/p>\n<p dir=\"ltr\" align=\"left\">#define EEPROM_ADDR 0x50\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ I2C Buss address of 24LC256 256K EEPROM<\/p>\n<p dir=\"ltr\" align=\"left\">void setup()<br \/>\n{<br \/>\nWire.begin();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ join I2C bus (address optional for master)<br \/>\nSerial.begin(9600);<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 \/\/ TESTS FOR EACH FUNCTION BEGIN HERE<br \/>\nSerial.println(&#8220;Writing Test:&#8221;);<br \/>\nfor (int i=0; i&lt;20; i++){\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ loop for first 20 slots<br \/>\ni2c_eeprom_write_byte(EEPROM_ADDR,i,i+65);\u00a0\u00a0 \/\/ write address + 65 A or 97 a<br \/>\nSerial.print(&#8220;. &#8220;);<br \/>\ndelay(10);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ NEED THIS DELAY!<br \/>\n}<br \/>\nSerial.println(&#8220;&#8221;);<br \/>\ndelay(500);<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 Serial.println(&#8220;Reading Test:&#8221;);<br \/>\nfor (int i=0; i&lt;20; i++){\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ loop for first 20 slots<br \/>\nSerial.write(i2c_eeprom_read_byte(EEPROM_ADDR, i));<br \/>\nSerial.print(&#8221; &#8220;);<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 \/\/ setup for page tests . . .<br \/>\nbyte PageData[30];\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ array that will hold test data for a page<br \/>\nbyte PageRead[30];\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ array that will hold result of data for a page<br \/>\nfor (int i=0; i&lt;30; i++){\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ zero both arrays for next test<br \/>\nPageData[i] = 0;<br \/>\nPageRead[i] = 0;<br \/>\n}<br \/>\nSerial.println(&#8220;&#8221;);<br \/>\nfor (int i=0; i&lt;30; i++) PageData[i] = i+33;\u00a0 \/\/ fill up array for next test char 33 = !<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 Serial.println(&#8220;Writing Page Test:&#8221;);<br \/>\ni2c_eeprom_write_page(EEPROM_ADDR, 100, PageData, 28 ); \/\/ 28 bytes\/page is max<\/p>\n<p dir=\"ltr\" align=\"left\">\u00a0 Serial.println(&#8220;Reading Page Test:&#8221;);<br \/>\ni2c_eeprom_read_buffer( EEPROM_ADDR, 100, PageRead, 28);<br \/>\nfor (int i=0; i&lt;28; i++){<br \/>\nSerial.write(PageRead[i]);\u00a0\u00a0\u00a0 \/\/ display the array read<br \/>\nSerial.print(&#8221; &#8220;);<br \/>\n}<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">void loop()<br \/>\n{<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data )<br \/>\n{<br \/>\nint rdata = data;<br \/>\nWire.beginTransmission(deviceaddress);<br \/>\nWire.write((int)(eeaddress &gt;&gt; 8));\u00a0\u00a0\u00a0 \/\/ Address High Byte<br \/>\nWire.write((int)(eeaddress &amp; 0xFF));\u00a0 \/\/ Address Low Byte<br \/>\nWire.write(rdata);<br \/>\nWire.endTransmission();<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">\/\/ Address is a page address, 6-bit (63). More and end will wrap around<br \/>\n\/\/ But data can be maximum of 28 bytes, because the Wire library has a buffer of 32 bytes<br \/>\nvoid i2c_eeprom_write_page<br \/>\n( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length )<br \/>\n{<br \/>\nWire.beginTransmission(deviceaddress);<br \/>\nWire.write((int)(eeaddresspage &gt;&gt; 8)); \/\/ Address High Byte<br \/>\nWire.write((int)(eeaddresspage &amp; 0xFF)); \/\/ Address Low Byte<br \/>\nbyte c;<br \/>\nfor ( c = 0; c &lt; length; c++)<br \/>\nWire.write(data[c]);<br \/>\nWire.endTransmission();<br \/>\ndelay(10);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ need some delay<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress )<br \/>\n{<br \/>\nbyte rdata = 0xFF;<br \/>\nWire.beginTransmission(deviceaddress);<br \/>\nWire.write((int)(eeaddress &gt;&gt; 8));\u00a0\u00a0\u00a0 \/\/ Address High Byte<br \/>\nWire.write((int)(eeaddress &amp; 0xFF));\u00a0 \/\/ Address Low Byte<br \/>\nWire.endTransmission();<br \/>\nWire.requestFrom(deviceaddress,1);<br \/>\nif (Wire.available()) rdata = Wire.read();<br \/>\nreturn rdata;<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">\/\/ should not read more than 28 bytes at a time!<br \/>\nvoid i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length )<br \/>\n{<br \/>\nWire.beginTransmission(deviceaddress);<br \/>\nWire.write((int)(eeaddress &gt;&gt; 8));\u00a0\u00a0\u00a0 \/\/ Address High Byte<br \/>\nWire.write((int)(eeaddress &amp; 0xFF));\u00a0 \/\/ Address Low Byte<br \/>\nWire.endTransmission();<br \/>\nWire.requestFrom(deviceaddress,length);<br \/>\n\/\/int c = 0;<br \/>\nfor ( int c = 0; c &lt; length; c++ )<br \/>\nif (Wire.available()) buffer[c] = Wire.read();<br \/>\n}<\/p>\n<p dir=\"ltr\" align=\"left\">\n<p dir=\"ltr\" align=\"left\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.robot-r-us.com\/images\/stories\/Ele\/SEEP24C256%20I2C%20EEprom%20A.JPG\" width=\"552\" height=\"479\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to do some data storage in Arduino but found that the EEPROM in ATmega chip too limited, then this I2C EEPROM module is your best choice. This module is based on the EEPROM chip AT24C256, which has 256k bit capacity. It communicate with Arduino\u00a0using I2C bus. \u00a0**I2C EEPROM Introduction on Arduino \u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[],"class_list":["post-22090","post","type-post","status-publish","format-standard","hentry","category-13"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6cOVM-5Ki","_links":{"self":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22090"}],"version-history":[{"count":1,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22090\/revisions"}],"predecessor-version":[{"id":22091,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22090\/revisions\/22091"}],"wp:attachment":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}