Skip to content

Commit f0f0e37

Browse files
icyqwqlbuque
authored andcommitted
lib/module: Add step motor driver module.
Signed-off-by: icyqwq <[email protected]>
1 parent cbfdd63 commit f0f0e37

File tree

8 files changed

+637
-0
lines changed

8 files changed

+637
-0
lines changed

docs/en/module/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Module
1515
rca.rst
1616
relay_2.rst
1717
rs232.rst
18+
step_motor_driver.rst
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
2+
StepMotorDriverModule
3+
=====================
4+
5+
.. include:: ../refs/module.stepmotordrivermodule.ref
6+
7+
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.
8+
9+
Support the following products:
10+
11+
|StepMotorDriverModule|
12+
13+
Micropython Example:
14+
15+
.. literalinclude:: ../../../examples/module/step_motor_driver.py
16+
:language: python
17+
:linenos:
18+
19+
20+
UIFLOW2 Example:
21+
22+
|example.png|
23+
24+
.. only:: builder_html
25+
26+
|step_motor_driver.m5f2|
27+
28+
class StepMotorDriverModule
29+
---------------------------
30+
31+
Constructors
32+
------------
33+
34+
.. class:: StepMotorDriverModule(address, step_pin, dir_pin)
35+
36+
Initialize the StepMotorDriverModule.
37+
38+
:param hex address: The I2C address of the device.
39+
:param tuple step_pin: The step pin (X, Y, Z) of the motor.
40+
:param tuple dir_pin: The dir pin (X, Y, Z) of the motor.
41+
42+
UIFLOW2:
43+
44+
|init.png|
45+
46+
47+
Methods
48+
-------
49+
50+
.. method:: StepMotorDriverModule.reset_motor(motor_id, state)
51+
52+
Reset the motor.
53+
54+
:param motor_id: The motor to reset.
55+
Options:
56+
- ``X``: StepMotorDriverModule.MOTOR_X
57+
- ``Y``: StepMotorDriverModule.MOTOR_Y
58+
- ``Z``: StepMotorDriverModule.MOTOR_Z
59+
:param bool state: The state of the motor.
60+
61+
UIFLOW2:
62+
63+
|reset_motor.png|
64+
65+
.. method:: StepMotorDriverModule.set_motor_state(state)
66+
67+
Enable or disable the motor.
68+
69+
:param bool state: The state of the motor.
70+
71+
UIFLOW2:
72+
73+
|set_motor_state.png|
74+
75+
.. method:: StepMotorDriverModule.set_microstep(step)
76+
77+
Set the microstep.
78+
79+
:param step: The microstep value.
80+
Options:
81+
- ``FULL``: StepMotorDriverModule.STEP_FULL
82+
- ``1/2``: StepMotorDriverModule.STEP1_2
83+
- ``1/4``: StepMotorDriverModule.STEP1_4
84+
- ``1/8``: StepMotorDriverModule.STEP1_8
85+
- ``1/16``: StepMotorDriverModule.STEP1_16
86+
- ``1/32``: StepMotorDriverModule.STEP1_32
87+
88+
UIFLOW2:
89+
90+
|set_microstep.png|
91+
92+
.. method:: StepMotorDriverModule.set_motor_pwm_freq(motor_id, freq)
93+
94+
Set the motor pwm freq.
95+
96+
:param motor_id: The motor to set the freq.
97+
Options:
98+
- ``X``: StepMotorDriverModule.MOTOR_X
99+
- ``Y``: StepMotorDriverModule.MOTOR_Y
100+
- ``Z``: StepMotorDriverModule.MOTOR_Z
101+
:param int freq: The freq value.
102+
103+
UIFLOW2:
104+
105+
|set_motor_pwm_freq.png|
106+
107+
.. method:: StepMotorDriverModule.set_motor_direction(motor_id, direction)
108+
109+
Set the motor direction.
110+
111+
:param motor_id: The motor to set the direction.
112+
Options:
113+
- ``X``: StepMotorDriverModule.MOTOR_X
114+
- ``Y``: StepMotorDriverModule.MOTOR_Y
115+
- ``Z``: StepMotorDriverModule.MOTOR_Z
116+
:param bool direction: The direction value.
117+
Options:
118+
- ``Positive``: 1
119+
- ``Negative``: 0
120+
121+
UIFLOW2:
122+
123+
|set_motor_direction.png|
124+
125+
.. method:: StepMotorDriverModule.get_all_limit_switch_state()
126+
127+
Get all io state.
128+
129+
130+
UIFLOW2:
131+
132+
|get_all_limit_switch_state.png|
133+
134+
.. method:: StepMotorDriverModule.get_limit_switch_state(switch_id)
135+
136+
Get the io state.
137+
138+
:param int switch_id: The io id.
139+
140+
UIFLOW2:
141+
142+
|get_limit_switch_state.png|
143+
144+
.. method:: StepMotorDriverModule.get_fault_io_state(motor_id)
145+
146+
Get the fault io state.
147+
148+
:param int motor_id: The motor id.
149+
Options:
150+
- ``X``: StepMotorDriverModule.MOTOR_X
151+
- ``Y``: StepMotorDriverModule.MOTOR_Y
152+
- ``Z``: StepMotorDriverModule.MOTOR_Z
153+
154+
UIFLOW2:
155+
156+
|get_fault_io_state.png|
157+
158+
.. method:: StepMotorDriverModule.motor_control(motor_id, state)
159+
160+
Control the motor to rotate/stop.
161+
162+
:param motor_id: The motor id.
163+
Options:
164+
- ``X``: StepMotorDriverModule.MOTOR_X
165+
- ``Y``: StepMotorDriverModule.MOTOR_Y
166+
- ``Z``: StepMotorDriverModule.MOTOR_Z
167+
:param bool state: The state value.
168+
Options:
169+
- ``Rotate``: 1
170+
- ``Stop``: 0
171+
172+
UIFLOW2:
173+
174+
|motor_control.png|
175+
176+
.. method:: StepMotorDriverModule.get_firmware_version()
177+
178+
Get the firmware version.
179+
180+
181+
UIFLOW2:
182+
183+
|get_firmware_version.png|
184+
185+
.. method:: StepMotorDriverModule.set_i2c_address(new_address)
186+
187+
Set the i2c address.
188+
189+
:param int new_address: The new address.
190+
191+
UIFLOW2:
192+
193+
|set_i2c_address.png|
194+
195+
196+
197+
Constants
198+
---------
199+
200+
.. data:: StepMotorDriverModule.MOTOR_X
201+
.. data:: StepMotorDriverModule.MOTOR_Y
202+
.. data:: StepMotorDriverModule.MOTOR_Z
203+
204+
Motor IDs
205+
206+
.. data:: StepMotorDriverModule.MOTOR_STATE_ENABLE
207+
.. data:: StepMotorDriverModule.MOTOR_STATE_DISABLE
208+
209+
Motor states
210+
211+
.. data:: StepMotorDriverModule.INPUT_REG
212+
.. data:: StepMotorDriverModule.OUTPUT_REG
213+
.. data:: StepMotorDriverModule.POLINV_REG
214+
.. data:: StepMotorDriverModule.CONFIG_REG
215+
.. data:: StepMotorDriverModule.FAULT_REG
216+
.. data:: StepMotorDriverModule.RESET_REG
217+
.. data:: StepMotorDriverModule.FIRM_REG
218+
.. data:: StepMotorDriverModule.I2C_REG
219+
220+
Register addresses
221+
222+
.. data:: StepMotorDriverModule.STEP_FULL
223+
.. data:: StepMotorDriverModule.STEP1_2
224+
.. data:: StepMotorDriverModule.STEP1_4
225+
.. data:: StepMotorDriverModule.STEP1_8
226+
.. data:: StepMotorDriverModule.STEP1_16
227+
.. data:: StepMotorDriverModule.STEP1_32
228+
229+
Microstep values
230+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
.. |StepMotorDriverModule| image:: https://static-cdn.m5stack.com/resource/docs/products/module/Stepmotor%20Driver%20Module13.2%20v1.1/img-c2b8ceac-b6be-4cec-9a15-228fcf8623e7.webp
3+
:target: https://docs.m5stack.com/en/module/Stepmotor%20Driver%20Module13.2%20v1.1
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/init.png
8+
.. |reset_motor.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/reset_motor.png
9+
.. |set_motor_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/set_motor_state.png
10+
.. |set_microstep.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/set_microstep.png
11+
.. |set_motor_pwm_freq.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/set_motor_pwm_freq.png
12+
.. |set_motor_direction.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/set_motor_direction.png
13+
.. |get_all_limit_switch_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/get_all_limit_switch_state.png
14+
.. |get_limit_switch_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/get_limit_switch_state.png
15+
.. |get_fault_io_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/get_fault_io_state.png
16+
.. |motor_control.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/motor_control.png
17+
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/get_firmware_version.png
18+
.. |set_i2c_address.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/set_i2c_address.png
19+
20+
.. |example.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/stepmotordrivermodule/example.png
21+
22+
.. |step_motor_driver.m5f2| raw:: html
23+
24+
<a
25+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/step_motor_driver.m5f2"
26+
target="_blank"
27+
>
28+
step_motor_driver.m5f2
29+
</a>
30+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.1.6","type":"basic","components":[{"name":"screen","type":"screen","layer":0,"screenId":"builtin","screenName":"","id":"__basic_screen","createTime":1730340918058,"x":0,"y":0,"width":320,"height":240,"backgroundColor":"#222222","size":0,"isSelected":true}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","rgb","speaker"]},{"module":["module_stepmotor_driver"]}],"units":[],"hats":[],"bases":[],"i2cs":[],"blockly":"<variables><variable id=\"Xh1l;hi6HqjB~2n_Qc0!\">DIR</variable></variables><block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"50\" y=\"50\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"module_stepmotor_driver_init\" id=\"AdoixQQt!-k^T/Zk`eoN\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"ADDR\"><shadow type=\"math_number\" id=\"iPoPul(U;1no%F~s@IWy\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0x27</field></shadow></value><value name=\"STEP\"><block type=\"module_stepmotor_driver_xyz_input\" id=\"P(xxJz9;L#cwu}2w_9l,\" deletable=\"false\" movable=\"false\"><value name=\"X\"><shadow type=\"math_number\" id=\"0o?EJlcz^5kH7}weZhLR\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">16</field></shadow></value><value name=\"Y\"><shadow type=\"math_number\" id=\"*qQ-X:iOg7RTEw!?:h;O\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">12</field></shadow></value><value name=\"Z\"><shadow type=\"math_number\" id=\"$LUr$=Dw737E9Iw,^.Yg\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">15</field></shadow></value></block></value><value name=\"DIR\"><block type=\"module_stepmotor_driver_xyz_input\" id=\"fiDFX(3)Z,tqPigf+Qd{\" deletable=\"false\" movable=\"false\"><value name=\"X\"><shadow type=\"math_number\" id=\"$/L]|{y-R+V.D|*Mq|F6\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">17</field></shadow></value><value name=\"Y\"><shadow type=\"math_number\" id=\"}zAO7WWY8~:mmuwPSdex\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">13</field></shadow></value><value name=\"Z\"><shadow type=\"math_number\" id=\"OeIp~98C4k]M,wYS*r02\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"text_print\" id=\"1XsE@lt]}q5I/2?[iHxg\"><value name=\"TEXT\"><shadow type=\"text\" id=\"py(k1kaG2Oe8:)VXOGW9\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_stepmotor_driver_get_all_limit_switch_state\" id=\"r%02h5~--kG~?+XYX$ms\"><field name=\"NAME\">stepmotor_driver_0</field></block></value><next><block type=\"text_print\" id=\"CcSF6c_5ahje.amLHB-W\"><value name=\"TEXT\"><shadow type=\"text\" id=\"fPm^[hDx6U]c[hYnXh/z\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_stepmotor_driver_get_limit_switch_state\" id=\"+O,RW|`x5}I,9vk{Tuf!\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"ID\"><shadow type=\"math_number\" id=\"]YYRdo}VK]zP6KCC(;6e\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></shadow></value></block></value><next><block type=\"text_print\" id=\"N;nKMJ3j(mpsHkKI_YIz\"><value name=\"TEXT\"><shadow type=\"text\" id=\"(]__~F?i%O%lY40!A^?x\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_stepmotor_driver_get_fault_io_state\" id=\"L_CQj?qBh9B^+$F%^U;J\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"ID\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"FCgBT~tU1hLvKJT)fpOk\"><field name=\"VALUE\">MOTOR_X</field></shadow></value></block></value><next><block type=\"text_print\" id=\"DnkJ_O7?}kfc^1MD5@OU\"><value name=\"TEXT\"><shadow type=\"text\" id=\"67RYSj=Fk|Qo5(cyMV7a\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_stepmotor_driver_get_firmware_version\" id=\"doPBhgjJ]p7Yv3+65B|k\"><field name=\"NAME\">stepmotor_driver_0</field></block></value><next><block type=\"module_stepmotor_driver_reset_motor\" id=\"(H9%/~41u_$KBI5-D#c[\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"5*}p+j}Eu!Y7B$5Qv,{(\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"STATE\"><shadow type=\"module_stepmotor_driver_state_option\" id=\"}c3|;7WQiR-^+u0M#v$I\"><field name=\"VALUE\">MOTOR_STATE_ENABLE</field></shadow></value><next><block type=\"module_stepmotor_driver_set_motor_state\" id=\"jufY]XR]VXBTrd-fzWOm\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"STATE\"><shadow type=\"module_stepmotor_driver_state_option\" id=\"e4b/~ofk6+-tFop|I{yv\"><field name=\"VALUE\">MOTOR_STATE_ENABLE</field></shadow></value><next><block type=\"module_stepmotor_driver_set_microstep\" id=\"AC1kf6EUi5VJ.849ax//\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"VALUE\"><shadow type=\"module_stepmotor_driver_microstep_option\" id=\"eW(9@^KBI3C[;GplW:H1\"><field name=\"VALUE\">STEP_FULL</field></shadow></value><next><block type=\"module_stepmotor_driver_set_motor_direction\" id=\"Mk0;h}azpS8.2Z;xt9X|\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"|pAY:;aQS!EED:daShVs\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"VALUE\"><shadow type=\"module_stepmotor_driver_direction_option\" id=\"@w#(.5JRVMbeL23K}+#Y\"><field name=\"VALUE\">1</field></shadow></value><next><block type=\"module_stepmotor_driver_set_motor_pwm_freq\" id=\"J@bpHJo4CgtA:zfm1Du=\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"x/_3P2+3t@2;.V)Z1mg[\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"FREQ\"><shadow type=\"math_number\" id=\"%1q[X)?U}..pk!ZYQKh.\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1000</field></shadow></value><next><block type=\"module_stepmotor_driver_motor_control\" id=\"z4FLZLC|EXQ1`RN8I++h\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\".),6ixW-_)|oC|@mWKG1\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"VALUE\"><shadow type=\"module_stepmotor_driver_control_option\" id=\"QP7|5rdx[wB#X$FXcgtu\"><field name=\"VALUE\">1</field></shadow></value><next><block type=\"variables_set\" id=\"E1ja$h|lTDuK.cB=z=/A\"><field name=\"VAR\" id=\"Xh1l;hi6HqjB~2n_Qc0!\">DIR</field><value name=\"VALUE\"><block type=\"math_number\" id=\"}{7FtIr7pqr*yb}${_M]\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"750\" y=\"110\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"><next><block type=\"controls_ifelse\" id=\"uFG$mw@@#chfWeD~YLes\"><value name=\"IF0\"><block type=\"variables_get\" id=\"f/8Y(~`HF;AUcZGlJalm\"><field name=\"VAR\" id=\"Xh1l;hi6HqjB~2n_Qc0!\">DIR</field></block></value><statement name=\"DO0\"><block type=\"module_stepmotor_driver_set_motor_direction\" id=\"O@]On::S+SCF`%cKVqZ{\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"s.gsmTvQL`L0x~;_P?8u\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"VALUE\"><shadow type=\"module_stepmotor_driver_direction_option\" id=\")mcjO./qQ0${UqHM*e0}\"><field name=\"VALUE\">1</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"module_stepmotor_driver_set_motor_direction\" id=\"M=,p-qib+:a]/]HxfL$w\"><field name=\"NAME\">stepmotor_driver_0</field><value name=\"MOTOR\"><shadow type=\"module_stepmotor_driver_motorid_option\" id=\"rTA.k3q^gtsHYZw.q:Mh\"><field name=\"VALUE\">MOTOR_X</field></shadow></value><value name=\"VALUE\"><shadow type=\"module_stepmotor_driver_direction_option\" id=\"{Mqer.hQ{,[oSc|%UNN8\"><field name=\"VALUE\">0</field></shadow></value></block></statement><next><block type=\"variables_set\" id=\"Z+rt{uGI?(1(c~o*jo,+\"><field name=\"VAR\" id=\"Xh1l;hi6HqjB~2n_Qc0!\">DIR</field><value name=\"VALUE\"><block type=\"logic_negate\" id=\"IM9:U8=Y0A3Z0:?iDeSs\"><value name=\"BOOL\"><block type=\"variables_get\" id=\"co7s6YSYqu0VxnMUbQJm\"><field name=\"VAR\" id=\"Xh1l;hi6HqjB~2n_Qc0!\">DIR</field></block></value></block></value><next><block type=\"time_sleep_second\" id=\"qs/n/:uBLOaS7[hwz[xx\"><value name=\"SECOND\"><shadow type=\"math_number\" id=\"[r4511JWjq;G#*2?0?ED\"><mutation max=\"Infinity\" min=\"0\" precision=\"0\"></mutation><field name=\"NUM\">2</field></shadow></value></block></next></block></next></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":320,"height":240,"scale":0.78,"screenName":"","blockId":"","screenColorType":0,"id":"builtin","createTime":1730340918058}],"logicWhenNum":0,"customList":[]}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os, sys, io
2+
import M5
3+
from M5 import *
4+
from module import StepMotorDriverModule
5+
import time
6+
7+
8+
stepmotor_driver_0 = None
9+
10+
11+
DIR = None
12+
13+
14+
def setup():
15+
global stepmotor_driver_0, DIR
16+
17+
M5.begin()
18+
Widgets.fillScreen(0x222222)
19+
20+
stepmotor_driver_0 = StepMotorDriverModule(
21+
address=0x27, step_pin=(16, 12, 15), dir_pin=(17, 13, 0)
22+
)
23+
print(stepmotor_driver_0.get_all_limit_switch_state())
24+
print(stepmotor_driver_0.get_limit_switch_state(0))
25+
print(stepmotor_driver_0.get_fault_io_state(StepMotorDriverModule.MOTOR_X))
26+
print(stepmotor_driver_0.get_firmware_version())
27+
stepmotor_driver_0.reset_motor(
28+
StepMotorDriverModule.MOTOR_X, StepMotorDriverModule.MOTOR_STATE_ENABLE
29+
)
30+
stepmotor_driver_0.set_motor_state(StepMotorDriverModule.MOTOR_STATE_ENABLE)
31+
stepmotor_driver_0.set_microstep(StepMotorDriverModule.STEP_FULL)
32+
stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 1)
33+
stepmotor_driver_0.set_motor_pwm_freq(StepMotorDriverModule.MOTOR_X, 1000)
34+
stepmotor_driver_0.motor_control(StepMotorDriverModule.MOTOR_X, 1)
35+
DIR = 0
36+
37+
38+
def loop():
39+
global stepmotor_driver_0, DIR
40+
M5.update()
41+
if DIR:
42+
stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 1)
43+
else:
44+
stepmotor_driver_0.set_motor_direction(StepMotorDriverModule.MOTOR_X, 0)
45+
DIR = not DIR
46+
time.sleep(2)
47+
48+
49+
if __name__ == "__main__":
50+
try:
51+
setup()
52+
while True:
53+
loop()
54+
except (Exception, KeyboardInterrupt) as e:
55+
try:
56+
from utility import print_error_msg
57+
58+
print_error_msg(e)
59+
except ImportError:
60+
print("please update to latest firmware")

m5stack/libs/module/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"Relay4Module": "relay_4",
2020
"Relay2Module": "relay_2",
2121
"RS232Module": "rs232",
22+
"StepMotorDriverModule": "step_motor_driver",
2223
}
2324

2425
# Lazy loader, effectively does:

m5stack/libs/module/manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"relay_4.py",
2323
"relay_2.py",
2424
"rs232.py",
25+
"step_motor_driver.py",
2526
),
2627
base_path="..",
2728
opt=0,

0 commit comments

Comments
 (0)