Skip to content

Commit 7b843c1

Browse files
icyqwqlbuque
authored andcommitted
doc: Add doc for GRBL module.
Signed-off-by: icyqwq <[email protected]>
1 parent 429d73c commit 7b843c1

File tree

6 files changed

+286
-3
lines changed

6 files changed

+286
-3
lines changed

docs/en/module/grbl.rst

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
2+
GRBLModule
3+
==========
4+
5+
.. include:: ../refs/module.grblmodule.ref
6+
7+
GRBL 13.2 is a three-axis stepper motor driver module in the M5Stack stacking module series. It uses an ATmega328P-AU controller with three sets of DRV8825PWPR stepper motor driver chip control ways, which can drive three bipolar steppers at the same time.
8+
9+
Support the following products:
10+
11+
|GRBLModule|
12+
13+
Micropython Example:
14+
15+
.. literalinclude:: ../../../examples/module/grbl_example.py
16+
:language: python
17+
:linenos:
18+
19+
20+
UIFLOW2 Example:
21+
22+
|example.png|
23+
24+
.. only:: builder_html
25+
26+
|grbl_example.m5f2|
27+
28+
class GRBLModule
29+
----------------
30+
31+
Constructors
32+
------------
33+
34+
.. class:: GRBLModule(address)
35+
36+
Initialize the GRBLModule.
37+
38+
:param hex address: The I2C address of the device.
39+
40+
UIFLOW2:
41+
42+
|init.png|
43+
44+
45+
Methods
46+
-------
47+
48+
.. method:: GRBLModule.g_code(command)
49+
50+
Send the G-code command.
51+
52+
:param command: The G-code command.
53+
54+
UIFLOW2:
55+
56+
|g_code.png|
57+
58+
.. method:: GRBLModule.get_code_time(code)
59+
60+
Get the time of the code.
61+
62+
:return (int): The estimated time of the command.
63+
:param code: The G-code command
64+
65+
UIFLOW2:
66+
67+
|get_code_time.png|
68+
69+
.. method:: GRBLModule.turn(x, y, z, speed)
70+
71+
Turn the motor to a specific position.
72+
73+
:param x: The position of the X motor, 1.6&#x3D;360°.
74+
:param y: The position of the Y motor, 1.6&#x3D;360°.
75+
:param z: The position of the Z motor, 1.6&#x3D;360°.
76+
:param speed: The speed of the motor.
77+
78+
UIFLOW2:
79+
80+
|turn.png|
81+
82+
.. method:: GRBLModule.set_mode(mode)
83+
84+
Set the mode of the motor.
85+
86+
:param mode: The mode of the motor.
87+
Options:
88+
- ``Absolute``: GRBLModule.MODE_ABSOLUTE
89+
- ``Relative``: GRBLModule.MODE_RELATIVE
90+
91+
UIFLOW2:
92+
93+
|set_mode.png|
94+
95+
.. method:: GRBLModule.init(x_step, y_step, z_step, acc)
96+
97+
Initialize the motor.
98+
99+
:param x_step: The step of the X motor.
100+
:param y_step: The step of the Y motor.
101+
:param z_step: The step of the Z motor.
102+
:param acc: The acceleration of the motor.
103+
104+
UIFLOW2:
105+
106+
|init.png|
107+
108+
.. method:: GRBLModule.flush()
109+
110+
Flush the buffer.
111+
112+
113+
UIFLOW2:
114+
115+
|flush.png|
116+
117+
.. method:: GRBLModule.get_message()
118+
119+
Get the message.
120+
121+
:return (str): The message string.
122+
123+
UIFLOW2:
124+
125+
|get_message.png|
126+
127+
.. method:: GRBLModule.get_status()
128+
129+
Get the status.
130+
131+
:return (str): The status string.
132+
133+
UIFLOW2:
134+
135+
|get_status.png|
136+
137+
.. method:: GRBLModule.get_idle_state()
138+
139+
Get the idle state.
140+
141+
:return (bool): The idle state.
142+
143+
UIFLOW2:
144+
145+
|get_idle_state.png|
146+
147+
.. method:: GRBLModule.get_lock_state()
148+
149+
Get the lock state.
150+
151+
:return (bool): The lock state.
152+
153+
UIFLOW2:
154+
155+
|get_lock_state.png|
156+
157+
.. method:: GRBLModule.wait_idle()
158+
159+
Wait until the motor is idle.
160+
161+
162+
UIFLOW2:
163+
164+
|wait_idle.png|
165+
166+
.. method:: GRBLModule.unlock_alarm_state()
167+
168+
Unlock the alarm state.
169+
170+
171+
UIFLOW2:
172+
173+
|unlock_alarm_state.png|
174+
175+
.. method:: GRBLModule.lock()
176+
177+
Lock the motor.
178+
179+
180+
UIFLOW2:
181+
182+
|lock.png|
183+
184+
.. method:: GRBLModule.unlock()
185+
186+
Unlock the motor.
187+
188+
189+
UIFLOW2:
190+
191+
|unlock.png|
192+
193+
194+
195+
Constants
196+
---------
197+
198+
.. data:: GRBLModule.MODE_ABSOLUTE
199+
.. data:: GRBLModule.MODE_RELATIVE
200+
201+
Motor mode
202+

docs/en/module/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Module
88
ain4.rst
99
display.rst
1010
dualkmeter.rst
11+
grbl.rst
1112
hmi.rst
1213
lora.rst
1314
plus.rst

docs/en/refs/module.grbl.ref

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
.. |GRBLModule| image:: https://static-cdn.m5stack.com/resource/docs/products/module/grbl13.2/grbl13.2_01.webp
3+
:target: https://docs.m5stack.com/en/module/grbl13.2
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/init.png
8+
.. |g_code.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/g_code.png
9+
.. |get_code_time.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/get_code_time.png
10+
.. |turn.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/turn.png
11+
.. |set_mode.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/set_mode.png
12+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/init.png
13+
.. |flush.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/flush.png
14+
.. |get_message.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/get_message.png
15+
.. |get_status.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/get_status.png
16+
.. |get_idle_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/get_idle_state.png
17+
.. |get_lock_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/get_lock_state.png
18+
.. |wait_idle.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/wait_idle.png
19+
.. |unlock_alarm_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/unlock_alarm_state.png
20+
.. |lock.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/lock.png
21+
.. |unlock.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/unlock.png
22+
23+
.. |example.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/grblmodule/example.png
24+
25+
.. |grbl_example.m5f2| raw:: html
26+
27+
<a
28+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/grbl_example.m5f2"
29+
target="_blank"
30+
>
31+
grbl_example.m5f2
32+
</a>
33+
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_grbl"]}],"units":[],"hats":[],"bases":[],"i2cs":[],"blockly":"<block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"50\" y=\"51\"><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_grbl_init\" id=\"RC-vbx-n(Cv_B!chD8f,\"><field name=\"NAME\">grbl_0</field><value name=\"ADDR\"><shadow type=\"module_grbl_addr_option\" id=\"5n)d,8aA$iIg@,#0ujOG\"><field name=\"VALUE\">0x70</field></shadow></value><next><block type=\"text_print\" id=\"d;AT9P.x{E5F=S$?{;E9\"><value name=\"TEXT\"><shadow type=\"text\" id=\"-}`=,Z#ox68s,O@3/onO\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_grbl_get_message\" id=\"/_w~#^SP3Z7[h/PDbL#+\"><field name=\"NAME\">grbl_0</field></block></value><next><block type=\"text_print\" id=\"rAZTRKWhf0E-Ma=]{6e1\"><value name=\"TEXT\"><shadow type=\"text\" id=\"uifkr9|kz3RUl*X(@d-)\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_grbl_get_status\" id=\"{iwh*qbulI?8;g-Y~^Gx\"><field name=\"NAME\">grbl_0</field></block></value><next><block type=\"text_print\" id=\"3cfrH`5lu*l.xYG)or/k\"><value name=\"TEXT\"><shadow type=\"text\" id=\"bgF_OeSd0s+{Kz{.gc}O\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_grbl_get_idle_state\" id=\"II0Gu_~2_#:!6|f!l3OY\"><field name=\"NAME\">grbl_0</field></block></value><next><block type=\"text_print\" id=\"9T7AOTCFaQ;We8m?;%vt\"><value name=\"TEXT\"><shadow type=\"text\" id=\"ck=KdstUI]*/Eub*N]O0\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"module_grbl_get_lock_state\" id=\"?TfyE=Q^#:$TrW5Red):\"><field name=\"NAME\">grbl_0</field></block></value><next><block type=\"module_grbl_set_mode\" id=\"=cQ:1^tpiu{OO(4oJA=)\"><field name=\"NAME\">grbl_0</field><value name=\"VALUE\"><shadow type=\"module_grbl_mode_option\" id=\"Xbxccp+!8#Q#3T^i};Wx\"><field name=\"VALUE\">MODE_ABSOLUTE</field></shadow></value><next><block type=\"module_grbl_unlock\" id=\"?:tWQ.93q?e6tCK~@28s\"><field name=\"NAME\">grbl_0</field><next><block type=\"module_grbl_turn\" id=\";$uH`^/JPd~`viN].@(E\"><field name=\"NAME\">grbl_0</field><value name=\"X\"><shadow type=\"math_number\" id=\"9bqk,Y!IvrWsi/MEkNZo\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">5</field></shadow></value><value name=\"Y\"><shadow type=\"math_number\" id=\"Oyx0aZ-%9tDn0?nM{J+8\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">5</field></shadow></value><value name=\"Z\"><shadow type=\"math_number\" id=\"[I,}$8YetURhKt5UiXEU\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">10</field></shadow></value><value name=\"SPEED\"><shadow type=\"math_number\" id=\"joYdc.,5tj8|CsN#|=nD\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">5</field></shadow></value><next><block type=\"module_grbl_wait_idle\" id=\"ME#BAawyx,PY@hk]B#5=\"><field name=\"NAME\">grbl_0</field><next><block type=\"module_grbl_lock\" id=\"j!D}N^/]fu1it?,@w_qU\"><field name=\"NAME\">grbl_0</field></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=\"690\" y=\"110\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"></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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os, sys, io
2+
import M5
3+
from M5 import *
4+
from module import GRBLModule
5+
6+
7+
grbl_0 = None
8+
9+
10+
def setup():
11+
global grbl_0
12+
13+
M5.begin()
14+
Widgets.fillScreen(0x222222)
15+
16+
grbl_0 = GRBLModule(address=0x70)
17+
print(grbl_0.get_message())
18+
print(grbl_0.get_status())
19+
print(grbl_0.get_idle_state())
20+
print(grbl_0.get_lock_state())
21+
grbl_0.set_mode(GRBLModule.MODE_ABSOLUTE)
22+
grbl_0.unlock()
23+
grbl_0.turn(5, 5, 10, 5)
24+
grbl_0.wait_idle()
25+
grbl_0.lock()
26+
27+
28+
def loop():
29+
global grbl_0
30+
M5.update()
31+
32+
33+
if __name__ == "__main__":
34+
try:
35+
setup()
36+
while True:
37+
loop()
38+
except (Exception, KeyboardInterrupt) as e:
39+
try:
40+
from utility import print_error_msg
41+
42+
print_error_msg(e)
43+
except ImportError:
44+
print("please update to latest firmware")

m5stack/libs/module/grbl.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ class GRBLModule:
2323
image: https://static-cdn.m5stack.com/resource/docs/products/module/grbl13.2/grbl13.2_01.webp
2424
category: Module
2525
26-
example: |
27-
from module import GRBLModule
28-
motor = GRBLModule()
26+
example:
27+
- ../../../examples/module/grbl_example.py
28+
29+
m5f2:
30+
- module/grbl_example.m5f2
2931
3032
3133
"""

0 commit comments

Comments
 (0)