MBC PS2 / PS4 Controller receiver × micro:bit (MakeCode)

Read a gamepad with a micro:bit in three steps

In MakeCode for micro:bit, first add the MBC extension, then wait for the receiver in "on start", and last put button and joystick blocks into "forever". The PS2 and PS4 receivers use the same blocks. Follow the steps on the left, and the blocks on the right grow with you. The block pictures come from MakeCode's own renderer, so they look the same as in the editor. Switch to JavaScript at the top right, just like the switch in MakeCode.

MakeCode is free and needs no login. Open it in Chrome or Edge. Click "Download" to save a .hex file and drag it onto the micro:bit.

1

Add the MBC extension and wire it up

The micro:bit does not know the Controller yet. After you add the MBC extension, an "MBC Sensors" category appears, and the gamepad blocks are in its "Gamepad" group. Pick your micro:bit version and your receiver first; the hardware check below changes with them.

Which micro:bit do you have? (V2 has "V2" printed on the back)
Which receiver do you have?
  1. Open MakeCode and click "New Project".
  2. At the bottom of the toolbox, click "Advanced" → "Extensions".
  3. Paste https://github.com/contactmbcrobot/pxt-mbc-sensors into the search box, press Enter and click mbc-sensors.
  4. The blocks are in English. (Traditional Chinese is also included in the extension.)
  5. Pair the gamepad with the receiver first (the receiver light shows when it is connected).
2

On start: wait for the receiver

The receiver needs a moment to start. The program first waits until it is ready: tick = connected, cross = not connected. A tick only means the receiver is wired up. To check the gamepad itself, use "gamepad is connected".

I2C address of the sensor
  1. From "Logic", drag "if … then … else" into "on start".
  2. From "MBC Sensors" → "more", drag "wait for device at … ready, timeout … ms" into the condition. Pick 66 (0x42) and type 3000.
  3. From "Basic", drag two "show icon" blocks: one tick, one cross.
  4. Put "pause 100 ms" into "forever".

3

Use the button and joystick blocks

The "MBC Sensors → Gamepad" group has blocks for buttons, joysticks, triggers, gamepad state and events, plus battery, rumble and light bar (PS4 only). The "Device" group has shared blocks that every MBC sensor has. Pick one, and the blocks and the output switch to its example.

Gamepad simulator: click the buttons, drag the joysticks and watch the output on the right

The simulator is only a picture. Click a button once to hold it and again to release it. Drag a joystick dot to move it (it stays where you let go; "Release all" centres it). Joysticks give −100 ~ +100, 0 = centre, right and up are positive. The PS4 battery is fixed at 80 as an example. The PS and capture buttons appear only for PS4 / PS5.

An example for every block

Every block of the Gamepad group and the Device group has an example you can copy (address 0x42). In the "PS4 only" group, the PS2 receiver reads 0 and ignores the commands. Click "Try it" to jump to step 3, and the blocks and output on the right switch to that example.

Good to know

  1. Unplugging does not stop the program: when the receiver cannot be read, reading blocks return 0 (true/false blocks return false), and nothing is printed. A joystick value of 0 means "centre", so an unplugged receiver makes the robot stop instead of running away. To tell "stick not pushed" from "not connected", use "device at … is ready".
  2. When the gamepad is not connected: the receiver still answers, every button is 0, the joysticks go back to the centre (0), and "gamepad is connected" is false.
  3. Direction: right and up are positive on the joysticks, −100 ~ +100, 0 = centre. The 16 buttons use the PSX layout (bit0 of the bit mask is SELECT, bit14 is ✕).
  4. PS4 only: battery, PS / capture buttons, rumble and light bar. On the PS2 receiver, battery and system buttons are always 0, and rumble and light bar commands are ignored. A PS5 pad with the PS4 receiver reports gamepad type 4.
  5. The PS2 and PS4 receivers both use 0x42: to connect two of them to the same P19 / P20, first move one with "change device at … to address …", then pick "changed address" in step 2.
  6. JavaScript extras: mbc.readValue(66, 0x01) reads any I2C value directly (−32768 = not connected), and mbc.writeCmd(66, 0xE5, [200]) sends a command. The value ids are in the I2C reference on the product website.