Skip to content

Instantly share code, notes, and snippets.

@pbochynski
Last active November 8, 2022 10:58
Show Gist options
  • Save pbochynski/c8336c885251c77ed9fbf8e75cd4defc to your computer and use it in GitHub Desktop.
Save pbochynski/c8336c885251c77ed9fbf8e75cd4defc to your computer and use it in GitHub Desktop.
Pybrics broadcast

Pybrics hub-to-hub communication test

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:

  1. Install experimental firmware for your hubs following this guide
  2. 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)
  1. 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)

And you are done:

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)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment