Web Serial Example
This is an example of how to use the Web Serial API to connect to a serial device. It will connect to a serial device at 115200 baud and print out all data that is received.
Scenarios
Connect via bluetooth
To connect via bluetooth, you need to have a bluetooth device connected to your computer. After that, you can click the button below to connect to the serial device. The serial device will be connected to your computer and you can start sending data to it. You can also see the data that is received from the serial device. The serial device must be set to 115200 baud. You can change the baud rate in the code.
Connect via USB
To connect via USB, you need to have a USB device connected to your computer. After that, you can click the button below to connect to the serial device. The serial device will be connected to your computer and you can start sending data to it. You can also see the data that is received from the serial device. The serial device must be set to 115200 baud. You can change the baud rate in the code.
1. Flash your Arduino capable device
The Arduino could be programmed with the following
code:
Click here
void setup() {
Serial.begin(115200); // Start serial communication with 115200 baud
}
void loop() {
if (Serial.available()) { // Check whether data is available
String data = Serial.readStringUntil('\n'); // Read data up to the line break
Serial.println("Echo: " + data); // Send back the received data
}
}
Install it here directly. Reload the page, after installation!
2. Connect to the serial device
Connection
…
Port
…
Readable
…