m5stack_pbhub¶
CircuitPython driver for M5Stack PbHub
Author(s): Dario Cammi
Implementation Notes¶
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
# * Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class m5stack_pbhub.NeoPixels(pbHub: PbHub, channel: int, number_of_leds: int, brightness: float = 0.5)¶
Drive an array of NeoPixels connect to the PbHub
- Parameters:
pbHub – Instance of PbHub where the leds are connected
channel – Hub channel where the leds are connected
number_of_leds – Number of leds connected to the channel
brightness – Leds brightness
Here is an example of driving a strip with 10 leds connected on channel 0:
import time import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) strip = m5stack_pbhub.NeoPixels(hub, 0, 10) strip[0] = 0xFF0000 # Set the color a single led strip[3] = 0xFF00FF # Set the color a single led time.sleep(1) strip[1:3] = 0x00FFFF # Set the color of two leds time.sleep(1) strip.fill(0xFFFF00) # Set the color of the wall strip time.sleep(1)
- property brightness: float¶
Leds brightness. Range 0 to 1
A change in the brightness take effect only on the subsequent leds color write
- class m5stack_pbhub.PbHub(i2c: I2C, addr: int = 0x61)¶
CircuitPython driver for M5Stack PbHub
- Parameters:
Quickstart: Importing and using the hub
Here is an example of using the
PbHubclass. First you will need to import the libraries, get an I2C bus and create an hub instanceimport board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c)
Now you can create an I/O on one of PbHub channel. For example let create a digital input
din = m5stack_pbhub.PbHubDigitalInput(hub, channel = 1, io = 1) input_value = din.value
- class m5stack_pbhub.PbHubAnalogInput(pbHub: PbHub, channel: int)¶
PbHub analog input
Analog inputs are always on IO pin 0. The resolution is 12 bit (0 - 4095)
Here is an example of reading an analog input
import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) ain = m5stack_pbhub.PbHubAnalogInput(hub, channel = 0) print(ain.value)
- class m5stack_pbhub.PbHubDigitalInput(pbHub: PbHub, channel: int, io: int)¶
PbHub digital input
- Parameters:
Here is an example of reading a digital input
import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) din = m5stack_pbhub.PbHubDigitalInput(hub, channel = 0, io = 0) print(din.value)
- class m5stack_pbhub.PbHubDigitalOutput(pbHub: PbHub, channel: int, io: int)¶
PbHub digital output
- Parameters:
Here is an example of driving a digital output
import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) dout = m5stack_pbhub.PbHubDigitalOutput(hub, channel = 0, io = 0) dout.value = 1 # set the output print(dout.value) # read the output value
- class m5stack_pbhub.PbHubPwmOutput(pbHub: PbHub, channel: int, io: int)¶
PbHub PWM output
- Parameters:
The output resolution is 8 bit (0 - 255)
Here is an example of driving PWM output
import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) pwm = m5stack_pbhub.PbHubPwmOutput(hub, channel = 0, io = 0) pwm.value = 127
- class m5stack_pbhub.PbHubServo(pbHub: PbHub, channel: int, io: int)¶
PbHub output to drive RC servo
- Parameters:
Here is an example of driving an RC servo
import board import m5stack_pbhub i2c = board.I2C() hub = m5stack_pbhub.PbHub(i2c) servo = m5stack_pbhub.PbHubServo(hub, channel = 0, io = 0) servo.angle = 45 # set servo angle in degrees servo.pulse = 1500 # set servo angle as pulse with. 1500µs is equivalent to 90 degrees