A javascript library to interact with BBC micro:bit and p5.js over WebUSB
A javascript library to interact with BBC micro:bit using web usb API.
Based on the library created by bsiever/microbit-webusb and updated to provide the same API for UART properties as nkymut/microbit-webble-p5js and enabled easy transition from WebUSB to WebBluetooth development interoperability.
Upgrade Micro:bit to latest firmware (above version 249) ** Updating your micro:bit firmware
microBit=new uBitWebUSB()
microBit.connected
microBit.connectDevice()
Search for WebUSB devices and connect.
example:
connectButton = createButton("connect");
connectButton.mousePressed(
function(){
microBit.searchDevice();
}
);
microBit.onConnect(callbackFunction)
Register a callback function invoked when the microBit connects
example:
microBit.onConnect(
function(){
console.log("connected");
}
);
microBit.onDisconnect(callbackFunction)
Register a callback function invoked when the microBit disconnects
example:
microBit.onDisconnect(
function(){
console.log("disconnected");
}
);
microBit.onReceiveUART(callbackFunction)
microBit.onReceiveSerial(callbackFunction)
microBit.setReceiveUARTCallback(callbackFunction)
Register a callback function to be invoked when UART data is received.
example:
microBit.setReceiveUARTCallback(
function(data){
console.log("UART received",data);
receivedText = data;
}
);
microBit.writeUARTData(string)
Send text line to microbit via UART.
example:
var messageText = "Hello!";
microBit.writeUARTData(messageText);
microBit.sendSerial(string)
Send text line to microbit via UART. an alias of writeUARTData()
example:
var messageText = "Hello!";
microBit.sendSerial(messageText);
Check the examples folder for working examples.
Learn how to exchange text messages between the microbit and a p5.js sketch via UART, update microBit’s LED message from the sketch.
Learn how to receive lightsensor value from the microbit and update a p5.js sketch via UART.
Learn how to control the color of Neopixel LED connected to micro:bit from p5.js sketch via UART.
bsiever/microbit-webusb:WebUSB Utils for Micro:bit (( live DEMO