English
English
简体中文
日本語

UiFlow Tutorial

UiFlow1 Development Guide

Project Management

Use LTE network

UiFlow1 Blockly

Event

Unit

Unit HBridge

Example

Set motor parameters and control motor rotation

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

setScreenColor(0x222222)
hbridge_0 = unit.get(unit.HBRIDGE, unit.PORTA)

hbridge_0.init_i2c_address(0x20)
hbridge_0.set_8bit_pwm(127)
hbridge_0.set_16bit_pwm(32767)
hbridge_0.set_direction(1)
while True:
  print((str('Current:') + str(((str((hbridge_0.get_vin_current())) + str('A'))))))
  wait(1)
  wait_ms(2)

API

hbridge_0.init_i2c_address(0x20)
  • Initializes Unit and sets the I2C address
print(hbridge_0.get_adc_value(0, 8))
  • Get voltage resolution
print(hbridge_0.get_vin_current())
  • Get voltage (A, Float)
print(hbridge_0.get_device_status(0xFE))
  • Get the Unit version
print(hbridge_0.get_driver_config(4))
  • Obtain configuration information
    • DIRECTION
    • 8Bit_PWM_DUTY
    • 16Bit_PWM_DUTY
    • PWM_FREQUENCY
hbridge_0.set_16bit_pwm(32767)
  • Set the 16-bit PWM duty cycle
hbridge_0.set_8bit_pwm(127)
  • Set the 8-bit PWM duty cycle
hbridge_0.set_direction(0)
  • Set the current direction
  • STOP
  • FORWARD
  • REVERSE
hbridge_0.set_pwm_freq(1000)
  • Set the PWM frequency
Page Tools
PDF
On This Page