StepMotorDriver Module
StepMotor Driver Module 13.2 V1.1 is a stepper motor driver adapted to M5 main control, using STM32+HR8825 stepper motor drive scheme, providing 3-way bipolar stepper motor control interface.
Support the following products:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from module import StepMotorDriverModule 9import time 10 11 12stepmotor_driver_0 = None 13 14 15DIR = None 16 17 18def setup(): 19 global stepmotor_driver_0, DIR 20 21 M5.begin() 22 Widgets.fillScreen(0x222222) 23 24 stepmotor_driver_0 = StepMotorDriverModule( 25 address=0x27, step_pin=(16, 12, 15), dir_pin=(17, 13, 0) 26 ) 27 print(stepmotor_driver_0.get_all_limit_switch_state()) 28 print(stepmotor_driver_0.get_limit_switch_state(0)) 29 print(stepmotor_driver_0.get_fault_io_state(StepMotorDriverModule.MOTOR_X)) 30 print(stepmotor_driver_0.get_firmware_version()) 31 stepmotor_driver_0.reset_motor( 32 StepMotorDriverModule.MOTOR_X, StepMotorDriverModule.MOTOR_STATE_ENABLE 33 ) 34 stepmotor_driver_0.set_motor_state(StepMotorDriverModule.MOTOR_STATE_ENABLE) 35 stepmotor_driver_0.set_microstep(StepMotorDriverModule.STEP_FULL) 36 stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 1) 37 stepmotor_driver_0.set_motor_pwm_freq(StepMotorDriverModule.MOTOR_X, 1000) 38 stepmotor_driver_0.motor_control(StepMotorDriverModule.MOTOR_X, 1) 39 DIR = 0 40 41 42def loop(): 43 global stepmotor_driver_0, DIR 44 M5.update() 45 if DIR: 46 stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 1) 47 else: 48 stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 0) 49 DIR = not DIR 50 time.sleep(2) 51 52 53if __name__ == "__main__": 54 try: 55 setup() 56 while True: 57 loop() 58 except (Exception, KeyboardInterrupt) as e: 59 try: 60 from utility import print_error_msg 61 62 print_error_msg(e) 63 except ImportError: 64 print("please update to latest firmware")
UIFLOW2 Example:
class StepMotorDriverModule
Constructors
Methods
- StepMotorDriverModule.reset_motor(motor_id, state)
Reset the motor.
- Parameters:
motor_id – The motor to reset. Options: -
X
: StepMotorDriverModule.MOTOR_X -Y
: StepMotorDriverModule.MOTOR_Y -Z
: StepMotorDriverModule.MOTOR_Zstate (bool) – The state of the motor.
UIFLOW2:
- StepMotorDriverModule.set_motor_state(state)
Enable or disable the motor.
- Parameters:
state (bool) – The state of the motor.
UIFLOW2:
- StepMotorDriverModule.set_microstep(step)
Set the microstep.
- Parameters:
step – The microstep value. Options: -
FULL
: StepMotorDriverModule.STEP_FULL -1/2
: StepMotorDriverModule.STEP1_2 -1/4
: StepMotorDriverModule.STEP1_4 -1/8
: StepMotorDriverModule.STEP1_8 -1/16
: StepMotorDriverModule.STEP1_16 -1/32
: StepMotorDriverModule.STEP1_32
UIFLOW2:
- StepMotorDriverModule.set_motor_pwm_freq(motor_id, freq)
Set the motor pwm freq.
- Parameters:
motor_id – The motor to set the freq. Options: -
X
: StepMotorDriverModule.MOTOR_X -Y
: StepMotorDriverModule.MOTOR_Y -Z
: StepMotorDriverModule.MOTOR_Zfreq (int) – The freq value.
UIFLOW2:
- StepMotorDriverModule.set_motor_direction(motor_id, direction)
Set the motor direction.
- Parameters:
motor_id – The motor to set the direction. Options: -
X
: StepMotorDriverModule.MOTOR_X -Y
: StepMotorDriverModule.MOTOR_Y -Z
: StepMotorDriverModule.MOTOR_Zdirection (bool) – The direction value. Options: -
Positive
: 1 -Negative
: 0
UIFLOW2:
- StepMotorDriverModule.get_all_limit_switch_state()
Get all io state.
UIFLOW2:
- StepMotorDriverModule.get_limit_switch_state(switch_id)
Get the io state.
- Parameters:
switch_id (int) – The io id.
UIFLOW2:
- StepMotorDriverModule.get_fault_io_state(motor_id)
Get the fault io state.
- Parameters:
motor_id (int) – The motor id. Options: -
X
: StepMotorDriverModule.MOTOR_X -Y
: StepMotorDriverModule.MOTOR_Y -Z
: StepMotorDriverModule.MOTOR_Z
UIFLOW2:
- StepMotorDriverModule.motor_control(motor_id, state)
Control the motor to rotate/stop.
- Parameters:
motor_id – The motor id. Options: -
X
: StepMotorDriverModule.MOTOR_X -Y
: StepMotorDriverModule.MOTOR_Y -Z
: StepMotorDriverModule.MOTOR_Zstate (bool) – The state value. Options: -
Rotate
: 1 -Stop
: 0
UIFLOW2:
- StepMotorDriverModule.get_firmware_version()
Get the firmware version.
UIFLOW2:
Constants
- StepMotorDriverModule.MOTOR_X
- StepMotorDriverModule.MOTOR_Y
- StepMotorDriverModule.MOTOR_Z
Motor IDs
- StepMotorDriverModule.MOTOR_STATE_ENABLE
- StepMotorDriverModule.MOTOR_STATE_DISABLE
Motor states
- StepMotorDriverModule.INPUT_REG
- StepMotorDriverModule.OUTPUT_REG
- StepMotorDriverModule.POLINV_REG
- StepMotorDriverModule.CONFIG_REG
- StepMotorDriverModule.FAULT_REG
- StepMotorDriverModule.RESET_REG
- StepMotorDriverModule.FIRM_REG
- StepMotorDriverModule.I2C_REG
Register addresses
- StepMotorDriverModule.STEP_FULL
- StepMotorDriverModule.STEP1_2
- StepMotorDriverModule.STEP1_4
- StepMotorDriverModule.STEP1_8
- StepMotorDriverModule.STEP1_16
- StepMotorDriverModule.STEP1_32
Microstep values