There are many ways to control p5.js with micro:bit. The method we are using here is to turn our micro:bit into a human interface device or HID. To put it simply, turn micro:bit into a Bluetooth keyboard or a Bluetooth mouse. This way, as long as our p5.js code works with a keyboard or a mouse, it will work with our micro:bit.

Disclaimer: Working with Bluetooth can be frustrating when pairing, disconnecting and forgetting. Do not put key presses or mouse clicks in the forever loop without a conditional (if, else) because it will automatically press or click on stuff on your computer forever. If that were to happen, disconnect the power from the micro:bit immediately (cable or battery).

We recommend you to use Chrome or Microsoft Edge for the tutorial. If you use Safari, you would need to manually download your file into micro:bit.

Setting up your micro:bit for Bluetooth HID

In order to connect to the micro:bit via Bluetooth, we need to know the device name of our micro:bit. Each micro:bit has a name made out of 5 small letters (e.g. papoz). Please follow the following tutorial in order to get the device name of your micro:bit.

Step 1: Go to makecode.microbit.org

Untitled

Step 2: Click on New Project

Untitled

Step 3: Give your project a name and click Create!

Untitled

Step 4: If it is your first time, you can take a tour of the editor by clicking Next.

Untitled

Step5: Once you are done, click Finish.

Untitled

Step 6: Click on Extensions.