I think I get the encode/decode to/from bytes.
- Code: Select all | TOGGLE FULL SIZE
>>> message = "Python is fun"
>>> bytes_encoded = message.encode()
>>> bytes_decoded = bytes_encoded.decode()
>>> print(bytes_encoded)
b'Python is fun'
>>> print(bytes_decoded)
Python is fun
>>>
Now how do you write the bytes_encoded to Fram? Clearly based on the example of Fram[0] = 1 won't cut it for trying to swap in the bytes_encoded variable.
Sorry, I'm not a master python expert.
- Code: Select all | TOGGLE FULL SIZE
>>> import board
>>> import busio
>>> import digitalio
>>> import adafruit_fram
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> wp = digitalio.DigitalInOut(board.D21)
>>> fram = adafruit_fram.FRAM_I2C(i2c, wp_pin=wp)
>>> message = "Python is fun"
>>> bytes_encoded = message.encode()
>>> fram[0] = bytes_encoded
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/adafruit_fram.py", line 174, in __setitem__
"Data must be a single integer, or a bytearray," " list, or tuple."
ValueError: Data must be a single integer, or a bytearray, list, or tuple.
>>>
Now I did read up on using bytearray and that seems to be heading in that direction, but for only 1 character of my message vs. the whole thing.
- Code: Select all | TOGGLE FULL SIZE
>>> array = bytearray(bytes_encoded)
>>> print(array)
bytearray(b'Python is fun')
>>> fram[0] = array
>>> print(fram[0])
bytearray(b'P')
>>>
Do you happen to have anything that's been used with this FRAM to write and read data?
My end goal is to take sensor data from a BMP390 and write it to the FRAM. Right now I've
got code which taking (pressure = bmp.pressure) and sending it via Mosquito (client.publish('Pressure', pressure)).
But I'd also like to write a hard copy of that same data to the FRAM chip.
Suggestions?