Hi
I have no idea if this may be of help to anyone trying to use i2c to communicate from a Pi to an FRAM chip such as the MB85RC256 .
Though Adafruit distribute an 'FRAM breakout' (that seems to use the MB85RC256 ) their libraries seem orientated to Arduino - I have not found any for node-red or even python.
Eventually, thanks to this forum, I discovered a few leads that got me going. I ended up using Pigpio. It seems to work really well. Eventually I will get it into Javascript and then a node for NR.
But if anyone is struggling to communicate with this device, here is the python code I used.
NOTE: You will need to make sure the 'BUS' and 'FRAM' variables use those that match YOUR i2c setup....
###########################################################
I have no idea if this may be of help to anyone trying to use i2c to communicate from a Pi to an FRAM chip such as the MB85RC256 .
Though Adafruit distribute an 'FRAM breakout' (that seems to use the MB85RC256 ) their libraries seem orientated to Arduino - I have not found any for node-red or even python.
Eventually, thanks to this forum, I discovered a few leads that got me going. I ended up using Pigpio. It seems to work really well. Eventually I will get it into Javascript and then a node for NR.
But if anyone is struggling to communicate with this device, here is the python code I used.
NOTE: You will need to make sure the 'BUS' and 'FRAM' variables use those that match YOUR i2c setup....
###########################################################
Code:
# This code is used to write and read to/from an FRAM chip on the i2c bus of a Raspberry Pi# I have only tried this with the MB85RC256 device# I believe this is the same chip as in the Adafruit 'FRAM breakout'## I have not tried this code with that breakout board.# I am sure this code could be tighter and more elegant. I am not a coder.# But life is short and it does what I need# If you have struggled to use FRAMs on a Pi, then it is a good starting point...import timeimport structimport sysimport pigpio # http://abyz.co.uk/rpi/pigpio/python.html# My file for this code is called "frampig.py"## IMPORTANT: The programme assumes two command line arguments:## - Text to be written# - Memory location of first character (decimal)## Launch like this: python frampig.py "Hello world again!" 1033## It will bomb-out if you fail to supply arguments.MY_STRING=sys.argv[1] # The string you want to saveMEM_LOCATION=int(sys.argv[2]) # The starting address (decimal) of where to start the saving in the FRAM# We need to split the start location up into two bytesdef bytes(integer): return divmod(integer, 0x100)high, low = bytes(MEM_LOCATION)MY_START_POS=[high,low]# The FRAM chip assumes it will be fed a list of numbers# The firt two must be the start location, the rest are the integer values of the characters to be written# So start the list with the previously calculated start position (two bytes)MY_SAVE_LIST=[high,low]#Now add the decimal values of all the characters in the incoming string to be writtenfor ele in MY_STRING: MY_SAVE_LIST.extend(ord(num) for num in ele)# We will need the length later to read back the same number of characters as we wanted to saveMY_LENGTH=len(MY_STRING)#i2c bus and FRAM address (I am using custom pins for i2c, hence bus 3) BUS=3 # <=== CHECK YOUR i2c BUS NUMBER!FRAM=0x57 # <=== CHECH YOUR FRAM ADDRESS!pi=pigpio.pi() # open local Pi instance# Open ic2handleI2C = pi.i2c_open(BUS, FRAM)# Write incoming string (MYLIST) starting at MYSTART address (remember, the first two digits of MY_LIST are the start position...)pi.i2c_write_device(handleI2C, MY_SAVE_LIST)# The following write instruction seems to set the device to use correct# address for the start of the subsequent read instruction... but I am not sure# The read instructions seems to go astray without this call!pi.i2c_write_device(handleI2C, MY_START_POS)# Now the actual read instruction, we will retrieve just the same number of characters as were writtenREADBACK=pi.i2c_read_device(handleI2C,MY_LENGTH)# Turn the byte object into a listREADLIST=list(READBACK[1])# Now convert the list of numbers back into a stringres = ''.join(map(chr, READLIST))MYASCII=str(res)# See what it looks like!print(MYASCII)pi.stop# Good luck!
Statistics: Posted by nicknack23 — Tue Mar 05, 2024 3:46 pm — Replies 0 — Views 27