• sales

    +86-0755-88291180

DDSM Driver HAT (B) User Guide

Overview

This is a driver board for the DDSM400 direct drive servo hub motor, with 6 DDSM400 motor interfaces on board, integrating ESP32 and hub motor control circuits. We have open source hub motor control demos and JSON communication interface, users can use the host computer to send JSON format instructions to control the hub motor through USB connection, and get JSON format feedback (motor current, speed, temperature and other information).

Users can also redevelop it and use it as a lower computer for robot projects.


Features

  • Used to drive DDSM400 hub motors, with 6-channel DDSM400 motor interfaces on board
  • Easy-to-use DDSM400 hub motor control demo and SDK
  • Supports multiple wired and wireless communication methods, supports JSON command interaction, convenient for host computer control
  • Supports connecting to Raspberry Pi, powering the Pi via integrated 5V buck regulator circuit and communicating through GPIO UART interface, neat cable management
  • Integrated WEB application for controlling and setting DDSM400 hub motor, convenient for debugging
  • Direct communication with DDSM400 hub motors via Type-C interface

    Onboard Resources

    DDSM Driver HAT (B) resources.jpg

    Precautions

    1. Due to the special structure of the hub motor, it can not be placed directly on the desktop to let it rotate, it is best to fix the shaft of the hub motor, if you do not have the corresponding structural parts to install the hub motor, you can set the heartbeat function to make the hub motor automatically stop rotating, the specific method will be introduced later; It is also possible to install the hub motor using our suspension structure UGV Suspension (A) or UGV Suspension (B), Specifically, select the corresponding structural parts according to your hub motor model.
      550px-DDSM Model selection.jpg
    2. There are currently three hub motors, DDSM115, DDSM210 and DDSM400. Hub motors of different models cannot be mixed at the same time, because the control commands and feedback information are different. Do not connect the motor and the driver board until you set the ID for the motor.

    Basic Usage

    Power Preparation

    Prepare the power supply of the DDSM Driver HAT (B) board, which can be powered by one of the two power supply interfaces of DC5525 or XT60.

    The DDSM Driver HAT (B) driver board supports 9~28V DC power supply, and the driver board is suitable for the DDSM400 hub motor with an operating voltage range of 9~28V and a rated voltage of 25.2V.

    The current of the power supply should be chosen based on the hub motor's operational requirements. The larger the supported current, the better. In our use tests, a 24V 6A power supply can be used in most scenarios.


    ESP32 Usage Control

    The DDSM Driver HAT (B) driver board comes with the hub motor control demo by default at the factory, ensuring that the "UART Control Switch" is in the ESP32 position (as shown below), and the hub motor can receive control commands from the ESP32 at this time. The driver board is powered by two power supply interfaces, DC5525 or XT60, and the ESP32 on the driver board will automatically turn on and establish a hot spot for users to connect at the same time.

    • The default name of the hotspot established by ESP32 is ESP32-AP, and the default password is 12345678. You can use your mobile phone, tablet or PC to connect to this hotspot, then open a browser and enter 192.168.4.1 in the address bar to access the hub motor Web control application.
    • Web control application has a JSON command input box. Below is a JSON command example. You can click on the "INPUT" next to the JSON command example to automatically fill the corresponding JSON command into the input box, then modify the value of the command in the input box, and after modifying, click "SEND" to send the command to the ESP32.


    Set Motor ID

    Each hub motor has a default ID of 1 at the factory, so you need to set the ID for each hub motor before performing hub motor control.

    1. Connect the hub motor that needs to set an ID with the driver board. Note: Only one hub motor can be connected to the driver board. If more than one hub motor is connected, all hub motors connected to the driver board will be set to the same new ID.
    2. Power the driver board via the DC5525 or XT60 power interfaces. Connect a phone, tablet, or PC to the hotspot of the ESP32-AP (password: 12345678). Open a web browser and visit 192.168.4.1 to access the hub motor Web control application.
    3. Click "INPUT" next to the CMD_DDSM_CHANGE_ID command in DDSM CTRL, and you can see that the JSON command in the upper input box showing the motor ID is: {"T":10011,"id":1}, where:
      • T: The command type for setting the motor ID is 10011. Different command operations have own corresponding command types. These are fixed values and cannot be modified.
      • id: Changed to the ID value of the hub motor that needs to be set, which is 1~253. The newly set ID supports power-off saving.

    If you forget the ID set for the hub motor before, or need to check whether the ID setting is successful, you can query the hub motor ID by sending CMD_DDSM_ID_CHECK command in DDSM CTRL. The feedback is as follows:

    {"T":20010,"id":6,"typ":210,"spd":-1,"crt":-2,"act":1,"tep":40,"err":0}
    


    Motor Enabling

    After powering on the motor, it defaults to a disabled state, so enabling the motor is required before controlling it in current loop, speed loop, or position loop modes.

    Click "INPUT" next to the CMD_CHANGE_Enable command in DDSM CTRL, and you can see that the JSON command in the upper input box showing the motor enabled is: {"T":11002,"id":1}, where:

    • T: The command type for the motor to enable is 11002. Different command operations have own corresponding command types. These are fixed values and cannot be modified.
    • id: Changed to the ID that needs to enable the motor.


    Motor Mode Switching

    The Hub motor supports different motor mode switching, but the hub motor after re-powering is in the disabled mode by default. When the motor is enabled, it defaults to current loop mode.

    You can use the CMD_CHANGE_MODE command to switch the mode loop, and you can see that the JSON command is displayed as: {"T":10012,"id":1,"mode":2}, where:

    • T: The command type for motor mode switching is 10012. These are fixed values and cannot be modified.
    • id: The ID of the motor mode that needs to be switched.
    • mode: The value corresponding to motor mode. The details are as follows:
      • 0: Open loop, similar to PWM control of a DC motor (just as the motor will not turn when this value is too low and needs to reach a certain threshold to start turning), the absolute value of cmd is larger, the acceleration is greater, and the range of cmd values is -32767 ~ 32767.
      • 1: Current loop, the closed loop controls the current level, the larger the absolute value of the cmd value of CMD_DDSM_CTRL (hereinafter referred to as the cmd value, because no matter what mode loop, it is controlled by the JSON command CMD_DDSM_CTRL), the greater the acceleration, the value range of cmd value is -32767 ~ 32767, corresponding to -8A~8A, but DDSM400 only supports a maximum of 1.0 A.
      • 2: Speed loop, the closed loop controls the speed level, and the value range of the cmd value is determined according to the limit speed of the motor, the limit speed of the motor depends on the power supply capacity and the load of the motor, the larger the load, the smaller the limit speed that can be reached. The DDSM400 can reach 400rpm without load.
      • 3: Position loop, when the motor switches to position loop, the speed cannot be too fast. It is best to switch to position loop when the motor is stationary. The position when switching to position loop is the position where the cmd value is 0. However, if a motor that is already in position loop receives a command to switch to position loop again, position 0 will not be updated. The range of cmd values in position loop is 0 ~ 32767 (0 ~ 360°), with values increasing for clockwise rotation, and the motor will automatically plan the shortest path to move to the target position. For example, if the motor is currently at position 0 but you need it to rotate counterclockwise to a certain position, the cmd value should be greater than 32767/2 because the counterclockwise path to the target position is shorter.


    Closed-loop speed control

    Set Heartbeat Function

    Before controlling the rotation of the hub motor, you need to fix the hub motor shaft. If you currently do not have the corresponding structural components to fix the motor shaft, you can set a heartbeat function to automatically stop the hub motor from rotating (in the default speed loop mode).

    • Click "INPUT" next to the CMD_HEARTBEAT_TIME command, and you can see that the JSON command for setting the heartbeat function in the input box at the top of the web interface is: {"T":11001,"time":2000}, where:
      • T: Set the command type for the heartbeat function to 11001. These are fixed values and cannot be modified.
      • time: Time, in ms. When the time value is -1, the heartbeat function is disabled; when the time value is 2000, if no new command is received within 2 seconds after sending the motion control command, the driver board will automatically control the hub motor to stop rotating, so as to prevent the hub motor from rotating all the time.

    There are two points to note:

    1. The heartbeat function in the provided demos only applies to the four hub motors with IDs 1, 2, 3, and 4;
    2. When the hub motor is in position loop mode, it is best to disable the heartbeat function (i.e., when the time value is -1), otherwise, automatically executing the heartbeat function in position loop mode will cause the hub motor to return to the 0 position.
    Example:
    You can set a heartbeat function command with a time value of 1000, enter the JSON command in the input box: {"T ": 11001," time ": 1000}, click SEND to send, so that when you control the hub motor with ID 1, 2, 3, and 4 to rotate, it will automatically stop after rotating for 1 second, so as to prevent the danger caused by sudden rotation of the motor without structural parts to fix the motor shaft.
    

    Perform Speed Control

    Before performing speed closed-loop control, ensure that you have enabled the motor and switched the motor mode from current loop to speed loop.

    • Click "INPUT" next to the JSON command CMD_DDSM_CTRL, and you can see that the JSON command for the speed ring control motor displayed in the input box at the top of the web interface is: {"T":10010,"id":1,"cmd":50,"act":3}, where:
      • T: Set the command type for the heartbeat function to 11001. These are fixed values and cannot be modified.
      • id: Changed to ID of hub motor to be controlled.
      • cmd: The value of the action command, which needs to correspond to the range of values of the specific mode loop.
      • act: The acceleration time per revolution in 0.1ms. The larger the act value, the smoother the speed change.
    • In the default speed loop mode, the cmd value, which is the value of the target speed for DDSM400 hub motors, is 0.1 rpm. For example, if the cmd value is 100, the target speed for DDSM400 is 10 rpm.

    After clicking SEND to send this command, the hub motor will start rotating. If you don't set the heartbeat function (the time value of the heartbeat function is -1) the hub motor will rotate all the time, and then you can use the speed control command above to change the target speed cmd value to 0 to stop the hub motor from rotating.


    Obtain motor feedback

    • Every time you use CMD_DDSM_CTRL to control the motor, the motor will feedback the current status information.
    • You can use the CMD_DDSM_INFO command to get other information feedback.


    JSON Command Table

    Motor Control

    • {"T":11002,"id":1}——Motor enable command
      • id: Changed to the ID that needs to enable the motor.
    • {"T":11002,"id":1}——Motor disable command
      • id: Changed to the ID that needs to disable the motor.
    • {"T":10010,"id":1,"cmd":50,"act":3}——Motor mode control command
      • id: Changed to ID of hub motor to be controlled.
      • cmd: The value of the action command, which needs to correspond to the range of values of the specific mode loop.
      • act: The acceleration time per revolution in 0.1ms. The larger the act value, the smoother the speed change.
    • {"T":10011,"id":2}——Set the Motor ID command (at this point there is and only one motor is allowed to be connected to the driver board)
      • id: Changed to the ID value of the hub motor that needs to be set, which is 1~253. The newly set ID supports power-off saving.
    • {"T":10012,"id":1,"mode":2}——Switch motor mode command
      • id: The ID of the motor mode that needs to be switched.
      • mode: The value corresponding to motor mode. For specific motor switchable mode, please refer to Motor mode switching in basic usage.
    • {"T":10031}——View the Motor ID command (at this point there is and only one motor is allowed to be connected to the driver board)
    • {"T":10032,"id":1}——View other information commands for the motor
      • id: The motor ID that needs to be viewed.
    • {"T":11001,"time":2000}——Set heartbeat function command
      • time: Time, in ms. When the time value is -1, the heartbeat function is disabled; when the time value is 2000, if no new command is received within 2 seconds after sending the motion control command, the driver board will automatically control the hub motor to stop rotating, so as to prevent the hub motor from rotating all the time.

    WIFI Setting

    • {"T":10401,"cmd":3}——Set the default mode of WIFI when the driver board is powered on
      • cmd: The code of the default mode. 0: WIFI off; 1: AP mode; 2: STA mode; 3: AP+STA mode.
    • {"T":10402,"ssid":"ESP32-AP","password":"12345678"}——Set the AP mode and establish a WIFI hotspot
      • ssid: The hotspot name of the AP mode.
      • password: The hotspot password for AP mode.
    • {"T":10403,"ssid":"EM","password":"bubu6788"}——Set the STA mode to connect the driver board to your existing WIFI
      • ssid: The name of the existing WIFI hotspot, which needs to be modified to the name of the WIFI hotspot you want to connect to.
      • password: The password of the existing WIFI hotspot needs to be modified to the password corresponding to the WIFI hotspot.
    • {"T":10404,"ap_ssid":"ESP32-AP","ap_password":"12345678","sta_ssid":"JSBZY-2.4G","sta_password":"waveshare0755"}——Set AP+STA mode, establish a WiFi hotspot while connecting to an existing WiFi
    • {"T":10405}——View the setting information
    • {"T":10408}——Disconnect the WIFI connection


    ESP32 Setting

    • {"T":600}——ESP32 restart
    • {"T":601}——Get the remaining size of Flash
    • {"T":604}——Clear the nvs area (if there is any functional error, send this command to clear the nvs area and power on the driver board again)

    Wired Control for JSON Commands

    The basic usage section introduces how to send JSON commands in Web applications and explains JSON commands. This section describes how to send JSON commands via wired connection to control the driver board and hub motors.

    You can use a Raspberry Pi, Jetson, PC or other device with a USB port (USB port for serial communication) as the host computer, and connect the driver board and the host computer through the 40PIN serial port or USB port. You can run a Python script on the host computer or send JSON commands to control the hub motor by a tool such as the serial port debugging assistant.

    Serial Port Debugging Assistant

    Here introduces the use of a simple serial port debugging assistant to control the hub motor:

    • Download Serial port debugging assistant
    • Connect the hub motor to the driver board, power the driver board, use a USB cable to connect the host computer and the Type-C port marked with ESP32-USB on the driver board, and make sure that the "UART Control Switch" is in the ESP32 position
    • Double-click to open the cktszsss32.exe, select the USB port number, open the serial port, baud rate 115200, edit the JSON command, you need to manually add a newline character \n after the JSON instruction, or you can choose not to add "\n" and check "Add Enter"

    600px-DDSM-Driver-HAT-A-串口调试助手.png

    • The function of the JSON command is the same as described in the Web Application section above


    Python Serial Communication

    You can run the Python script on the host machine to control the hub motor. This script can be used on any device that supports running Python scripts and serial communication, including Windows PC, Raspberry Pi, Jetson Orin, etc. You can change the serial port device name parameter when running the Python script according to actual conditions.

    Working with Windows

    Install Python

    1. Go to Python official website to download the latest version of Python installation package. You can download it according to your operating system, I downloaded it here for Windows, the version is 3.12.0.

    2. After downloading, double-click the installation program python-3.12.0-amd64. Remember to check "Add python.exe to PATH", then click "Customize installation" to enter the "Optional Features" interface. Note: If you are installing on a Windows system, make sure to check "Add Python.exe to PATH".

    3. In the Optional Features screen, check the box and click "Next" to enter the "Advanced Options" screen.

    4. In the "Advanced Options" interface, the installation address can be changed to the address you want to install after clicking "Browse", this is the default installation address, click "Install" to install after setting, and wait for the installation to be completed.


    Deploy Python virtual environment

    Click to download Python serial communication demo and unzip it, and then enter cmd in the "Start" menu bar to open the Windows command prompt interface, input the cd folder path to enter the ddsm_python project folder.

    cd C:\Users\liuwei\Downloads\Ddsm_python\ddsm_python (liuwei needs to be changed into the corresponding user name of your system)
    

    To create a virtual environment for this project in this project folder, and enter the command: python -m venv [virtual environment name, usually called project name-env].

    python -m venv ddsm-env
    

    To activate the virtual environment, in the command prompt interface enter: project name- env\Scripts\activate.bat.

    ddsm-env\Scripts\activate.bat
    

    After unzipping, you can see that there is a requirements.txt file in the demo, this file is the list of installation packages required for the DDSM_Python project, you can directly install all the necessary packages into the virtual environment by entering the following command:

    python -m pip install -r requirement.txt
    

    700px-Ddsm pythonverify.png

    The virtual environment is already set up, and the installation packages required for this project are installed. Next, we will run the serial communication demo.


    Run Demo

    The Python demo used for serial communication is serial_simple_ctrl.py. The details of the demo are as follows:

    import serial
    import argparse
    import threading
    
    def read_serial():
        while True:
            data = ser.readline().decode('utf-8')
            if data:
                print(f"Received: {data}", end='')
    
    def main():
        global ser
        parser = argparse.ArgumentParser(description='Serial JSON Communication')
        parser.add_argument('port', type=str, help='Serial port name (e.g., COM1 or /dev/ttyUSB0)')
    
        args = parser.parse_args()
    
        ser = serial.Serial(args.port, baudrate=115200, dsrdtr=None)
        ser.setRTS(False)
        ser.setDTR(False)
    
        serial_recv_thread = threading.Thread(target=read_serial)
        serial_recv_thread.daemon = True
        serial_recv_thread.start()
    
        try:
            while True:
                command = input("")
                ser.write(command.encode() + b'\n')
        except KeyboardInterrupt:
            pass
        finally:
            ser.close()
    
    
    if __name__ == "__main__":
        main()

    Connect the hub motor to the driver board, power the driver board, use a USB cable to connect the host computer and the Type-C port marked with ESP32-USB on the driver board, and make sure that the "UART Control Switch" is in the ESP32 position.

    After connecting, search for the Device Manager in the "Start" search bar to view the newly inserted port number. Here, the newly inserted is COM67, and the port number varies for different computers. Remember the newly connected port number.

    700px-DDSM-Python串口通信1.png

    Use the following command to run the serial communication program, and change the serial device name parameter entered when running the Python script according to the actual situation. Replace the COM67 with the port number of the serial device that the driver board inserts into the PC. If you are using a Raspberry Pi, Jeston Orin Nano, etc., change it to the corresponding port name as well.

    python serial_simple_ctrl.py COM67
    

    When the run is complete, the terminal will not return any information, and then you can enter the JSON command into the terminal, press Enter, and you can communicate with the DDSM Driver HAT (B). For example, if you need to obtain the ID of the currently connected motor (only one motor can be connected at this time), you can send {"T":10031}, and a message will be fed back after the transmission is successful.

    700px-DDSM-Python串口通信2.png

    Product Initialization

    When you upload other demo to the DDSM Driver HAT (B) driver board, it will automatically replace its original factory demo. If you need to quickly restore the driver board to the factory demo, you can use the ESP32 download tool we provide.

    The steps are as follows:

    1. Click ESP32 download tool to download, unzip it after downloading, and double-click to open the "flash_download_tool_3.9.5.exe" program. After opening, two windows will pop up, we need to operate the UI interface of the download tool, and the other window will act as a terminal to show the working status of the download tool.

    2. On the "DOWNLOAD TOOL MODE" screen, select ESP32 for Chip Type and Factory for WorkMode. (With Factory, the relative path will only be used when calling the binary, so the user does not need to manually enter the binary path, click OK after selection.)

    M2-S Factory1.png


    3. Enter the download tool software interface, the right side represents the ability to upload programs to 8 drive boards simultaneously. Move the switch on the DDSM Driver HAT (B) driver board to the ESP32 position, connect the ESP32-USB interface on the DDSM Driver HAT (B) driver board to the computer with a USB cable, click on "COM", and select the newly appearing COM (the new COM here is COM67); BAUD is used to set download speed, the higher the speed, the faster. ESP32 can use up to 921600.

    700px-DDSM-Factory1.png


    4. After selection, click "START" to start uploading the program. Once the upload is complete, "IDLE WAIT" will change to "FINISH COMPLETE". After completion, you can disconnect the driver board from the computer's USB connection, connect the hub motor, and power it on to perform the Basic Usage Control.

    DDSM-Factory2.pngDDSM-Factory3.png


    Resources

    Product Model

    Schematic Diagram

    Factory Demo

    Factory Demo Download Tool

    Python Script

    Serial Port Debugging Assistant


    Support

    Monday-Friday (9:30-6:30) Saturday (9:30-5:30)

    Email: services01@spotpear.com