![]() |
BBBも混雑しはじめてきたw |
いやー、嫌ですね、技術屋って略号ばっかりで…と言われそうなタイトルですが。とりあえず、いろいろググっていたら、シェルスクリプトだけでI2C液晶が時計になってしまう記事を見かけたので、さっそく試してみました。
まず、i2cの初期化をします。初期化について参考にさせていただいたのはこちらです。
記事はRev.A5AでうちのはRev.Cなのが原因かどうか、少しパラメータなどが違っていました。
まず、P8-17/18ピンのi2c端子I2C1を有効にしますが、その前にポートの状態を調べておきます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@beaglebone:~# ls -al /sys/bus/i2c/devices/i2c-* | |
lrwxrwxrwx 1 root root 0 6月 22 2014 /sys/bus/i2c/devices/i2c-0 -> ../../../devices/ocp.3/44e0b000.i2c/i2c-0 | |
lrwxrwxrwx 1 root root 0 6月 22 2014 /sys/bus/i2c/devices/i2c-1 -> ../../../devices/ocp.3/4819c000.i2c/i2c-1 | |
root@beaglebone:~# |
つぎに、ポートを初期化します。
echo BB-I2C1 > /sys/devices/bone_capemgr.9/slots
もう一度ポートの状態を確認します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@beaglebone:~# ls -al /sys/bus/i2c/devices/i2c-* | |
lrwxrwxrwx 1 root root 0 6月 24 2014 /sys/bus/i2c/devices/i2c-0 -> ../../../devices/ocp.3/44e0b000.i2c/i2c-0 | |
lrwxrwxrwx 1 root root 0 6月 24 2014 /sys/bus/i2c/devices/i2c-1 -> ../../../devices/ocp.3/4819c000.i2c/i2c-1 | |
lrwxrwxrwx 1 root root 0 2月 18 23:00 /sys/bus/i2c/devices/i2c-2 -> ../../../devices/ocp.3/4802a000.i2c/i2c-2 | |
root@beaglebone:~# |
良いようです。はい。ここで注意。配線したのはI2C1ですが、今設定して変化したのはi2c-2って書いてある行です。上の記事によれば、1と2の番号とデバイスが入れ替わっているのだとか。よーわからんのですが、Beagleboneにはこういう要素が多いような気がします。ともかく、先人のおかげでハマらないですみました。ありがとうございます。
というわけで、秋月の液晶「 I2C接続小型LCDモジュールピッチ変換キット」をBeagleboneと接続します。GND, 3.3V、あとは10kΩでプルアップしたSDAとSCL。基本これだけでいいのですが、RESET端子を3.3Vにつないでおきます。オープンにしたままだとリセットされないことがあるので。
接続したら、確認します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@beaglebone:~# i2cdetect -y -r 2 | |
0 1 2 3 4 5 6 7 8 9 a b c d e f | |
00: -- -- -- -- -- -- -- -- -- -- -- -- -- | |
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3e -- | |
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
70: -- -- -- -- -- -- -- -- | |
root@beaglebone:~# |
液晶のデバイス番号3eが見えますね。秋月の資料には「スレーブアドレスは、0x7Cです」と書いてありますが、これはread/writeビットを最下位に置いて読んでいるためです。これ、メーカーなどによって読み方 / 指定の仕方が違うので悩むんですよね…。ともかくBBBでは3eです。
では、今度はBeagleBone Black のハードウェアハック(5)を参考にしてデジタル時計を動かしてみます。viでコードをコピペするのですが、記事とはi2csetのパス(i2cset=/usr/sbin/i2ctest)と接続しているポート(bus=2)が異なるのでそこは書き換えたのですが…記事の通りでは真っ黒い四角が並ぶだけでした。上記秋月の資料と比較してみると、コントラスト設定値として0x3fが指定されてて液晶が真っ黒になってしまうのと、意味はわからないですがICONってのがOFFになっていること、が原因のようでした。秋月の資料と同じデータ順にして、ばっちり動きました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
i2cset=/usr/sbin/i2cset | |
bus=2 | |
chip=0x3e | |
LANG=C | |
# initialize LCD display | |
$i2cset -y $bus $chip 0 0x38 0x39 0x14 0x70 0x56 0x6c i | |
sleep 0.5 | |
$i2cset -y $bus $chip 0 0x38 0x0c 0x01 i | |
sleep 0.5 | |
while true ; do | |
MSG=`date +"%X" | perl -pe '$_=join" ",map{ord }split//'` | |
$i2cset -y $bus $chip 0 0x01 | |
$i2cset -y $bus $chip 0x40 $MSG i | |
sleep 1 | |
done |
スクリプトでこんなことできちゃうんですね。すげー。
改めて、初期化とスクリプト時計の執筆者の方々に感謝申し上げます。おかげさまで今夜はすっきりぐっすり眠れそうです。
ありがとうございました。
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。