WebSerial Example

This page sends out a serial port using the WebSerial API. It should work on Chrome and Edge browsers.

To open a port, Click the "open port" button and pick a port. To close that port, click the button again. You can open and close the port multiple times, but you can only open one port at a time. This page sends and receives ascii-encoded strings. There's also a commented-out option showing how to parse a string as a JSON ojbect.

As of 15 May 2022, the webserial script that this sketch is using auto-detects new serial ports and opens them. Here's an Arduino sketch that works with it.

If you'd like to see the source code, it's here on gitHub. There's an Arduino sketch in that directory that will work with this page. It will echo back whatever you send it, and once a second, it will send you the number of seconds since it started as a JSON string.

Here is a helpful introduction to WebSerial. Most of this script was based on that tutorial.

If you want to see a version in p5.js, click here, and here is the source code.


Latest input from the serial port: no input yet
Seconds passed:no seconds yet
Slide the slider:
Type a string, then hit enter: