RL78 G23 128p FPB サーボモータ (Arduino™ スケッチ) - renesas/Arduino GitHub Wiki

はじめに

  • 本ページではサーボモータを0度から180度まで往復運動させる方法について記載します
  • Arduino IDEやArduinoライブラリのインストール方法、スケッチをボードに書き込む方法などの基本情報はクイックスタートガイドをご覧ください

動作環境と使用製品

このページでは以下の環境と製品を使用しています

ハードウェア

ソフトウェア

  • Arduino IDE 2.3.6
  • RL78/G23-128p FPB Arduino Library v1.2.0

ピン接続

  • SG-90とRL78/G23-128p FPBのピンを以下のように接続します
SG-90ピン 接続先のRL78/G23-128p FPBピン
SIG (橙) 9
+V (赤) 5V
GND (茶) GND

connection

サンプルスケッチ選択

  • Arduino IDEを開き、「ファイル」→「スケッチ例」→「Servo」→「Sweep」を選択します

コンパイル・書き込み・動作確認

  • コンパイルと書き込みを行います

    • Arduino IDE上で「書き込み」を選択すると、コンパイルと書き込みが開始されます
  • 以下のようにサーボモータが0度から180度まで往復運動していれば正しく動作しています default_servo_c

サンプルスケッチの変更例

サーボモータの指示角を変更

  • 角度の設定は「myservo.write(角度[deg]);」で行います
  • スケッチの下記部分を変更することで指示角を20度に設定できます
    24-33行目
    -  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
    -    {                                  // in steps of 1 degree 
    -      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    -      delay(15);                       // waits 15ms for the servo to reach the position 
    -    } 
    -    for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
    -    {                                
    -      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    -      delay(15);                       // waits 15ms for the servo to reach the position 
    -    } 
    
    +  myservo.write(20);
    
    • 実際の動作
      20deg

SG-90のSIGピンを2番ピンに変更

  • 接続するピン番号を変更するときは、19行目にある「myservo.attach(9);」の「9」の部分を接続したピン番号に変更します。

  • SIGピンの接続には次のピンが利用できます。(ピンリストはこちら)

  • サーボモータに対応しているピン
    0-19, 23, 25-29, 31-56, 58, 59, 62-71, 74-89, 92-118
  • 以下はSIGピンを9番ピンから2番ピンに変更する例です

    • ピン接続を以下に変更してください

      SG-90ピン 接続先のRL78/G23-128p FPBピン
      SIG (橙) 2
      +V (赤) 5V
      GND (茶) GND
  • スケッチの下記部分を変更することでSIGピンを2番ピンに設定できます

    19行目
    -  myservo.attach(9);
    +  myservo.attach(2);