树莓派BLE连接micro:bit

sudo apt update
sudo apt install python3-distutils python3-dbus
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
sudo pip3 install bluezero ipython
sudo usermod -aG bluetooth pi
sudo reboot
bluetoothctl
>>> show
Controller XX:XX:XX:XX:XX:XX (public)
        Name: raspberrypi
        Alias: raspberrypi
        Class: 0x00000000
        Powered: yes
        Discoverable: no
        Pairable: yes
>>> scan on
Discovery started
[NEW] Device 7A:AB:38:13:4A:24 7A-AB-38-13-4A-24
>>> scan off
Discovery stopped
>>> pair YY:YY:YY:YY:YY:YY
>>> paired-devices
Device YY:YY:YY:YY:YY:YY BBC micro:bit
>>> connect YY:YY:YY:YY:YY:YY
>>> disconnect YY:YY:YY:YY:YY:YY
>>> exit
#!/usr/bin/env python3

from bluezero import microbit

ubit = microbit.Microbit(
    adapter_addr='XX:XX:XX:XX:XX:XX',
    device_addr='YY:YY:YY:YY:YY:YY'
)

ubit.connect()

desired_services = [
    'LED Service',
]

assert all(i in ubit.services_available() for i in desired_services)

ubit.text = 'hello, world'

ubit.disconnect()
chmod +x hello.py
./hello.py

参考: