Raspberry Pi PicoはArduinoでarduino-picoボードマネージャーを使って動かしています。

今回,Picoで初めてサーボライブラリを使ってみましたが,サーボのパルス幅のデフォルト値が標準の値ではなく,サーボの動きが小さい事が分かりました。

Seeeduino XIAOのプログラムなどと互換をとりたいので,標準値に設定しました。


githubのarduino-picoのServo.hライブラリには以下のコメントがあります。
 安全のために動きを小さくしているようです。
attach(pin, min, max)
Attaches to a pin setting min and max values in microseconds
default min is 1000, max is 2000

ArduinoのServoライブラリの解説によると標準値は以下になっています。
min (optional): the pulse width, in microseconds, corresponding to the minimum (0 degree) angle on the servo (defaults to 544)
max (optional): the pulse width, in microseconds, corresponding to the maximum (180 degree) angle on the servo (defaults to 2400)

という事で,arduino-picoのデフォルトは使わず
 attach(pin, 544, 2400);
という設定にして無事同じ動作になりました(^^)。



サーボはSeeeduino XIAOで動く「モグラたたき」のプロトタイプで3台まで使っていましたが,ぼちぼちとモグラの数を増やしています。




次はPin数の多いPicoを使おうと思っていて,追加したモグラを1台ずつPicoでチェックしてみたのですが,その際に動きが違ってデフォルトの違いに気がつきました(^^;;;;;





上記のパルス幅の変更をして使っている,サーボとヒットセンサーのチェックプログラムです。

// Pico test1, Servo Pin6, switch Pin14, LED Pin13

#include <servo.h>
Servo myservo1;

const int L_Pos=65; // stop positions
const int M_Pos=95;
const int H_Pos=125;

void setup() {
myservo1.attach(6,544,2400); // Init. servo
myservo1.write(90);

pinMode(13, OUTPUT); // LED for check the switch
}

void loop() {
digitalWrite(13, LOW); // LED off

myservo1.write(L_Pos); // move to low position
delay(1000); // wait for 1000 ms

myservo1.write(M_Pos); // move to middle position
delay(500);

byte hit=0;
unsigned long h_time=1000;
unsigned long s_time=millis();

myservo1.write(H_Pos); // move to high position
while(millis()-s_time < h_time){
if (digitalRead(14) == 1){ // hit?
hit=1;
digitalWrite(13, HIGH); // turn the LED on
}
}
}





ちなみにarduino-picoのサーボライブラリで扱えるサーボ数は最大8台までです。動作にPIO(prgrammable input / output)を使っている関係だそうです。


う〜む,飽き性だからでしょうね。
同じものをいくつも作るのが得意じゃない事もあって,モグラ作りの作業が遅々として進みません(^^;;;;;;;;

ま,趣味なので無理しないでぼちぼちとやっていきましょう。