Read\Write I2C EEPROM using Arduino (or anything) - Page 1
Forum section: electronics / beginners

author: VEGETA
author_rank: Super Contributor
timestamp: July 24, 2017, 08:10:37 pm
content: Dear EEVBlog members,I saw this link:https://playground.arduino.cc/Code/I2CEEPROMI need to read AT24cxx eeproms data to a file on my PC\laptop (.txt for example) and also writes a certain file to another EEPROM... like copying one of them then programming the other one.I didn't find in that link or any other how to do that part which involves storing the values in a txt file not just on serial because some chips has too many lines, also writing will not happen if I have the data on a txt file using that sketch alone.Looking forward to your generous help!Best regards,Vegeta

author: 3db
author_rank: Frequent Contributor
timestamp: July 24, 2017, 11:46:07 pm
content: Check out the UNI-T UT210E clamp meter thread.There's some information there about using an Arduino to read/write these chips.You could also check Kerry Wong's Youtube channel where he modifies one of these chips in a multimeter.He wrote some Arduino code to do this which is on his website.Sorry I can't be bothered finding the links for you3DB

author: rstofer
author_rank: Super Contributor
timestamp: July 25, 2017, 12:21:37 am
content: That library code reads and writes the EEPROM, nothing else. In setup() there is an example of writing a string to the EEPROM starting at address 0x0000. In loop() there is an example of reading the contents starting at address 0x0000 on up until a 0x00 is read (end of string written above).Getting EEPROM data into and out of the Arduino is one thing, writing a text file out in PC land is an entirely different matter. There are a number of projects on the Internet where the user wants to capture text data from the Arduino. That is pretty easy! I would have the Arduino convert the bytes to the Intel Hex format before transmission. That includes calculating the checksum which will allow the PC to verify the transmission.What's hard is having the PC send data to the Arduino serial port. The hardest part is for the Arduino to halt the PC while is processes a line of text. I'm not sure what the best way to do that will be. I would write something in Python (I guess...) that reads the file converts it to Intel Hex format if not already done and sends one line to the Arduino. Then the Python code waits for an acknowledgement from the Arduino before sending the next line. The Arduino will eat the hex line, verify the checksum and strip out the bytes before writing the EEPROM with the library from above.Note that the Intel Hex format has an address field. This is kind of nice should the file be discontinuous. You know where to write the bytes based on the address field. This field only covers 64k bytes so there is another record type that gives an address to add. If the hex file is coming from a compiler, the appropriate record type may already be determined. If what you have is a big heap of bytes, you can decide how to implement the Extended Linear Address record (type '04).http://www.interlog.com/~speff/usefulinfo/Hexfrmt.pdfThe Arduino <-> I2C is trivial, the rest of the project is going to take a little time.This should be an interesting use of Arduino and Python (or whatever).

author: rstofer
author_rank: Super Contributor
timestamp: July 25, 2017, 12:28:55 am
content: There's another way to skin this cat - skip the Arduino and buy one of the FTDI FT2232 bridges.http://hackaday.com/2011/11/14/ft-2232-bridges-python-and-i2cspi/I haven't gone down this rabbit hole. One comment is that writing code is time consuming but there is a library wrapper (Linux based)http://www.devttys0.com/2011/11/speaking-spi-i2c-with-the-ft-2232/I like breaking the project up into pieces. I would probably create the Arduino serial exchange with Intel Hex bit and the I2C library first and then worry about what to do with the PC end of the business.Any language can be used, Python isn't the only game in town. What you do need is a serial library to talk to the Arduino VCOM port.

author: rstofer
author_rank: Super Contributor
timestamp: July 25, 2017, 12:33:19 am
content: There's another way: Use a Raspberry Pi. How you get the file from a PC to the PI is a simple matter of file sharing over the LAN.Now that you have the .bin file you can use the RPI I2C library to read/write the EEPROM.https://www.richud.com/wiki/Rasberry_Pi_I2C_EEPROM_ProgramNote section 10 where reading and writing a file is discussed.This might be the easiest way once you get the setup out of the way. Raspberry PI can deal with files and I2C so the task doesn't need to be spread all over the place.

author: 3db
author_rank: Frequent Contributor
timestamp: July 25, 2017, 07:33:48 am
content: Or even easier just buy the CH340 based programmer mentioned in the UT210 thread.

author: VEGETA
author_rank: Super Contributor
timestamp: July 25, 2017, 07:44:44 am
content: I have found this tool which seems cheap:https://www.banggood.com/CH341A-24-25-Series-EEPROM-Flash-BIOS-DVD-USB-Programmer-p-929338.htmlI guess that would work but I didn't do much research about it. I am not sure if it does program at24cxx eeproms or not.However, this seems to work according to description:https://www.ebay.com/p/EEPROM-Programmer-Reader-Writer-USB-for-At24cxx-Hot/874481693I hoped to find a simple way using Arduino to save the file to a *.txt and send it by serial port, then vise versa. I found some results but one github page is for linux with compiling software and stuff which won't help. I tried searching for using tools such as usbasp or serial to ttl converters but no use since it is I2C not serial data. Using RPI now is not an option for me.I guess, according to your replies and my situation, buying one of these 5$ I2C EEPROM programmer is the choice (if anyone can confirm that they work). Messing with Arduino and stuff will take time and effort while I cannot provide due to my work (plus, I am not the one who will eventually work on these eeproms).I just hoped to have a simple Arduino code to dump stuff to PC via serial port or vice versa.

author: 3db
author_rank: Frequent Contributor
timestamp: July 25, 2017, 07:55:55 am
content: I can confirm that the ones with a black and gold pcb work.Search Amazon for CH341A USB Programmer and you'll see the type I mean.I think there was a minor issue with the software but it's easily fixed and is mentioned on Youtube.I have no reason to believe the ones you found will not work.Good luck.

author: Rerouter
author_rank: Super Contributor
timestamp: July 25, 2017, 10:41:58 am
content: You can approach it like i did for a rom dumper i made, have it spit out the code in 8 bit chunks, formatted how the write operation has to take place, e.g. reading from 0x09 returns "eeprom.write(0x09,0xAA);" etc, so you just have to copy the serial dump in to your code for the write

author: Ian.M
author_rank: Super Contributor
timestamp: July 25, 2017, 11:48:39 am
content: The major issue is reliable PC <> Arduino comms.As the Arduino makes no provision for hardware handshaking, you have three choices:1. Keep the baud rate low enough so that even with the worst case delay to write to a file on the PC or to write a page to the EEPROM, neither the PC's or the Arduino's serial receive buffers will overflow. As the worst case delay on the PC cant be guaranteed, you'll need to set the baud rate very conservatively and have some means of detecting if data has been lost.2. Use a higher level protocol that transfers the data as packets, with a unique packet number, length check and checksum so that retransmission can be requested for any packet that has lost or corrupted characters. This will have a considerable impact on the Arduino code, as you must wait for each packet's reception to be confirmed before you can reuse the packet buffer + you have to handle the overhead of building each packet. On the PC side, you'll probably need custom software, though it may be possible to reuse file transfer software designed to handle transfers via serial modem, with a well documented protocol and packet structure.3. Use Intel HEX as the data format, implement XON/XOFF handshaking for the PC<>Arduino serial link, and code the Arduino loop() function to be non-blocking so it can always respond to a received XOFF quickly. Unfortunately the Arduino Wire (I2C) library uses blocking code so either you need to use a non-blocking Wire replacement or bypass the Wire library and use the AVR TWI hardware interface directly, otherwise you risk dropping data while waiting for an EEPRM byte or page write to complete. On the PC end, use any terminal that supports XON/XOFF handshaking, capture to, and transmission of a file. As there is no check that whole lines haven't been lost from the Intel HEX file, you also need a verify mode on the Arduino that compares received data against existing EEPROM contents, and repoorts any discrepancies and the total number of bytes checked.

author: VEGETA
author_rank: Super Contributor
timestamp: July 25, 2017, 02:21:03 pm
content: Quote from: 3db on July 25, 2017, 07:55:55 amYou mean this one right?https://www.aliexpress.com/item/Free-shipping-Local-tyrants-gold-CH341A-programmer-routing-liquid-crystal-USB-motherboard-BIOS-FLASH-burn-24/32263275388.html

author: 3db
author_rank: Frequent Contributor
timestamp: July 25, 2017, 04:01:48 pm
content: @VEGETAYes that's the one.