How to connect
The API documentation:
Connect to the first micro:bit found#
# Look for a micro:bit and connect to it
# / Zoek een willekeurige micro:bit en verbind ermee
with KaspersMicrobit.find_one_microbit() as a_microbit:
print(f'Bluetooth address: {a_microbit.address()}')
print(f"Device name: {a_microbit.generic_access.read_device_name()}")
Connect to multiple micro:bits#
# Look for all active micro:bits and connect to them one after another
# / zoek alle micro:bits en verbind er om de beurt mee
multiple_microbits = KaspersMicrobit.find_microbits()
for microbit in multiple_microbits:
with microbit:
print(f'Bluetooth address: {microbit.address()}')
print(f"Device name: {microbit.generic_access.read_device_name()}")
Find a micro:bit by name#
# Look for the micro:bit with the name 'tupaz' and connect to it
# (this does not work with pairing)
# / zoek de micro:bit met de naam 'tupaz' en verbind ermee
# (dit werkt niet met pairing)
with KaspersMicrobit.find_one_microbit(microbit_name='tupaz') as tupaz:
print(f'Bluetooth address: {tupaz.address()}')
print(f"Device name: {tupaz.generic_access.read_device_name()}")
Connect to a micro:bit by address#
# Connect to the micro:bit with the address 'E3:7E:99:0D:C1:BA'
# / Maak een verbinding met de micro:bit met het adres 'E3:7E:99:0D:C1:BA'
with KaspersMicrobit('E3:7E:99:0D:C1:BA') as addressed:
print(f'Bluetooth address: {addressed.address()}')
print(f"Device name: {addressed.generic_access.read_device_name()}")