1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ふたたび)M5NanoC6、SG-90(RCサーボ)で旗を振って遊ぶ。(3.1.2)

Last updated at Posted at 2025-02-25

注意、いろいろ

  • 前回との違いは、ESP32のバージョンが3.1.2になったから

  • 自己責任の意味がわかる人

  • 過去ログを見よ!!!

  • ESP32 Arduino 3.1.2

  • あまり正確では、ない

  • 10ビット(1024)の固定小数点の処理をしている

  • おどしでも、冗談でもなく、サーボ系は、一発で終わるので、ちょとめんどい。(悪い意味)

  • サーボをパソコンに繋いだままやるとパソコンが破壊されます。

  • モーター、コイル等、逆起電力で高電圧が発生する時の安全対策は、各自実行してください。

  • 最低でも、試す時は、モバイルバッテリを使用してください。

  • モータ系の力学装置系をなぜ、あまりやらないのかは、まず、物理的にお金がかかる、いろいろ、危険であるから

目的

無線でラジコンサーボ SG90を制御する(予定)

結果

image_original (47).jpg

image_original (48).jpg

プログラム


//servo_sg90_test3_M5NanoC6_1
//ESP32 Arduino 3.1.2


//インクルド
#include <Arduino.h>


//定義
//使い方 SOのマクロに0から180を設定すると
//PWMの間隔の値が返る
// a = SO(i);
// //a = SO(180-i);
//V_0が0度の時の初期値で単位は、nS(ナノ秒)
//V_180が180度の時の初期値で単位は、nS(ナノ秒)
//SO(角度) 正転
//M_SO(角度) 逆転
#define V_0    500
#define V_180 2400
#define Wavelength_1count (((1000000/50)*1024)/4096)
#define T_MIN ((V_0*1024)/Wavelength_1count)
#define T_MAX ((V_180*1024)/Wavelength_1count)
#define HH  ((T_MAX-T_MIN)*1024)/180
#define SO(AA) (T_MIN+(((AA)*(HH))>>10))
#define M_SO(AA) (SO(180-(AA)))

//PWMのポート、周期、分解度のビット数
#define PWM_PIN 2
#define FREQUENCY 50
#define RESOLUTION 12


void setup() {
  // put your setup code here, to run once:

  //出力ピンの初期化
  pinMode(PWM_PIN, OUTPUT);

  // PWM設定(ピン番号, 周波数, 分解能)
  ledcAttach(PWM_PIN, FREQUENCY, RESOLUTION);

}//setup


void loop() {
  // put your main code here, to run repeatedly:

  // DUTY比を指定して、ポートに対して実行 0°
  ledcWrite(PWM_PIN, M_SO(0));
  delay(2000); //2秒待つ

  // DUTY比を指定して、ポートに対して実行 180°
  ledcWrite(PWM_PIN, M_SO(180));
  delay(2000); //2秒待つ

}//loop

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?