Example Code for Using the On-board Motor Driver
Last revision 2026/01/06
The article presents a comprehensive guide on using the UNIHIKER onboard motor driver with Python, detailing hardware setup, software configuration, and sample code for motor direction and speed control.
Hardware Preparation
- 2x3A DC Motor Driver Carrier Board for UNIHIKER M10
- UNIHIKER M10
- DC Motor
- 7.4V lithium battery
Software Preparation
According to the Getting Started section in the UNIHIKER official documentation, it is recommended for beginners to operate according to the instructions in the Mind+ section. [Click to view]
The main process is: download and install MInd+ on your PC, open Mind+, switch to Python mode and Code page, click on the icon in front of Terminal, open the Connect Remote Terminal menu, and then connect the UNIHIKER. After that, you can create a new py file in the File System, write code and run.

Wiring Diagram


Other Preparation Work
Note: When driving the motor, you need to connect 6-12V power from the DC port, the VM light is on, otherwise the motor will not rotate.
Sample Code
# -*- coding: UTF-8 -*-
# MindPlus
# Python
import time
from pinpong.board import Board,Pin
from pinpong.extension.unihiker import *
Board().begin()
p_p5_out=Pin(Pin.P5, Pin.OUT)
p_p8_pwm=Pin(Pin.P8, Pin.PWM)
p_p6_out=Pin(Pin.P6, Pin.OUT)
p_p16_pwm=Pin(Pin.P16, Pin.PWM)
while True:
print("Simultaneously forward at 50% speed")
# P5 controls the direction of M1
# P8 controls the speed of M1
# P6 controls the direction of M2
# P16 controls the speed of M2
p_p5_out.write_digital(1)
p_p8_pwm.write_analog(512)
p_p6_out.write_digital(1)
p_p16_pwm.write_analog(512)
time.sleep(3)
print("Simultaneously stop")
# Speed is 0, the motor stops rotating
p_p8_pwm.write_analog(0)
p_p16_pwm.write_analog(0)
time.sleep(3)
print("Simultaneously reverse at 100% speed")
# Low level means the motor reverses
p_p5_out.write_digital(0)
p_p8_pwm.write_analog(1023)
p_p6_out.write_digital(0)
p_p16_pwm.write_analog(1023)
time.sleep(3)
Result
Both motors rotate forward at the same time, then stop, and then reverse.

Was this article helpful?
