# Example of WebUSB being used by Browser Based App to communicate with a Microbit

**URL:** https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808
**Category:** micro:bit
**Created:** [January 11, 2024, 5:38pm UTC](https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808 "2024-01-11T17:38:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![broadside](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@broadside](https://forum.makecode.com/u/broadside)
#### Post date: [January 11, 2024, 5:38pm UTC](https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808/1 "2024-01-11T17:38:56Z")

</div>

Our STEM club has a couple of projects in mind that required a Browser based App (HTML/javascript etc) to communicate serially with a Microbit.

Microbit help/support suggests using webUSB as a channel - using (I assume) WebUSB serial.js

However I’ve not succeeded in finding any working examples to learn from.

Can anyone point us in a useful direction?

Thanks in advance

---

<div class="post-metadata">

### Author: ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)
#### Post date: [January 12, 2024, 5:39pm UTC](https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808/2 "2024-01-12T17:39:53Z")

</div>

Hi @broadside & welcome to the forum,

I created a WebUSB library for the micro:bit that a few others have used. It was really meant for graphing applications and treats messages with a colon, like “x:5”, specially.

You’re welcome to use it or review the code for inspiration: [https://github.com/bsiever/microbit-webusb](https://github.com/bsiever/microbit-webusb). The repository includes a working example of a basic console and docs:

- [live demo “console”](https://bsiever.github.io/microbit-webusb/) (note that browsers can only have one tab communicating with a device. May need to close a MakeCode or Python tab/connection to use);
- [index.html source](https://github.com/bsiever/microbit-webusb/blob/master/index.html), which contains the basic JavaScript calls to the library for the demo;
- [JSDoc documentation pages](https://bsiever.github.io/microbit-webusb/docs/); and
- [repo readme.md](https://github.com/bsiever/microbit-webusb/blob/master/readme.md).
  - [MakeCode Demo Program](https://github.com/bsiever/microbit-webusb/blob/master/readme.md#program-the-microbit-from-shared-project) (a simple program that makes the micro:bit read/write to serial and can be used for testing the demo page).

Originally it was a stand alone library. Unfortunately, the micro:bit v2.2 boards weren’t compatible, so I decided to make it a wrapper around [DAPjs](https://github.com/ARMmbed/dapjs) (using DAPjs seemed more robust).

---

<div class="post-metadata">

### Author: ![broadside](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@broadside](https://forum.makecode.com/u/broadside)
#### Post date: [January 12, 2024, 11:16pm UTC](https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808/3 "2024-01-12T23:16:52Z")

</div>

You beat me to it!!! I just came here to point everyone to your Github page! I found your page earlier, and had it working in minutes.

Thank you very much for documenting this, and the work you put into it

It works really well for what we have in mind - and a great starting point for our next projects (the first is connecting to an RFID reader/writer, the second is to implement a better controller for lighting a very large model of a future Mars colony!!)

Ken

---

<div class="post-metadata">

### Author: ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)
#### Post date: [January 17, 2024, 6:10pm UTC](https://forum.makecode.com/t/example-of-webusb-being-used-by-browser-based-app-to-communicate-with-a-microbit/25808/4 "2024-01-17T18:10:47Z")

</div>

@broadside Great — I’m happy to hear people are finding it useful! Feel free to let me know if you have any questions. I know some users have removed the part that parses the key/value pairs used for graphing because it wasn’t suitable for their purposes.

If you have a chance, please post details of your work here when you’re done. It sounds like a fun project. I sometimes teach IoT topics, including integrating with things like RFID readers. I enjoy seeing those sorts of projects.

Bill
