A Javascript Library to interact with a microcontroller using USB (WebSerial)
Check the example here : https://usini.github.io/esprerial
In your HTML file add the libraries (you can either download it here, or use JSDelivr CDN)
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/usini/esprerial/dist/esprerial.min.js"></script>
// Create Esprerial with baudrate 115200 / endline= "\r\n"
serial = new Esprerial();
// Custom baudrate / endline
serial = new Esprerial(baudrate=9600, endline="\n")
<button onclick="serial.begin()">Connect</button>
function serial_read(message){
console.log(message);
}
serial.setRead(serial_read);
serial.write("Hello World");
You can also set a callback when the connection is established or if an error occurred
serial.setStart(serial_start);
serial.setError(serial_error);