サーボで動かすのは、以前に、ここ とか ここ で使ったおもちゃのロボットハンドです。
まずは、Servo Driver への送信コマンドを解析するためにArduinoに接続して、Adafruit提供のライブラリのソースを見ながら、ロジアナでI2Cの信号を追いかけました。
次に IchigoJam に Servo Driver を接続して、手動でコマンドをたたきながら、ロジアナで応答を確認。
一応、パルス幅設定が正常にに行われ、オシロでもPWM出力のパルス幅が変わることが確認できたので、実際にサーボを接続して、コードから動かしてみました。
動かしてみたところ。
コードはこんな感じ。
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
10 clt:clv:A=#40 | |
20 poke #700,#0,#10,#65,#a1 | |
30 R=i2cw(A,#700,1,#700,1) | |
40 wait(1) | |
50 R=i2cw(A,#700,1,#701,1) | |
60 wait(1) | |
70 R=i2cw(A,#700,1,#702,1) | |
80 wait(1) | |
90 R=i2cw(A,#700,1,#700,1) | |
100 wait(1) | |
110 R=i2cw(A,#700,1,#703,1) | |
120 wait(180) | |
200 for I=1 to10 | |
210 for B=0 to 1 | |
220 poke #705,#6+B*4,#0,#0,#0,#7 | |
230 R=i2cw(A,#705,1,#706,4) | |
240 next | |
250 for B=2 to 4 | |
260 poke #705,#6+B*4,#0,#0,#70,#3 | |
270 R=i2cw(A,#705,1,#706,4) | |
280 next | |
290 wait(120) | |
300 B=0 | |
310 poke #705,#6+B*4,#0,#0,#0,#7 | |
320 R=i2cw(A,#705,1,#706,4) | |
330 B=1 | |
340 poke #705,#6+B*4,#0,#0,#70,#3 | |
350 R=i2cw(A,#705,1,#706,4) | |
360 B=2 | |
370 poke #705,#6+B*4,#0,#0,#0,#7 | |
380 R=i2cw(A,#705,1,#706,4) | |
390 for B=3 to 4 | |
400 poke #705,#6+B*4,#0,#0,#70,#3 | |
410 R=i2cw(A,#705,1,#706,4) | |
420 next | |
430 wait(120) | |
440 for B=0 to 1 | |
450 poke #705,#6+B*4,#0,#0,#70,#3 | |
460 R=i2cw(A,#705,1,#706,4) | |
470 next | |
480 for B=2 to 4 | |
490 poke #705,#6+B*4,#0,#0,#0,#7 | |
500 R=i2cw(A,#705,1,#706,4) | |
510 next | |
520 wait(120) | |
530 next | |
' 以下コメントです。入力不要。 | |
' Adafruit PCA9685 12bitx16ch I2C PWM Driver でサーボ制御。 | |
' 変数説明: | |
' A: PCA9685のI2Cアドレス | |
' B: サーボch | |
' C: PWM幅設定値 | |
' D: PWM幅設定値の上位8bit | |
' E* PWM幅設定値の下位8bit | |
' プログラムブロック説明: | |
' 10 初期化、I2Cアドレス設定。 | |
' 20~120 PCA9685をPWM周波数60Hzで初期化。 | |
' 210~290 グー。 | |
' 300~430 チョキ。 | |
' 440~520 パー。 |