/ examples / fram_i2c_simpletest.py
fram_i2c_simpletest.py
 1  ## Simple Example For CircuitPython/Python I2C FRAM Library
 2  
 3  import board
 4  import busio
 5  import adafruit_fram
 6  
 7  ## Create a FRAM object (default address used).
 8  i2c = busio.I2C(board.SCL, board.SDA)
 9  fram = adafruit_fram.FRAM_I2C(i2c)
10  
11  ## Optional FRAM object with a different I2C address, as well
12  ## as a pin to control the hardware write protection ('WP'
13  ## pin on breakout). 'write_protected()' can be used
14  ## independent of the hardware pin.
15  
16  # import digitalio
17  # wp = digitalio.DigitalInOut(board.D10)
18  # fram = adafruit_fram.FRAM_I2C(i2c,
19  #                              address=0x53,
20  #                              wp_pin=wp)
21  
22  ## Write a single-byte value to register address '0'
23  
24  fram[0] = 1
25  
26  ## Read that byte to ensure a proper write.
27  ## Note: reads return a bytearray
28  
29  print(fram[0])
30  
31  ## Or write a sequential value, then read the values back.
32  ## Note: reads return a bytearray. Reads also allocate
33  ##       a buffer the size of slice, which may cause
34  ##       problems on memory-constrained platforms.
35  
36  # values = list(range(100)) # or bytearray or tuple
37  # fram[0] = values
38  # print(fram[0:99])