Unofficial port of the Basicmicro Arduino Library for ESP-IDF.
This is unofficial - not made by or endorsed by BasicMicro!
ForwardM1(),BackwardM1(),ForwardM2(),BackwardM2()— basic speed controlDutyM1(),DutyM2(),DutyM1M2()— direct PWM duty cycle (-32767 to +32767)DutyAccelM1(),DutyAccelM2(),DutyAccelM1M2()— duty cycle with hardware acceleration rampSpeedM1(),SpeedM2()— encoder-based speed controlSpeedAccelM1(),SpeedAccelM2()— speed with accelerationForwardMixed(),BackwardMixed(),TurnRightMixed(),TurnLeftMixed()— mixed modeStopM1(),StopM2(),StopAll()— stop helpers
ReadEncM1(),ReadEncM2()— read encoder countsReadSpeedM1(),ReadSpeedM2()— read encoder speedsResetEncoders()— reset encoder counts to zero
ReadVersion()— firmware version stringReadError()— 32-bit error/warning status with detailed flagsGetStatus()— comprehensive status in one call (voltages, temps, currents, encoders, speeds, errors)ReadMainBatteryVoltage(),ReadLogicBatteryVoltage()— battery voltagesReadTemp(),ReadTemp2()— board temperaturesReadCurrents()— motor currentsReadBuffers()— command buffer depthsReadPWMs()— current PWM output values
SetTimeout(),GetTimeout()— communication timeout (auto-stop if no commands received)SetMainVoltages(),ReadMinMaxMainVoltages()— main battery voltage limitsSetLogicVoltages(),ReadMinMaxLogicVoltages()— logic battery voltage limitsSetM1MaxCurrent(),SetM2MaxCurrent()— per-motor current limitsReadM1MaxCurrent(),ReadM2MaxCurrent()— read current limitsWriteNVM()— save settings to flashReadNVM()— reload settings from flashRestoreDefaults()— factory reset
roboclaw_enable_thread_safety()— opt-in UART mutex for multi-task access (zero overhead if not enabled)
Default pins:
- TX: GPIO 17 → RoboClaw S1 (RX)
- RX: GPIO 16 ← RoboClaw S2 (TX)
- Don't forget GND!
Default baud rate: 38400
Multiple RoboClaws can share the same TX/RX pins using different addresses (0x80, 0x81, etc.).
#include "roboclaw.h"
#include "roboclaw_uart.h"
#define ROBOCLAW_ADDRESS 0x80
void app_main(void) {
begin(38400);
// Optional: enable thread safety if using multiple FreeRTOS tasks
// roboclaw_enable_thread_safety();
char version[64];
if (ReadVersion(ROBOCLAW_ADDRESS, version)) {
printf("Version: %s\n", version);
}
// Set duty with acceleration ramp
DutyAccelM1M2(ROBOCLAW_ADDRESS, 16000, 5000, 16000, 5000);
vTaskDelay(pdMS_TO_TICKS(2000));
// Stop
DutyM1M2(ROBOCLAW_ADDRESS, 0, 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 38400Based on BasicMicro's official Arduino library.
- ESP-IDF 5.0+
- ESP32, ESP32-S2, ESP32-S3, ESP32-C3
- Any RoboClaw with packet serial communication
For RoboClaw hardware problems: contact BasicMicro For this ESP-IDF port: open an issue here