ESP32MX1508
MX1508 Motor Driver Arduino Library for the ESP32
Install / Use
/learn @ElectroMagus/ESP32MX1508README
MX1508 Driver Board Library for ESP32/Arduino
Arduino library for MX1508 dual DC motor driver compatible with the ESP32.
This was inspired by this AVR Library.
The MX1508 Motor Driver is a nice, low cost motor driver works from 2-10VDC, with a 1.5A operating current (2A peak). The driver is ideal for battery powered, smaller DC motors.
The ESP32 to use the LEDC Driver to send the PWM signals for speed control. The ESP32 can multiplex many of its pin functions, this library creates PWM Channels and assigns them to the pins specified.
The LEDC driver supports 8, 12 and 16 bit PWM resolution and can operate at a variety of frequencies allowing you to tune the driver to your particular motor.
Objective
This library is made to simplify the use of MX1508 by allowing for the simple setup of motors and then using functions to drive them.
#include <ESP32MX1508.h>
#define PINA 9
#define PINB 10
#define CH1 0 // 16 Channels (0-15) are availible
#define CH2 1 // Make sure each pin is a different channel and not in use by other PWM devices (servos, LED's, etc)
// Optional Parameters
#define RES 8 // Resolution in bits: 8 (0-255), 12 (0-4095), or 16 (0-65535)
#define FREQ 5000 // PWM Frequency in Hz
MX1508 motorA(PINA,PINB, CH1, CH2); // Default- 8 bit resoluion at 2500 Hz
//MX1508 motorA(PINA,PINB, CH1, CH2, RES); // Specify resolution
//MX1508 motorA(PINA,PINB, CH1, CH2, RES, FREQ); // Specify resolution and frequency
void setup() {
Serial.begin(9600);
}
void loop() {
motorA.motorGo(200); // Pass the speed to the motor: 0-255 for 8 bit resolution
delay(100);
motorA.motorStop(); // Soft Stop -no argument
delay(100);
motorA.motorRev(200); // Pass the speed to the motor: 0-255 for 8 bit resolution
delay(100);
MotorA.motorBrake(); // Hard Stop -no arguement
}
Methods and Functions
-
motorGo(pwmVal)
- This sets the PWM val which is related to the speed, depending on selected resolution
-
motorRev(pwmVal)
- This sets the PWM val which is related to the speed, depending on selected resolution
-
motorStop()
- Stops the motor from moving in the current direction
-
motorBrake()
- Actively brakes the motor
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
