Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pxt-robotpu-gamepad

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.

Supported targets

for PXT/microbit

Usage

  1. Create a new micro:bit MakeCode project.
  2. Add this extension by URL:
    • https://github.com/robotgyms/pxt-robotpu-gamepad
  3. In the on start block add:
    • set radio channel to (optional)
    • set robot name to (optional)
    • start Robot PU gamepad

Available blocks

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

How the gamepad works

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.

Value messages

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.

String messages

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.

Robot Pu receiver

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)
})

BLE bridge

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.

Default controls

  • Joystick on P1 and P2 sends #puspeed and #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

Development with Makefile

This repository includes a Makefile to wrap common PXT and release commands.

Build and compile check

make build

This runs:

pxt target microbit
pxt install
pxt build

You can also use make check or make test as aliases for make build.

Clean local build output

make clean

This removes the local built/ directory.

Release a new version

make release VERSION=v0.1.0

This will:

  1. Run the build.
  2. Update the version key in pxt.json.
  3. Stage all changes.
  4. Create a git commit named Release v0.1.0 if there are staged changes.
  5. Push the commit to origin.
  6. Create and push the release tag.

Other useful targets

  • make target — install or refresh the MakeCode micro:bit target
  • make install — install package dependencies
  • make tag VERSION=v0.1.0 — create a local git tag
  • make 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.

Tutorials

See the tutorials folder for lesson guides:

  • hello-robotpu.md — basic remote control
  • gamepad-controls.md — joystick, buttons, and gesture controls
  • radio-control-protocol.md — radio commands and how the gamepad talks to Robot PU
  • how-gamepad-works.md — deep dive into the gamepad driver and protocol internals
  • game-space-invader.md — play Space Invaders game with Robot Pu
  • game-hid-and-seek.md — regain control of Robot Pu when it changes radio channels to hide from you
  • gesture-pointer-chatbox.md — V2 logo touch chatbox

Supported hardware

  • micro:bit V1 and V2 (the base gamepad does not use V2-only features)
  • Some tutorials such as gesture-pointer-chatbox.md require the micro:bit V2 touch logo

License

MIT

About

MakeCode extension for the Robot PU radio gamepad. Control a Robot PU robot from a second micro:bit using joystick, buttons, tilt gestures, and custom radio commands.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages