Skip to content

Instantly share code, notes, and snippets.

@danielkucera
Created December 9, 2018 20:25
Show Gist options
  • Save danielkucera/321801887b62392deeea73b268a37ba7 to your computer and use it in GitHub Desktop.
Save danielkucera/321801887b62392deeea73b268a37ba7 to your computer and use it in GitHub Desktop.
i2c-eeprom.py
#!/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