Tutorial II: Motor Without Encoder Control Demo

From Waveshare Wiki
Revision as of 07:27, 1 September 2023 by Waveshare-admin (talk | contribs) (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Modules Usage Tutorial

Motor Without Encoder

As the motor without an encoder can not get the speed feedback, it only supports open-loop control. The motor without encoder control demo is provided as follows.


Upload Demo

After downloading the zip file, double-click it to open nospeedget.ino, connect the multifunctional driver board to the computer with a USB cable (here the Type-C port of the USB of the multifunctional driver board is inserted), click "Tools" -> "Ports", and then click the newly appeared COM port.
UGV1 doenload03EN.png
In Arduino IDE, click "Tools" → "Development Board" → "ESP32" → "ESP32 Dev Module". Upload the demo after selecting the board and the port. After uploading the demo, connect the encoderless motor to the motor interface PH2.0 2P on the driver board, connect the XH2.54 power supply interface to the power supply, and run the demo, and you can see the motor start to rotate.

Demo Analysis

const uint16_t PWMA = 25;         
const uint16_t AIN2 = 17;        
const uint16_t AIN1 = 21;         
const uint16_t BIN1 = 22;       
const uint16_t BIN2 = 23;        
const uint16_t PWMB = 26;   

const uint16_t ANALOG_WRITE_BITS = 8;

int freq = 100000;
int channel_A = 0;
int channel_B = 1;
int resolution = ANALOG_WRITE_BITS;

void initMotors(){
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  pinMode(PWMB, OUTPUT);

  ledcSetup(channel_A, freq, resolution);
  ledcAttachPin(PWMA, channel_A);

  ledcSetup(channel_B, freq, resolution);
  ledcAttachPin(PWMB, channel_B);


void forwardA(uint16_t pwm){
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, HIGH);
  ledcWrite(channel_A, pwm);

void forwardB(uint16_t pwm){
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, HIGH);
  ledcWrite(channel_B, pwm);

void setup() {

void loop() {