Giter Club home page Giter Club logo

microbit-webusb-p5js's Introduction

microbit-webusb-p5js

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.

Setup

  1. Upgrade Micro:bit to latest firmware (above version 249) ** Updating your micro:bit firmware

  2. Program the Micro:bit with one of the example programs that generates serial data

  3. Setup a Web Server & Open the project's page to run the sample application. VSCode + Live Server Extention

Constructor

  • microBit=new uBitWebUSB()

Properties

  • microBit.connected

Functions

  • 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);

Examples

Check the examples folder for working examples.

UART Echo example

Learn how to exchange text messages between the microbit and a p5.js sketch via UART, update microBit's LED message from the sketch.

micro:bit code

Try it here

UART LightSensor example

Learn how to receive lightsensor value from the microbit and update a p5.js sketch via UART.

micro:bit code

Try it here

Neopixel Control example

Learn how to control the color of Neopixel LED connected to micro:bit from p5.js sketch via UART.

micro:bit code

Try it here

References

microbit-webusb-p5js's People

Contributors

didny avatar nkymut avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

pictux

microbit-webusb-p5js's Issues

use "Serial" instead of "UART"?

Should I add "Serial" to the method names instead of "UART"?

Instead of
writeUARTData()
add
writeSerialData()

to make it easier for programming beginners to understand.

micro:bit v2.2 hardware breaks communication speed

Communication speed is extremely slow and almost unusable with micro:bit v2.2,
occurring in both Windows and Mac Chrome browsers.

There is no issue with micro:bit v2.0 or earlier version of hardware.

Tried downgrading v2.2 firmware with v2.0, yet no change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.