basic_read_write.py
1 # Basic Example to read and write from AT24MACx02 EEPROM Devices 2 3 # Written by FACTS Engineering 4 # Copyright (c) 2023 FACTS Engineering, LLC 5 # Licensed under the MIT license. 6 7 # 8 9 import board 10 import busio 11 import at24mac_eeprom 12 13 # Create EEPROM Object 14 i2c = busio.I2C(board.ATMAC_SCL, board.ATMAC_SDA) 15 # i2c = busio.I2C(board.SCL, board.SDA) # For external I2C devices 16 eeprom = at24mac_eeprom.AT24MAC(i2c) 17 18 # Address lines default to 0b100. They can be specified if needed. 19 # eeprom = at24mac_eeprom.AT24MAC(i2c, 0b101) 20 21 # Print out MAC address and serial number 22 print(eeprom.mac) # Format for use with Wiznet5k 23 print([hex(val) for val in eeprom.mac]) # Readable format 24 print(eeprom.serial_number) 25 print() 26 27 # Write and read to address 0 using the device object like an array 28 eeprom[0] = 76 29 print(eeprom[0]) 30 print() 31 32 # Write and read to address 100 using array slices 33 eeprom[100] = [6, 7, 8, 9, 10] 34 print([val for val in eeprom[100:105]]) 35 print() 36 37 while True: 38 pass