Tutorial IV: PWM Servo Control Demo

From Waveshare Wiki
Jump to: navigation, search

Modules Usage Tutorial

PWM Servo Control

The General Driver for Robots board has a module for sending PWM signals. The PWM servo can receive the PWM signal by connecting the IO port on the board, so as to control the PWM servo by the driver board. The following provides a simple rotation demo for the PWM servo.

Demo

Upload Demo

After downloading the dependency library ESP32Servo, unzip the downloaded file into the folder with path C:\Users\Username\AppData\Local\Arduino15\libraries.
PWM Servo Control Demore.png
After downloading the zip file, open pwmServo.ino, connect the multifunction driver board to the computer with a USB cable (the USB Type-C port of the multifunction driver board is inserted here), click "Tools" → "Ports", and then click "COM". Click on the newly appeared COM.
UGV1 doenload03EN.png
In Arduino IDE, click "Tools" → "Development Board" → "ESP32" → "ESP32 Dev Module". Upload the demo after selecting the board and port. After uploading the demo, connect the PWM servo and PWM signal servo interface, connect the XH2.54 power supply interface to the power supply, and run the demo, you can see the PWM servo will swing back and forth.

Demo Analysis

#include <Servo.h>
Servo pwmServo;

#define PSERVO_PIN 4

int pwmServoChannel = 7;
int pwmServoInitPos = 90;


void pwmServoInit(){
  pwmServo.attach(PSERVO_PIN);
}

void setup() {
  pwmServoInit();
}

void loop() {
  pwmServo.write(50);
  delay(1000);
  pwmServo.write(90);
  delay(1000);
}

Resource