Tutorial II: Motor Without Encoder Control Demo
Modules Usage Tutorial
- How To Install Arduino IDE
- Tutorial I: Motor With Encoder Control Demo
- Tutorial II: Motor Without Encoder Control Demo
- Tutorial III: ST3215 Serial Bus Servo Control Demo
- Tutorial IV: PWM Servo Control Demo
- Tutorial V: IMU Data Reading Demo
- Tutorial VI: SD Card Reading Demo
- Tutorial VII: INA219 Voltage And Current Monitoring Demo
- Tutorial VIII: OLED Screen Control Demo
- Tutorial IX Lidar and Publishing Lidar Topics in ROS2
- UGV01 WIKI Main Page
- General Driver for Robots WIKI Main Page
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.
Demo
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.
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() { initMotors(); } void loop() { forwardA(400); forwardB(400); }