A Python-based GUI controller for DDSM210 hub motors, built for Waveshare DDSM Driver HAT (A) and ESP32. This project enables intuitive speed adjustment, direction control (forward/backward/left/right/stop), and advanced motor configuration via a user-friendly interface.
This controller communicates with ESP32 via HTTP/JSON (following Waveshare's official protocol) to control DDSM210 hub motors. It features differential reverse steering (left/right turns with 50% reverse differential speed) and built-in safety mechanisms like heartbeat timeout protection, making it ideal for mobile robots, smart cars, and other motor-driven projects. The project also supports lift control of 1610 lead screws via TCP/WiFi network switches.
- Speed Regulation: Slider-based speed control (0-210 RPM, matching DDSM210's no-load max speed) with real-time RPM ↔ CMD value display.
- Direction Control:
- Forward/Backward: Dual motors run at the same speed (forward/reverse).
- Left Turn: Right motor maintains set speed, left motor reverses at 50% of set speed.
- Right Turn: Left motor maintains set speed, right motor reverses at 50% of set speed.
- Stop: Instantly stop all motors.
- Advanced Configuration: View motor ID/info, switch motor working modes.
- Real-Time Logging: Record all command transmissions and responses for debugging.
- Safety Protection: 2-second heartbeat timeout (motors stop automatically if no commands received).
- Lead Screw Lift Control: TCP/WiFi network switch-based control for 57 stepper motor-driven 1610 lead screws (lift/lower, jog control, status query).
| Component | Specification |
|---|---|
| Main Controller | ESP32 (configured with Wi-Fi hotspot/ LAN access, default IP: 192.168.4.1) |
| Motor Driver | Waveshare DDSM Driver HAT (A) |
| Motor | DDSM210 Hub Motor (or compatible DDSM series like DDSM115) |
| Power Supply | DC power supply matching motor voltage/current requirements |
| Wiring | Left motor → ID 1, Right motor → ID 2 (match MOTOR_IDS in code) |
| Lead Screw Kit | (Optional) For lift control |
| Lead Screw | 1610 specification (0.03mm precision, 600mm stroke) |
| Stepper Motor | 57 stepper motor (drives lead screw) |
| Motor Driver | DM556-IO 57 self-pulse driver |
| Network Switch | 4-channel TCP (Ethernet + WiFi) network switch (fixed IP recommended) |
- Python Version: 3.10
- Required Libraries:
requests: For HTTP communication with ESP32tkinter: For GUI (built-in with Python, no extra installation needed)socket: For TCP communication with network switch (built-in)threading: For asynchronous data reception (built-in)
git clone https://github.com/your-username/ddsm210-motor-controller.git
cd ddsm210-motor-controllerpip install requests- Ensure motors are wired to the correct IDs (Left=1, Right=2) on the driver HAT.
- Confirm ESP32 is powered and connected to the same network as your PC.
- For lead screw: Connect 57 stepper motor to DM556-IO driver, wire driver's direction pin to network switch (NO terminal), ensure network switch is connected to the same router WiFi as PC.
python test5.pypython net_switch.py| Area | Function |
|---|---|
| Speed Adjustment | Use the slider to set target RPM (0-210). The label shows RPM and corresponding CMD value. |
| Direction Control | Click buttons for Forward/Backward/Left/Right/Stop to control motor movement. |
| Advanced Settings | Buttons to view motor ID, motor info, or switch motor working modes. |
| Log Area | Displays command logs (send/response/errors) for debugging. |
| Area | Function |
|---|---|
| Connection Settings | Enter network switch IP/port, click "Connect" to establish TCP connection. |
| Switch Control | 4 buttons for 4-channel switch control (toggle ON/OFF to drive lead screw lift/lower). |
| Operation | "Query Status" to check switch state; "Jog 1-4" for momentary control of each channel. |
| Data Display | Shows sent commands and received responses for debugging. |
- Adjust the speed slider to set your desired RPM.
- Click a direction button to control the motors.
- Check the log area to confirm command execution status.
- Enter network switch IP (default:
192.168.1.100) and port (default:8282). - Click "Connect" to establish TCP connection (status turns green if successful).
- Use switch buttons to control lead screw lift/lower (button text toggles between ON/OFF).
- Use "Query Status" to verify switch state, or "Jog" buttons for momentary control.
Modify the global variables in test5.py to adapt to your hardware/requirements:
# Network Configuration
ESP32_IP = "192.168.4.1" # ESP32 IP address (update if using LAN)
# Motor Configuration
MAX_RPM = 210 # Max RPM for DDSM210 (no-load)
DEFAULT_SPEED = 30 # Default startup speed (RPM)
CMD_PER_RPM = 10 # RPM to CMD mapping (1 RPM = 10 CMD)
MOTOR_IDS = [1, 2] # Motor ID mapping (Left=1, Right=2)
DEFAULT_ACT = 3 # Acceleration time (0.1ms unit)
MOTOR_TYPE = 210 # Motor model (210=DDSM210, 115=DDSM115)
# Safety Configuration
HEARTBEAT_TIME = 2000 # Heartbeat timeout (ms)
CMD_DELAY_MS = 5 # Delay between motor commands (ms)Modify default network switch parameters (if needed) in net_switch.py:
# Default network switch configuration (in create_widgets method)
self.ip_entry.insert(0, "192.168.1.100") # Update to your network switch IP
self.port_entry.insert(0, "8282") # Update to your network switch portThe controller sends JSON commands to ESP32 via HTTP (following Waveshare's official spec). Key commands:
| Command Type (T) | Function | Key Parameters | Example JSON |
|---|---|---|---|
| 10010 | Motor Speed Control | id (motor ID), cmd (speed cmd), act (acceleration) |
{"T":10010, "id":1, "cmd":300, "act":3} |
| 10031 | View Motor ID | - | {"T":10031} |
| 10032 | View Motor Info | id (motor ID) |
{"T":10032, "id":1} |
| 10012 | Switch Motor Mode | id (motor ID), mode (mode value) |
{"T":10012, "id":1, "mode":2} |
| 11001 | Set Heartbeat Timeout | time (timeout in ms) |
{"T":11001, "time":2000} |
| 11002 | Set Motor Type | type (210=DDSM210, 115=DDSM115) |
{"T":11002, "type":210} |
- Forward:
CMD = RPM × CMD_PER_RPM(e.g., 30 RPM → 300 CMD) - Reverse:
CMD = 100 + abs(RPM × CMD_PER_RPM)(e.g., -15 RPM → 100 + 150 = 250 CMD) - Stop:
CMD = 0
The controller sends ASCII commands to network switch via TCP. Key commands:
| Command | Function | Response (Switch State) |
|---|---|---|
aX |
Turn on X-th channel (X=1-4) | fX (X-th channel on) |
bX |
Turn off X-th channel (X=1-4) | nX (X-th channel off) |
qa |
Query all channels status | f1/f2/n3/f4 (mixed) |
cX |
Momentary control X-th channel (jog) | Corresponding fX/nX |
- Ensure your PC/controller is on the same network as ESP32 (Wi-Fi hotspot or LAN).
- Motor IDs must match wiring (Left=1, Right=2) — incorrect IDs cause reversed direction.
- Motors stop automatically after heartbeat timeout; re-send a command to reactivate.
- Avoid running motors at max RPM for extended periods (prevents overheating).
- Adjust the reverse CMD base value (
100) if using a non-standard driver HAT. - For lead screw: Use fixed IP for network switch to avoid connection issues; ensure driver direction pin is wired to switch's NO terminal.
- Do not disconnect network switch TCP connection abruptly — use "Disconnect" button to avoid port occupation.
- Switch ESP32 to AP+STA mode, connect to the same router WiFi as network switch/PC.
- Merge
test5.py(motor control) andnet_switch.py(lead screw control) into a single GUI program. - Unify control interface for both motor movement and lead screw lift/lower.
- Add interlock logic (e.g., stop motor movement when lead screw is in motion).
- Waveshare DDSM Driver HAT (A) Official Wiki
- DDSM210 Motor Datasheet
- ESP32 HTTP Server Documentation
- DM556-IO Stepper Driver Datasheet
This project is licensed under the MIT License — see the LICENSE file for details.
- Waveshare for open-sourcing the DDSM Driver HAT protocol documentation.
- The Python community for
tkinterandrequestslibraries.
一个基于Python的DDSM210轮毂电机GUI控制器,适用于Waveshare DDSM驱动板HAT (A)和ESP32。该项目通过用户友好的界面实现直观的速度调节、方向控制(前进/后退/左/右/停止)以及高级电机配置,同时支持基于TCP/WiFi网络开关的1610丝杆升降控制。
该控制器通过HTTP/JSON(遵循Waveshare官方协议)与ESP32通信,以控制DDSM210轮毂电机。它具备差动反向转向功能(左右转向时采用50%反向差速)和内置安全机制(如心跳超时保护),非常适合移动机器人、智能小车和其他电机驱动项目。同时集成了网络开关控制逻辑,可驱动57步进电机实现1610丝杆的精准升降。
- 速度调节:基于滑块的速度控制(0-210 RPM,匹配DDSM210的空载最大速度),并实时显示RPM与CMD值。
- 方向控制:
- 前进/后退:双电机以相同速度运行(正向/反向)。
- 左转:右电机保持设定速度,左电机以设定速度的50%反转。
- 右转:左电机保持设定速度,右电机以设定速度的50%反转。
- 停止:立即停止所有电机。
- 高级配置:查看电机ID/信息,切换电机工作模式。
- 实时日志:记录所有命令传输和响应,便于调试。
- 安全保护:2秒心跳超时(若未收到命令,电机自动停止)。
- 丝杆升降控制:基于TCP/WiFi网络开关的57步进电机控制,支持丝杆升降、点动操作、状态查询。
| 组件 | 规格说明 |
|---|---|
| 主控制器 | ESP32(已配置Wi-Fi热点/局域网接入,默认IP:192.168.4.1) |
| 电机驱动板 | Waveshare DDSM Driver HAT (A) |
| 电机 | DDSM210轮毂电机(或兼容的DDSM系列,如DDSM115) |
| 电源 | 符合电机电压/电流要求的直流电源 |
| 接线 | 左电机→ID 1,右电机→ID 2(与代码中的MOTOR_IDS匹配) |
| 丝杆套件 | (可选)用于升降控制 |
| 丝杆 | 1610规格(精度0.03mm,行程600mm,水平负载≤45kg,垂直负载≤35kg) |
| 步进电机 | 57步进电机(驱动丝杆) |
| 电机驱动器 | DM556-IO 57自发脉冲驱动器 |
| 网络开关 | 4路TCP(网口+WiFi)网络开关(建议配置固定IP) |
- Python版本:3.10
- 所需库:
requests:用于与ESP32进行HTTP通信tkinter:用于图形用户界面(Python内置,无需额外安装)socket:用于与网络开关进行TCP通信(Python内置)threading:用于异步接收网络开关数据(Python内置)
git clone https://github.com/your-username/ddsm210-motor-controller.git
cd ddsm210-motor-controllerpip install requests- 确保电机正确连接到驱动板上的对应ID(左=1,右=2)。
- 确认ESP32已通电且与电脑连接到同一网络。
- 丝杆部分:57步进电机连接至DM556-IO驱动器,驱动器方向接口接网络开关常开端,网络开关接入路由器WiFi并与电脑同网段。
python test5.pypython net_switch.py| 区域 | 功能 |
|---|---|
| 速度调节 | 使用滑块设置目标RPM(0-210)。标签显示RPM及对应的CMD值。 |
| 方向控制 | 点击前进/后退/左/右/停止按钮控制电机运动。 |
| 高级设置 | 用于查看电机ID、电机信息或切换电机工作模式的按钮。 |
| 日志区域 | 显示命令日志(发送/响应/错误),便于调试。 |
| 区域 | 功能 |
|---|---|
| 连接设置 | 输入网络开关IP/端口,点击“连接”建立TCP连接。 |
| 开关控制 | 4个按钮对应4路开关控制(切换开/关状态,驱动丝杆升降)。 |
| 操作区 | “查询状态”按钮获取开关当前状态;“点动1-4”按钮实现对应通道点动控制。 |
| 数据显示 | 显示发送的指令和接收的响应数据,便于调试。 |
- 调节速度滑块设置所需RPM。
- 点击方向按钮控制电机。
- 在日志区域查看命令执行状态。
- 输入网络开关IP(默认:
192.168.1.100)和端口(默认:8282)。 - 点击“连接”按钮建立TCP连接(状态变为绿色表示连接成功)。
- 点击开关按钮控制丝杆升降(按钮文字在“开/关”间切换)。
- 可点击“查询状态”验证开关当前状态,或通过“点动”按钮实现丝杆点动控制。
修改test5.py中的全局变量以适应硬件/需求:
# 网络配置
ESP32_IP = "192.168.4.1" # ESP32的IP地址(使用局域网时请更新)
# 电机配置
MAX_RPM = 210 # DDSM210的最大RPM(空载)
DEFAULT_SPEED = 30 # 默认启动速度(RPM)
CMD_PER_RPM = 10 # RPM到CMD的映射(1 RPM = 10 CMD)
MOTOR_IDS = [1, 2] # 电机ID映射(左=1,右=2)
DEFAULT_ACT = 3 # 加速时间(单位:0.1ms)
MOTOR_TYPE = 210 # 电机型号(210=DDSM210,115=DDSM115)
# 安全配置
HEARTBEAT_TIME = 2000 # 心跳超时时间(ms)
CMD_DELAY_MS = 5 # 电机命令之间的延迟(ms)如需修改网络开关默认参数,调整net_switch.py中以下代码:
# 默认网络开关配置(在create_widgets方法中)
self.ip_entry.insert(0, "192.168.1.100") # 改为你的网络开关实际IP
self.port_entry.insert(0, "8282") # 改为你的网络开关实际端口控制器通过HTTP向ESP32发送JSON命令(遵循Waveshare官方规范)。主要命令:
| 命令类型(T) | 功能 | 关键参数 | 示例JSON |
|---|---|---|---|
| 10010 | 电机速度控制 | id(电机ID)、cmd(速度指令)、act(加速度) |
{"T":10010, "id":1, "cmd":300, "act":3} |
| 10031 | 查看电机ID | - | {"T":10031} |
| 10032 | 查看电机信息 | id(电机ID) |
{"T":10032, "id":1} |
| 10012 | 切换电机模式 | id(电机ID)、mode(模式值) |
{"T":10012, "id":1, "mode":2} |
| 11001 | 设置心跳超时 | time(超时时间,单位ms) |
{"T":11001, "time":2000} |
| 11002 | 设置电机类型 | type(210=DDSM210,115=DDSM115) |
{"T":11002, "type":210} |
- 前进:
CMD = RPM × CMD_PER_RPM(例如:30 RPM → 300 CMD) - 反转:
CMD = 100 + abs(RPM × CMD_PER_RPM)(例如:-15 RPM → 100 + 150 = 250 CMD) - 停止:
CMD = 0
控制器通过TCP向网络开关发送ASCII指令,核心指令如下:
| 指令 | 功能 | 响应(开关状态) |
|---|---|---|
aX |
打开第X路开关(X=1-4) | fX(第X路已开) |
bX |
关闭第X路开关(X=1-4) | nX(第X路已关) |
qa |
查询所有开关通道状态 | 如f1/f2/n3/f4(混合状态) |
cX |
点动控制第X路开关 | 对应fX/nX响应 |
- 确保电脑/控制器与ESP32处于同一网络(Wi-Fi热点或局域网)。
- 电机ID必须与接线匹配(左=1,右=2)——ID错误会导致方向反转。
- 心跳超时后电机自动停止;重新发送命令即可重新激活。
- 避免长时间以最大RPM运行电机(防止过热)。
- 若使用非标准驱动板,可调整反转CMD基准值(
100)。 - 丝杆控制注意:网络开关建议配置固定IP,避免连接失效;驱动器方向引脚需接开关常开端。
- 请勿强制断开网络开关TCP连接,需点击“断开”按钮,避免端口占用。
- 将ESP32切换为AP+STA模式,接入与网络开关/电脑相同的路由器WiFi。
- 将
test5.py(电机控制)与net_switch.py(丝杆控制)合并为单一GUI程序。 - 统一电机运动和丝杆升降的控制界面。
- 增加互锁逻辑(如丝杆运动时禁止电机移动)。
本项目基于MIT许可证授权——详见LICENSE文件。
- 感谢Waveshare开源DDSM驱动板协议文档。
- 感谢Python社区提供的
tkinter和requests库。