yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Wheeled Chassis Kit📖
0.Chassis installation course
  • Installation Video-1
  • Installation Video-2
  • Installation Video-3
1.4-channel motor drive module tutorials
Motor introduction and commissioning
  • 1. Motor introduction and usage
  • 2.PC host
IIC communication
  • For Arduino
  • For ESP32
  • For JetsonNANO
  • For MSPM0
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
USART communication
  • For Arduino
  • For ESP32
  • For JetsonNANO
  • For MSPM0
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
2.Kinematic analysis
  • Kinematic Analysis of Two-wheel Drive Vehicles
  • Kinematic Analysis of Four-wheel Drive Vehicles
3.MSPM0 chassis tutorials(MSPM0G3507/MSPM0G3519)
MSPM0 Basic Course
  • 1. Introduction to MSPM0
Development environment construction
  • 01.CCS Theia Development
  • 02.MDK Arm Development
  • 03.UniFlash Downloader
  • 04.DAP-LINK download program
  • 05.Program simulation and debugging
  • 06.Engineering transplantation
Keil basic case
  • 1. Turn on the LED light
  • 2. System delay
  • 3. Button control
  • 4. External interruption
  • 5. Serial communication
  • 6. Timer
  • 7. PWM breathing light
  • 8. ADC acquisition
  • 9. DMA transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
CCS basic case
  • 1. Turn on the LED light
  • 2. System delay
  • 3. Button control
  • 4. External interruption
  • 5. Serial communication
  • 6. Timer
  • 7. PWM breathing light
  • 8. ADC acquisition
  • 9. DMA transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
MSPM0 Robot Expansion Board Example
  • 1. Introduction to MSPM0 robot expansion board
  • 2. Customize buttons
  • 3. Drive the buzzer
MSPM0 Sensor extension information
  • 01.3-channel tracking
  • 02.4-channel tracking
  • 03.8-channel tracking
  • 04.CCD tracking
  • 05.Electric PTZ control
  • 06.2.4G handle control
  • 07.Servo ultrasonic avoid
  • 08.Bluetooth remote control
  • 09.K210-Automatic Driving
  • 10.K210-Color follow
  • 11.K210-Number recognition
  • 12.K210-Color reaction
  • 13.K210-Road signs
  • 14.K210-Machine code following
  • 15.K210-QR code recognition
  • 16.K230-Visual tracking
  • 17.K230-Color tracking
  • 18.K230-Color response
  • 19.K230-Road sign recognition
  • 20.K230-Machine code tracking
  • 21.K230-QR code recognition action
  • 22.K230-Autonomous avoid
  • 23.K230-License plate tracking
  • 24.K230-Face tracking
  • 25.K230-Gaze direction tracking
  • 26.K230-Palm tracking
  • 27.K230-Target tracking
  • 28.K230-Human body tracking
  • 29.K230-OCR character recognition action
4.STM32 chassis tutorials
  • 01.3-channel tracking
  • 02.4-channel tracking
  • 03.8-channel tracking
  • 04.CCD tracking
  • 05.Electric PTZ control
  • 06.2.4G handle control
  • 07.Servo ultrasonic avoid
  • 08.Bluetooth remote control
  • 09.K210-Automatic Driving
  • 10.K210-Color follow
  • 11.K210-Number recognition
  • 12.K210-Color Reaction
  • 13.K210-Road signs
  • 14.K210-Machine code following
  • 15.K210-QR code recognition
  • 16.K230-Visual tracking
  • 17.K230-Color tracking
  • 18.K230-Color response
  • 19.K230-Road sign recognition
  • 20.K230-Machine code tracking
  • 21.K230-QR code recognition action
  • 22.K230-Autonomous avoid
  • 23.K230-License plate tracking
  • 24.K230-Face tracking
  • 25.K230-Gaze direction tracking
  • 26.K230-Palm tracking
  • 27.K230-Target tracking
  • 28.K230-Human body tracking
  • 29.K230-OCR character recognition action
5.Expand course
  • 1.Autonomous driving car
  • 2.Vehicle-mounted balance ball motion control systemnew
Download
  • Code
  • 3D_Model_File
Download ZIP

Welcome to Wheeled Chassis Kit repository

For PICO2

Drive motor and read encoder-USART

Drive motor and read encoder-USART

1.1 Explanation

Please read 《0. Motor introduction and usage》first to understand the motor parameters, wiring method, and power supply voltage you are currently using. To avoid improper operation and damage to the driver board or motor.

I2C and serial communication cannot be shared, only one can be selected.

Hardware wiring:

Motor4-channel motor drive board(Motor)
M2M-
V3V3
AH1A
BH1B
GGND
M1M+
4-channel motor drive boardPico2
RX2GP0
TX2GP1
GNDGND
5V3V3

 

1.2 Instructions

Open the code using Thonny software, connect to the Raspberry Pi pico2, and click the stop button on the far right of the upper toolbar.

Then, you can see the information of the current firmware in pico2 pop up in the message bar at the bottom, which means that the software has recognized the serial port.

If the message bar here shows that the serial port cannot be recognized, you need to refer to the firmware flashing tutorial and flash the firmware to the motherboard so that the serial port can be recognized.

 

After successfully identifying the serial port and printing the firmware information, click the green button to start running the script.

1.3 Code analysis

​x
UPLOAD_DATA = 3  #0:不接受数据 1:接收总的编码器数据 2:接收实时的编码器 3:接收电机当前速度 mm/s
                 #0: Do not receive data 1: Receive total encoder data 2: Receive real-time encoder 3: Receive current motor speed mm/s

MOTOR_TYPE = 1  #1:520电机 2:310电机 3:测速码盘TT电机 4:TT直流减速电机 5:L型520电机
                #1:520 motor 2:310 motor 3:speed code disc TT motor 4:TT DC reduction motor 5:L type 520 motor

  • UPLOAD_DATA: used to set the data of the motor encoder. Set 1 to the total number of encoder pulses and 2 to the real-time pulse data of 10ms.

  • MOTOR_TYPE: used to set the type of motor used. Just modify the corresponding numbers according to the comments according to the motor you are currently using. You don’t need to modify the rest of the code.

If you need to drive the motor and observe the data, just modify the two numbers at the beginning of the program. No changes are required to the rest of the code.

xxxxxxxxxx
def set_motor_parameter():

    if MOTOR_TYPE == 1:
        set_motor_type(1)  # 配置电机类型
        time.sleep(0.1)
        set_pluse_phase(30)  # 配置减速比,查电机手册得出
        time.sleep(0.1)
        set_pluse_line(11)  # 配置磁环线,查电机手册得出
        time.sleep(0.1)
        set_wheel_dis(67.00)  # 配置轮子直径,测量得出
        time.sleep(0.1)
        set_motor_deadzone(1600)  # 配置电机死区,实验得出
        time.sleep(0.1)

    elif MOTOR_TYPE == 2:
        set_motor_type(2)
        time.sleep(0.1)
        set_pluse_phase(20)
        time.sleep(0.1)
        set_pluse_line(13)
        time.sleep(0.1)
        set_wheel_dis(48.00)
        time.sleep(0.1)
        set_motor_deadzone(1200)
        time.sleep(0.1)

    elif MOTOR_TYPE == 3:
        set_motor_type(3)
        time.sleep(0.1)
        set_pluse_phase(45)
        time.sleep(0.1)
        set_pluse_line(13)
        time.sleep(0.1)
        set_wheel_dis(68.00)
        time.sleep(0.1)
        set_motor_deadzone(1250)
        time.sleep(0.1)

    elif MOTOR_TYPE == 4:
        set_motor_type(4)
        time.sleep(0.1)
        set_pluse_phase(48)
        time.sleep(0.1)
        set_motor_deadzone(1000)
        time.sleep(0.1)

    elif MOTOR_TYPE == 5:
        set_motor_type(1)
        time.sleep(0.1)
        set_pluse_phase(40)
        time.sleep(0.1)
        set_pluse_line(11)
        time.sleep(0.1)
        set_wheel_dis(67.00)
        time.sleep(0.1)
        set_motor_deadzone(1600)
        time.sleep(0.1)

This is used to store the parameters of the Yahboom motor. By modifying the MOTOR_TYPE parameter above, one-click configuration can be achieved.

In normally, do not modify the code here when using the Yahboom motor.

If you are using your own motor, or if a certain data needs to be modified according to your needs, you can check the course《1.2 Control command》 to understand the specific meaning of each command.

xxxxxxxxxx
if __name__ == "__main__":
    try:
        t = 0
        print("please wait...")
        send_upload_command(UPLOAD_DATA)#给电机模块发送需要上报的数据 Send the data that needs to be reported to the motor module
        time.sleep(0.1)
        set_motor_parameter()#设计电机参数  Design motor parameters

        while True:
            received_message = receive_data()  # 接收消息    Receiving Messages
            if received_message:    # 如果有数据返回 If there is data returned
                parsed = parse_data(received_message) # 解析数据 Parsing the data
                if parsed:
                    print(parsed)  # 打印解析后的数据   Print the parsed data

            t += 10
            M1 = t
            M2 = t
            M3 = t
            M4 = t
            
            if MOTOR_TYPE == 4:
                control_pwm(M1*2, M2*2, M3*2, M4*2)
            else:
                control_speed(M1, M2, M3, M4)#直接发送命令控制电机  Send commands directly to control the motor

            if t> 1000 or t < -1000:
                t = 0

            time.sleep(0.1)

In the loop program, the speed of the four motors will be slowly increased from 0 to 1000. If the motor type is 4, that is, the motor without encoder, the motor's PWM is directly controlled.

At the same time, the data sent by the driver board is read and printed out at the same time.

xxxxxxxxxx
# 接收数据  Receiving Data
def receive_data():
    global recv_buffer
    if uart.any() > 0:  # 检查串口缓冲区是否有数据  Check if there is data in the serial port buffer
        recv_buffer += uart.read(uart.any()).decode()  # 读取并解码数据  Read and decode data
        
        # 按结束符 "#" 分割消息 Split the message by the ending character "#"
        messages = recv_buffer.split("#")
        recv_buffer = messages[-1]
        
        if len(messages) > 1:
            return messages[0] + "#"  #返回一条完整的消息   Return a complete message
    return None

# 解析接收到的数据  Parsing received data
def parse_data(data):
    data = data.strip()  # 去掉两端的空格或换行符   Remove spaces or line breaks at both ends

    if data.startswith("$MAll:"):
        values_str = data[6:-1]  # 去除 "$MAll:" 和 "#" Remove "$MAll:" and "#"
        values = list(map(int, values_str.split(',')))  # 分割并转换为整数  Split and convert to integer
        parsed = ', '.join([f"M{i+1}:{value}" for i, value in enumerate(values)])
        return parsed
    elif data.startswith("$MTEP:"):
        values_str = data[6:-1]
        values = list(map(int, values_str.split(',')))
        parsed = ', '.join([f"M{i+1}:{value}" for i
For MSPM0
For RDK X5

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文