Initialize the I2C address and frequency configuration for the stepper motors, set the rotation direction for Motor X and Motor Y, read the device's firmware version and I2C address, then enter a control loop to perform reset operations on Motors X and Y, enable/disable motor operation, and toggle their activation states at predefined time intervals.
from m5stack import *
from m5ui import *
from uiflow import *
import module
import time
setScreenColor(0x000000)
stepmotor = module.get(module.STEPMOTORDRIVER)
stepmotor.initDevice(0x27)
stepmotor.setStepPulse(500, 0)
stepmotor.setStepPulse(500, 1)
stepmotor.setStepPulse(500, 2)
stepmotor.setStepDir(0, 1)
stepmotor.setStepDir(1, 1)
stepmotor.enableMotor(1)
print(stepmotor.readStatus(0XFE))
print(stepmotor.readStatus(0XFF))
while True:
stepmotor.resetMotor(0, 1)
wait(2)
stepmotor.resetMotor(1, 1)
wait(2)
stepmotor.enableMotor(0)
wait(2)
stepmotor.enableMotor(1)
wait(2)
stepmotor.resetMotor(0, 0)
wait(2)
stepmotor.resetMotor(1, 0)
wait(2)
wait_ms(2) stepmotor.enableMotor(0) stepmotor.initDevice(0x27) stepmotor.modbus_init(26, 34, 115200, 1, 1) stepmotor.readStatus(0XFE) stepmotor.readFaultPinStatus(0) stepmotor.readIOstatus() stepmotor.readPinStatus(0) stepmotor.resetMotor(0, 1) stepmotor.setI2cAddress(0x27) stepmotor.setMicroStepSelect(0) stepmotor.singleMotorCtrl(0, 0) stepmotor.setStepDir(0, 0) stepmotor.setStepPulse(500, 0) modbus.read_coils(1, 1, 0) modbus.read_discrete_inputs(1, 1, 0) modbus.read_holding_registers(1, 1, 0, True) modbus.read_input_registers(1, 1, 0, True) modbus.write_multiple_coils(1, 1, 0) modbus.write_multiple_registers(1, 1, 0, True) modbus.write_single_coil(1, 1, 0) modbus.write_single_register(1, 1, 0, True) print((str('code:') + str((1)))) modbus.find_address modbus.find_function modbus.find_quantity modbus.function_init(1, 0, 0) modbus.receive_req_create_pdu() modbus.create_slave_response(0) modbus.update_process(1, 0, 0, [0, 0, 0]) modbus._mdbus_uart.any() modbus._mdbus_uart.read() modbus._mdbus_uart.readline() modbus._mdbus_uart.read(10) modbus._mdbus_uart.write('') modbus._mdbus_uart.write(''+"\r\n") modbus._mdbus_uart.write(bytes([0, 0, 0]))