busio
— Hardware accelerated behavior¶
The busio
module contains classes to support a variety of serial
protocols.
When the microcontroller does not support the behavior in a hardware
accelerated fashion it may internally use a bitbang routine. However, if
hardware support is available on a subset of pins but not those provided,
then a RuntimeError will be raised. Use the bitbangio
module to explicitly
bitbang a serial protocol on any general purpose pins.
Libraries
All classes change hardware state and should be deinitialized when they
are no longer needed if the program continues after use. To do so, either
call deinit()
or use a context manager. See
Lifetime and ContextManagers for more info.
For example:
import busio
from board import *
i2c = busio.I2C(SCL, SDA)
print(i2c.scan())
i2c.deinit()
This example will initialize the the device, run
scan()
and then deinit()
the
hardware. The last step is optional because CircuitPython automatically
resets hardware after a program finishes.