Unofficial port of the RoboClaw Arduino Library for ESP-IDF.
I needed to use a RoboClaw motor controller in my ESP-IDF project, but the existing library is for Arduino. So I ported it to work with ESP-IDF.
- Motor control:
ForwardM1(),BackwardM1(),SpeedM1(), etc. - Reading encoders:
ReadEncM1(),ReadEncM2() - Reading speeds:
ReadSpeedM1(),ReadSpeedM2() - Battery voltage:
ReadMainBatteryVoltage(),ReadLogicBatteryVoltage() - Version info:
ReadVersion() - Reset encoders:
ResetEncoders()
Default pins:
- TX: GPIO 17 → RoboClaw S1 (RX)
- RX: GPIO 16 ← RoboClaw S2 (TX)
- Don't forget GND!
Default baud rate: 38400
#include "roboclaw.h"
#include "roboclaw_uart.h"
#define ROBOCLAW_ADDRESS 0x80
void app_main(void) {
// Start UART
begin(38400);
// Read version
char version[64];
if (ReadVersion(ROBOCLAW_ADDRESS, version)) {
printf("Version: %s\n", version);
}
// Move motor forward at 50% speed
ForwardM1(ROBOCLAW_ADDRESS, 64);
vTaskDelay(pdMS_TO_TICKS(1000));
// Stop
ForwardM1(ROBOCLAW_ADDRESS, 0);
}- Copy the
components/roboclaw/folder to your ESP-IDF project - Include the headers in your code
- Build with
idf.py build
Want different pins? Edit roboclaw_uart.c:
#define TXD_PIN 17 // Your TX pin
#define RXD_PIN 16 // Your RX pinWant different baud rate? Just change it:
begin(115200); // Instead of 38400- Uses ESP-IDF UART instead of Arduino Serial
- Simpler communication (no complex retries)
- Works with FreeRTOS
- Only includes the functions I actually needed
Based on BasicMicro's official Arduino library.
- ESP-IDF 5.0+
- ESP32, ESP32-S2, ESP32-S3, ESP32-C3
- Any RoboClaw with serial communication
For RoboClaw hardware problems: contact BasicMicro
For this ESP-IDF port: open an issue here
Note: This is just my personal port. For official ESP32 support, ask BasicMicro.