16from machine
import I2C, Pin
18bus = I2C(0, scl=Pin(5), sda=Pin(4))
23vin_type = motoron.VinSenseType.MOTORON_256
27min_vin_voltage_mv = 4500
31 (1 << motoron.STATUS_FLAG_PROTOCOL_ERROR) |
32 (1 << motoron.STATUS_FLAG_CRC_ERROR) |
33 (1 << motoron.STATUS_FLAG_COMMAND_TIMEOUT_LATCHED) |
34 (1 << motoron.STATUS_FLAG_MOTOR_FAULT_LATCHED) |
35 (1 << motoron.STATUS_FLAG_NO_POWER_LATCHED) |
36 (1 << motoron.STATUS_FLAG_RESET) |
37 (1 << motoron.STATUS_FLAG_COMMAND_TIMEOUT))
44mc.set_error_response(motoron.ERROR_RESPONSE_COAST)
45mc.set_error_mask(error_mask)
49mc.set_command_timeout_milliseconds(100)
52mc.set_max_acceleration(1, 140)
53mc.set_max_deceleration(1, 300)
59while mc.get_motor_driving_flag():
pass
63def check_for_problems():
64 status = mc.get_status_flags()
65 if (status & error_mask):
69 print(
"Controller error: 0x%x" % status, file=sys.stderr)
72 voltage_mv = mc.get_vin_voltage_mv(reference_mv, vin_type)
73 if voltage_mv < min_vin_voltage_mv:
75 print(
"VIN voltage too low:", voltage_mv, file=sys.stderr)
82 if time.ticks_ms() & 2048:
Represents an I2C connection to a Pololu Motoron Motor Controller.