MakeCode / PXT extension for the Robot PU radio gamepad. Use this with a second micro:bit to send joystick, button, and channel commands to a Robot PU robot over the micro:bit radio.
Learn more about Robot PU at robotgyms.com/pu.
for PXT/microbit
- Create a new micro:bit MakeCode project.
- Add this extension by URL:
https://github.com/robotgyms/pxt-robotpu-gamepad
- In the on start block add:
set radio channel to(optional)set robot name to(optional)start Robot PU gamepad
| Block | Description |
|---|---|
start gamepad |
Initializes the radio, buttons, and default joystick / button handlers. |
set robot name to |
Sets the name broadcast over radio. |
set radio channel to |
Sets the radio channel and updates radio.setGroup. |
radio channel |
Returns the current radio channel. |
use default button controls |
Resets B0–B4 to the default #puB commands. |
on gamepad button [B0] pressed |
Runs custom code when a B0–B4 button is pressed. |
joystick x |
Read the left/right joystick value (-1 .. 1). |
joystick y |
Read the forward/backward joystick value (-1 .. 1). |
send speed |
|
send turn |
|
send pitch |
|
send roll |
|
send button |
The gamepad micro:bit talks to Robot Pu over the micro:bit radio protocol. Both devices must be on the same radio group (channel 0..255). Use set radio channel to (or radio channel) to keep them matched.
The gamepad continuously sends radio.sendValue(key, value) for movement and button actions:
| Key | Value | Purpose |
|---|---|---|
#puspeed |
-1 .. 1 |
Forward/backward walking speed. |
#puturn |
-1 .. 1 |
Left/right turning. |
#pupitch |
degrees | Up/down tilt of the gamepad (head pitch). |
#puroll |
degrees | Left/right tilt of the gamepad (head yaw). |
#puB |
0 .. 4 |
External action buttons B0–B4. |
#puA / #puAB |
1 |
On-board A / A+B button status. |
radio.sendString(text) is used for text, name, and trigger commands:
| Format | Purpose |
|---|---|
#put<text> |
Robot Pu says the text. |
#pun<name> |
Broadcasts the gamepad name to the robot. |
#pus<song> |
Robot Pu sings a song. |
On the robot micro:bit, forward incoming radio packets to robotPuPro:
radio.onReceivedValue(function (name, value) {
robotPuPro.runKeyValueCommand(name, value)
})
radio.onReceivedString(function (text) {
robotPuPro.runStringCommand(text)
})A phone or app can also control the gamepad through a controller micro:bit that receives BLE events and converts them into the same radio.sendValue(...) and radio.sendString(...) commands.
- Joystick on P1 and P2 sends
#puspeedand#puturn - micro:bit A / B buttons change the radio group and send
#puA/#puB - A+B sends the gamepad name and current channel
- External buttons on P8, P13–P16 send button commands
#puB 0..4
This repository includes a Makefile to wrap common PXT and release commands.
make buildThis runs:
pxt target microbit
pxt install
pxt buildYou can also use make check or make test as aliases for make build.
make cleanThis removes the local built/ directory.
make release VERSION=v0.1.0This will:
- Run the build.
- Update the
versionkey inpxt.json. - Stage all changes.
- Create a git commit named
Release v0.1.0if there are staged changes. - Push the commit to origin.
- Create and push the release tag.
make target— install or refresh the MakeCode micro:bit targetmake install— install package dependenciesmake tag VERSION=v0.1.0— create a local git tagmake push-tag VERSION=v0.1.0— push a tag to origin
Before running make release, make sure your GitHub authentication is configured and that the package meets the BBC MakeCode extension approval requirements.
See the tutorials folder for lesson guides:
hello-robotpu.md— basic remote controlgamepad-controls.md— joystick, buttons, and gesture controlsradio-control-protocol.md— radio commands and how the gamepad talks to Robot PUhow-gamepad-works.md— deep dive into the gamepad driver and protocol internalsgame-space-invader.md— play Space Invaders game with Robot Pugame-hid-and-seek.md— regain control of Robot Pu when it changes radio channels to hide from yougesture-pointer-chatbox.md— V2 logo touch chatbox
- micro:bit V1 and V2 (the base gamepad does not use V2-only features)
- Some tutorials such as
gesture-pointer-chatbox.mdrequire the micro:bit V2 touch logo
MIT