microbit的24LCxx驱动(EEPROM)

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

microbit的24LCxx驱动(EEPROM)

#1

帖子 shaoziyang »

来自:https://github.com/matneee/microbit-I2C ... Read-Write

microbit带有I2C接口,这个驱动演示了通过I2C使用24LCxx读写数据。

代码: 全选

def weep(eepAdr, value):
    data = bytearray(3)
    data[0]=eepAdr >> 8 #msb
    data[1]=eepAdr & 0xFF #lsb
    data[2]=value
    i2c.write(0x50, data, repeat = False)
    sleep(20)
    return("OK")

#Read from EEPROM
#Writes the 2 byte memory address to tell the EEPROM where to fetch data from, then reads values from that memory address
#num represents how many sequential bytes to read (default is 1)
def reep(eepAdr, num = 1):
    data = bytearray(2)
    data[0]=eepAdr >> 8 
    data[1]=eepAdr & 0xFF
    i2c.write(0x50, data)
    value = (i2c.read(0x50, num, repeat=False))
    return value[:]
    
adr = 0
for val in font:
    weep (adr, val)
    adr +=1
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章