Simple test

Ensure your device works with this simple test.

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