This is the simple test for broadcast communication between to Technic Hubs (you can change it to City Hub Essential Hub, Inventor Hub, or Prime Hub).
Steps:
- Install experimental firmware for your hubs following this guide
- Connect sender hub and run this code:
from pybricks.hubs import TechnicHub
from pybricks.tools import wait
from pybricks.parameters import Color
from pybricks.experimental import Broadcast
hub = TechnicHub()
radio = Broadcast(topics=["tilt"])
while True:
pitch, roll = hub.imu.tilt()
hub.light.on(Color(roll+180))
radio.send("tilt", (pitch,roll))
wait(10)
- Connect reeiver hub and run this code:
from pybricks.hubs import TechnicHub
from pybricks.tools import wait
from pybricks.parameters import Color
from pybricks.experimental import Broadcast
hub = TechnicHub()
radio = Broadcast(topics=["tilt"])
while True:
data = radio.receive("tilt")
if data:
pitch, roll = data
hub.light.on(Color(roll+180))
wait(10)