実験 I2C 接続 AE-AQM0802(LCD) Raspberry Pi Zero WH

実験 I2C 接続 AE-AQM0802(LCD) Raspberry Pi Zero WH
AQM0802(400Kbit/s) +3.3V駆動 参考 i2cset

★コマンドからI2Cへアクセス
$ sudo raspi-config #I2C を有効にする
$ i2cdetect -y 1 #I2C bus 1 に接続されているデバイスを調べる
$ i2cset -y 1 0x3e 0x00 0x38 0x39 0x14 0x78 0x5f 0x6a i #1=I2C bus 1 -y=no confirmation i=block data(not 1 byte)
$ i2cset -y 1 0x3e 0x00 0x0c 0x01 i
$ i2cset -y 1 0x3e 0x00 0x06 b #b=one byte data
$ i2cset -y 1 0x3e 0x00 0x80 b #1st line
$ i2cset -y 1 0x3e 0x40 0x48 0x65 0x6c 0x6c 0x6f i #’Hello’

★I2C通信速度変更 speed 要再起動
/boot/config.txt
dtparam=i2c_baudrate=50000 #50Kbit/s

★Python3からI2Cへアクセス (baudrate=400000) 動作OK

import smbus,time
i2c1=smbus.SMBus(1)
i2c1.write_i2c_block_data(0x3e,0x00,[0x38,0x39,0x14,0x78,0x5f,0x6a])
time.sleep(0.200) #1=1s 0.001=1ms
i2c1.write_i2c_block_data(0x3e,0x00,[0x0c,0x01])
time.sleep(0.002) #1=1s 0.001=1ms
i2c1.write_byte_data(0x3e,0x00,0x06)
i2c1.write_byte_data(0x3e,0x00,0x80)
i2c1.write_i2c_block_data(0x3e,0x40,[0x48,0x65,0x6c,0x6c,0x6f]) #'Hello'

★I2C エラー処理準備 (通信中に SDA,SCL,+3.3V (どの信号でも)の障害でエラー発生)
[Errno 121] Remote I/O error

import smbus,time

i2c1=smbus.SMBus(1) #0=(port I2C0), 1=(port I2C1)
i2c1.write_i2c_block_data(0x3e,0x00,[0x38,0x39,0x14,0x78,0x5f,0x6a]); time.sleep(0.200) #200ms
i2c1.write_i2c_block_data(0x3e,0x00,[0x0c,0x01]); time.sleep(0.002) #2ms
i2c1.write_byte_data(0x3e,0x00,0x06)
i2c1.write_byte_data(0x3e,0x00,0x80)
i2c1.write_i2c_block_data(0x3e,0x40,[0x48,0x65,0x6c,0x6c,0x6f]) #'Hello'

d=1
while 1:
    d=0x30+((1+d)%10) #9-0 countdown ascii
    time.sleep(1.000) #1s
    try:
        i2c1.write_byte_data(0x3e,0x00,0xc0) #2nd line
        i2c1.write_byte_data(0x3e,0x40,d)
    except Exception as e:
        pass ;print(e) #error if exist