Created
December 9, 2018 20:25
-
-
Save danielkucera/321801887b62392deeea73b268a37ba7 to your computer and use it in GitHub Desktop.
i2c-eeprom.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import time | |
import os | |
bus = sys.argv[1] # /dev/i2c-X | |
addr = sys.argv[2] # 0x50 | |
filename = sys.argv[3] | |
offset = 0 | |
file = open(filename,"r") | |
while True: | |
chunk = file.read(16) | |
if not chunk: | |
break | |
data = " ".join("0x{:02x}".format(ord(c)) for c in chunk) | |
chlen = len(chunk) | |
cmd = "i2ctransfer -y %s w%d@%s 0x%X %s" % (bus, chlen + 1, addr, offset, data) | |
print cmd | |
os.system(cmd) | |
time.sleep(0.1) | |
offset += chlen | |
file.close() | |
cmd = "i2cdump -y %s %s" % (bus, addr) | |
print cmd | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment