GRBL 模块
GRBL 13.2 是 M5Stack 堆叠模块系列中的三轴步进电机驱动模块。它采用 ATmega328P-AU 控制器,配备三组 DRV8825PWPR 步进电机驱动芯片控制方式,可同时驱动三路双极性步进电机。
支持以下产品:
MicroPython 应用示例:
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 GRBLModule 9 10 11grbl_0 = None 12 13 14def setup(): 15 global grbl_0 16 17 M5.begin() 18 Widgets.fillScreen(0x222222) 19 20 grbl_0 = GRBLModule(address=0x70) 21 print(grbl_0.get_message()) 22 print(grbl_0.get_status()) 23 print(grbl_0.get_idle_state()) 24 print(grbl_0.get_lock_state()) 25 grbl_0.set_mode(GRBLModule.MODE_ABSOLUTE) 26 grbl_0.unlock() 27 grbl_0.turn(5, 5, 10, 5) 28 grbl_0.wait_idle() 29 grbl_0.lock() 30 31 32def loop(): 33 global grbl_0 34 M5.update() 35 36 37if __name__ == "__main__": 38 try: 39 setup() 40 while True: 41 loop() 42 except (Exception, KeyboardInterrupt) as e: 43 try: 44 from utility import print_error_msg 45 46 print_error_msg(e) 47 except ImportError: 48 print("please update to latest firmware")
UiFlow2 应用示例
class GRBLModule
构造函数
- class GRBLModule(address)
初始化 GRBLModule。
- 参数:
address (hex) – 设备的 I2C 地址。
UIFLOW2:

Methods
- GRBLModule.g_code(command)
发送 G-code 命令。
- 参数:
command – G-code 命令。
UIFLOW2:

- GRBLModule.get_code_time(code)
获取代码的时间。
- Return (int):
命令的估计时间。
- 参数:
code – G-code 命令
UIFLOW2:

- GRBLModule.turn(x, y, z, speed)
将电机转到指定位置。
- 参数:
x – X 电机的位置,1.6 = 360°。
y – Y 电机的位置,1.6 = 360°。
z – Z 电机的位置,1.6=360°。
speed – 电机的速度。
UIFLOW2:

- GRBLModule.set_mode(mode)
设置电机的模式。
- 参数:
mode – 电机的模式。选项:-
Absolute:GRBLModule.MODE_ABSOLUTE -Relative:GRBLModule.MODE_RELATIVE
UIFLOW2:

- GRBLModule.init(x_step, y_step, z_step, acc)
初始化电机。
- 参数:
x_step – X 电机的步进。
y_step – Y 电机的步距。
z_step – Z 电机的步距。
acc – 电机的加速度。
UIFLOW2:

- GRBLModule.flush()
刷新缓冲区。
UIFLOW2:

- GRBLModule.get_message()
获取消息。
- Return (str):
消息字符串。
UIFLOW2:

- GRBLModule.get_status()
获取状态。
- Return (str):
状态字符串。
UIFLOW2:

- GRBLModule.get_idle_state()
获取空闲状态。
- Return (bool):
空闲状态。
UIFLOW2:

- GRBLModule.get_lock_state()
获取锁定状态。
- Return (bool):
锁状态。
UIFLOW2:

- GRBLModule.wait_idle()
等待电机空闲。
UIFLOW2:

- GRBLModule.unlock_alarm_state()
解除警报状态。
UIFLOW2:

- GRBLModule.lock()
锁定电机。
UIFLOW2:

- GRBLModule.unlock()
解锁电机。
UIFLOW2:


