micro:bit Radio & Communication Cheatsheet
micro:bit Radio & Communication Cheatsheet
radio module, sending data, I2C, and UART at a glance.
Radio Setup
| import radio | Import the radio module |
| radio.on() | Enable the radio ߀” must call before send/receive |
| radio.off() | Disable radio to save power |
| radio.config(channel=7) | Set channel 0߀“83 ߀” only boards on same channel communicate |
| radio.config(group=1) | Logical group 0߀“255 ߀” boards must share same group |
| radio.config(power=7) | Transmit power 0 (min) to 7 (max range) |
Send & Receive
| radio.send("message") | Broadcast a string to all boards in range |
| radio.receive() | Returns next string from the receive queue, or None |
| radio.send_bytes(b"\\x01") | Send raw bytes instead of a string |
| radio.receive_bytes() | Receive raw bytes |
| radio.receive_full() | Returns (msg, rssi, timestamp) tuple |
I2C
| from microbit import i2c | I2C is part of the microbit module |
| i2c.scan() | Returns list of addresses of connected I2C devices |
| i2c.write(addr, bytes([0x00, 0x01])) | Write bytes to an I2C device |
| i2c.read(addr, n) | Read n bytes from an I2C device |
| SCL = pin19, SDA = pin20 | Default I2C pins on the micro:bit edge connector |
UART
| uart.init(baudrate=9600, tx=pin0, rx=pin1) | Initialise UART on specified pins |
| uart.any() | True if data is waiting in the receive buffer |
| uart.read() | Read all available bytes |
| uart.write("text") | Send text string over UART |