As part of the Winter Logger project, I got myself some DIP EEPROMs from eBay which were ostensibly AT24C256’s, mostly because I didn’t feel like buying yet more stuff that I probably would never use just to pad out Mouser’s £33 for free shipping minimum order.
This is what I got:
With all the counterfeit semiconductors floating out there, I wanted to verify if I at least had functional EEPROM that wasn’t literally just plastic with some legs tacked onto it - I wanted to test if all the memory cells actually worked.
CircuitPython
Python is always the first choice to hack together these sorts of one off scripts without having to go through the headache of C-like languages. Having a Pi Pico W laying around waiting to be tested, I decided to give this new CircuitPython stuff a go.
It wasn’t the ultra-smooth-switch-off-half-my-brain experience that I was used to with Python, especially with the I2C driver, and Googling didn’t immediately reveal answers, so here is a little trail for first timers out there to follow.
Code (that worked)
|
|
If a quick EEPROM tester script is all you’re after, there you go.
This code was adapted from the I2C bus scanner script here
Gotchas
In order to save space, some of the niceties of the classic Python interpreter aren’t available, and the error messages aren’t as helpful either.
Here are some of the issues that I encountered (with Adafruit CircuitPython 7.3.3 on 2022-08-29):
- If you try to read too many bytes you get a timeout, so I chose to read 2048 bytes to solve this problem
- The
to_bytes()
function throwsTypeError: function missing 1 required positional arguments
if you specify the names of arguments because natively, MicroPython (of which CircuitPython is a fork) does not implement named arguments to save space:dataToWrite = currentIndex.to_bytes(2, byteorder='big')
throwsTypeError: function missing 1 required positional arguments
dataToWrite = currentIndex.to_bytes(2, 'big')
works- Even more confusingly, it seems like some of CircuitPython’s own libraries do support keyword arguments (arguments with the names specified)… Specifically, during testing, the
i2c
functions worked with keyword arguments.
bytearray.extend()
does not work, instead, to concatenate byte arrays, usebyte_array1 += byte_array2
i2c.writeto(int("0x50", base=16), dataToWrite)
throwsTypeError: function doesn't take keyword arguments
because of the reason specified above. But I was extremely confused because in my mind the function throwing this error isi2c.writeto()
, not the nativeint()
casting. You don’t need to cast thestring
toint
by the way, just literally typing0x50
will work.
I’d recommend that you nest your code as little as possible by the way, since the error messages given in the terminal only tell you which line the error message occurs at, unlike the full blown desktop Python which has nice tracebacks and indicators.
Coil Whine?
As a quick aside, I noticed that the Pi Pico W was whistling when the program was running, and that the pitch would vary over time.
Interesting… Perhaps an investigation for another time.
Conclusion
Well, I’m happy to report that my EEPROM’s passed this data integrity check, time to move on with the Winter Logger project then.
Happy hacking!