DocBrownのブログ -3ページ目

DocBrownのブログ

電子工作等々。。。

Arduinoでブラシレスモーターを回してみました。

 

使用マイコン 

Adafruit HUZZAH32 - ESP32 Feather Board 千石にて購入

ブラシレスモーターとESC A2212/13T,VW-1H Amazonにて購入

ESCに入力した電圧 10V

 

ピンはA0を使用

 

ポイントはキャリブレーションを正しくするとちゃんと回ります。

 

プログラム

その1 パルスを自作

//  brushless motor
// motor : A2212/13T
// ESC VW-1H(020)
int motorPin0 = 26; //A0
 

void setup() {
  Serial.begin(115200);  
  pinMode(motorPin0,OUTPUT); 
  for (int i=0; i <= 100; i++){
    digitalWrite(motorPin0, HIGH); 
    delayMicroseconds(2000);
    digitalWrite(motorPin0, LOW); 
    delay(20);
   }
  delay(2000);
for (int j=0; j <= 100; j++){
    digitalWrite(motorPin0, HIGH); 
    delayMicroseconds(1000);
    digitalWrite(motorPin0, LOW); 
    delay(20);
  }
  delay(2000);
}
void loop(){
    digitalWrite(motorPin0, HIGH); 
    delayMicroseconds(2000);
    digitalWrite(motorPin0, LOW); 
    delay(20);
}

 

その2 パルスはLEDC_CHANNELを使用

//  brushless motor
// motor : A2212/13T
// ESC VW-1H(020)

#define LEDC_CHANNEL_0 0
#define LEDC_TIMER_BIT 10
#define LEDC_BASE_FREQ 50 //50Hz 0.02s  20ms
#define SRV_PIN 26

int min0 = 51; // (51/1024)*20ms = 1 ms (-90deg)
int max0 = 102; // (102/1024)*20ms = 2.4 ms (+90deg)

void setup() {
  Serial.begin(115200);  
  ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
  ledcAttachPin(SRV_PIN, LEDC_CHANNEL_0);
  
  ledcWrite(0, max0);
  delay(2000);
  ledcWrite(0, min0);
  delay(2000);
}
 

void loop(){
  ledcWrite(0, max0);
}