pdf-icon

UIFlow Guide

UiFlow1 Blockly

Event

Unit

UiFlow1 Project

Unit BLDC Driver

Example

Motor Rotates at Constant Speed

from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0x222222)
bldc_driver_0 = unit.get(unit.BLDC_DRIVER, unit.PORTA)

bldc_driver_0.init_i2c_address(0x65)
bldc_driver_0.set_motor_model(1)
bldc_driver_0.set_mode(0)
while True:
  bldc_driver_0.set_open_loop_pwm(500)
  bldc_driver_0.set_rpm_float(500)
  print((str('rpm value:') + str((bldc_driver_0.get_read_back_rpm_str))))
  print((str('pwm value:') + str((bldc_driver_0.get_open_loop_pwm))))
  wait_ms(2)

API

bldc_driver_0.init_i2c_address(0x65)
  • Initialize BLDC Driver and Set I2C Address
print((str('Version:') + str((bldc_driver_0.get_device_spec(0xFE)))))
  • Get Current Version of the Device
    • FIRMWARE_VERSION
    • I2C_ADDRESS
print((str('Current direction:') + str((bldc_driver_0.get_motor_current_direction))))
  • Get Current Rotation Direction of the Motor
print((str('Current mode:') + str((bldc_driver_0.get_current_mode))))
  • Get Current Mode
print((str('Mofot Current mode:') + str((bldc_driver_0.get_motor_current_model))))
  • Get Current Operating Mode of the Motor
print((str('pole pairs:') + str((bldc_driver_0.get_motor_pole_pairs))))
  • Get Pole Pair Number of the Motor
print((str('PID value:') + str((bldc_driver_0.get_pid_value))))
  • Get PID Controller Parameter Values
print((str('dutycycle value:') + str((bldc_driver_0.get_open_loop_pwm))))
  • Get PWM Duty Cycle Value in Open-Loop Mode
print((str('freq value') + str((bldc_driver_0.get_read_back_freq_float))))
  • Get Feedback Frequency Value (Floating-Point Format)
print((str('freq value:') + str((bldc_driver_0.get_read_back_freq_int))))
  • Get Feedback Frequency Value (Integer Format)
print((str('freq value:') + str((bldc_driver_0.get_read_back_freq_str))))
  • Get Feedback Frequency Value (String Format)
print((str('freq value:') + str((bldc_driver_0.get_read_back_freq_float))))
  • Get Feedback Speed Value (RPM, Floating-Point Format)
print((str('rpm value:') + str((bldc_driver_0.get_read_back_rpm_int))))
  • Get Feedback Speed Value (RPM, Integer Format)
print((str('rpm value:') + str((bldc_driver_0.get_read_back_rpm_str))))
  • Get Feedback Speed Value (RPM, String Format)
print((str('rpm value:') + str((bldc_driver_0.get_read_back_rpm_float))))
  • Get Set Speed Value (RPM, Floating-Point Format)
print((str('rpm value:') + str((bldc_driver_0.get_rpm_int))))
  • Get Set Speed Value (RPM, Integer Format)
print((str('motor status:') + str((bldc_driver_0.get_motor_status))))
  • Get Current Status of the Motor
bldc_driver_0.save_data_in_flash()
  • Save Current Motor Data to Flash Memory
bldc_driver_0.set_direction(0)
  • Set Motor Rotation Direction to Forward
    • FORWARD
    • BACKWARD
bldc_driver_0.set_i2c_address(0x65)
  • Set I2C Address of the Device
bldc_driver_0.set_mode(0)
  • Set Motor Mode
    • OPEN_LOOP
    • COLSE_LOOP
bldc_driver_0.set_motor_model(0)
  • Set Motor Speed Mode
    • LOW_SPEED
    • HIGH_SPEED
bldc_driver_0.set_open_loop_pwm(500)
  • Set PWM Duty Cycle in Open-Loop Mode
bldc_driver_0.set_pid_value(14200, 5536, 1580)
  • Set PID Controller Parameters
bldc_driver_0.set_pole_pairs(7)
  • Set Pole Pair Number of the Motor
bldc_driver_0.set_rpm_float(500)
  • Set Motor Speed (Floating-Point Format)
bldc_driver_0.set_rpm_int(500)
  • Set Motor Speed (Integer Format)
On This Page