🛠 Communication entre deux micro:bit avec le module radio

micro:bit V2 (BBC micro:bit v2) · intermediaire · Schéma : IMG-microbit-v2-intermediaire-2-microbit-v2-radio-communication.svg — deux micro:bit V2 face à face avec ondes radio entre elles, message « SOS » transitant de la matrice de l'une à l'autre

Objectives

Make two micro:bit V2 boards communicate wirelessly using the MicroPython radio module, which leverages the 2.4 GHz BLE radio of the nRF52833 (SoftDevice S113). You will send encrypted messages between multiple boards using groups.

Hardware

Complete Code

# Émetteur (carte 1)
from microbit import *
import radio

radio.on
radio.config(group=23, channel=40, power=6)

while True:
    if button_a.was_pressed:
        radio.send("SOS")
        display.show(Image.HAPPY)
    if button_b.was_pressed:
        radio.send("COUCOU")
        display.show(Image.SILLY)
    sleep(50)
# Récepteur (carte 2)
from microbit import *
import radio

radio.on
radio.config(group=23, channel=40, power=6)

while True:
    msg = radio.receive
    if msg == "SOS":
        display.show(Image.SAD)
        sleep(1000)
    elif msg == "COUCOU":
        display.show(Image.HEART)
        sleep(1000)
    display.clear
    sleep(50)

group filters recipients, channel (0-83) sets the 2.4 GHz channel, and power (0-7) sets the transmission power. Messages are small frames; the module is designed for games and multi-board networks (see the official "Fireflies" tutorial).

Expected Verification

Pressing A on board 1: board 2 displays a sad face; pressing B: a heart. Two boards flashed with the same code react to each other from several meters away.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials