Quantcast
Channel: JH7UBCブログ
Viewing all articles
Browse latest Browse all 440

Rasperry Pi I2C

$
0
0
 I2CアダプタをつけたLCD102をRaspberry Piで表示する勉強をしています。

 Raspberry PiのPythonで、I2C通信をbyte単位で行う関数は、

 write_byte_data(アドレス,コマンド,1バイトの値) です。

 実際にどのような信号がラズパイから出ているのか観察してみました。 

 測定用に次のような簡単なスクリプトを書き、I2Cの出力をpico scopeで記録しました。

from time import sleep
import smbus
bus = smbus.SMBus(1)
LCD_address = 0x27
try:
    while True:
        bus.write_byte_data(LCD_address,0x00,0x12)
        sleep(0.0001)
except KeyboardInterrupt:
    pass

ラズパイのSCLとSDA信号です。
イメージ 1

SCLの周波数は、約62.5KHzで、パルス幅は、約8usです。

1byteを送るのに要する時間は、約140usです。

I2Cデバイスを接続しないとIOエラーが出ます。

これを参考にして、I2Cアダプタ付きのLCD1602の表示テストのスクリプトを書いてみます。 

Viewing all articles
Browse latest Browse all 440

Trending Articles