Skip to content

Commit 28a92ea

Browse files
committed
webusb_serial work well
1 parent 8402487 commit 28a92ea

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

examples/WebUSB/webusb_serial/webusb_serial.ino

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111

1212
#include "Adafruit_TinyUSB.h"
1313

14-
/* This sketch demonstrates WebUSB
14+
/* This sketch demonstrates WebUSB as web serial with Chrome browser.
15+
* After enumerated successfully, Chrome will pop-up notification
16+
* with URL to landing page, click on it to test
17+
* - Click "Connect" and select device, When connected the on-board LED will litted up.
18+
* - Any charaters received from either webusb/Serial will be echo back to webusb and Serial
19+
*
20+
* Note:
21+
* - The WebUSB landing page notification is currently disabled in Chrome
22+
* on Windows due to Chromium issue 656702 (https://crbug.com/656702). You have to
23+
* go to https://adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial to test
24+
*
25+
* - On Windows 7 and prior: You need to use Zadig tool to manually bind the
26+
* WebUSB interface with the WinUSB driver for Chrome to access. From windows 8 and 10, this
27+
* is done automatically by firmware.
1528
*/
1629

1730
// USB WebUSB object
@@ -40,10 +53,23 @@ void setup()
4053
Serial.println("Adafruit TinyUSB WebUSB example");
4154
}
4255

56+
// function to echo to both Serial and WebUSB
57+
void echo_all(char chr)
58+
{
59+
Serial.write(chr);
60+
// print extra newline for Serial
61+
if ( chr == '\r' ) Serial.write('\n');
62+
63+
usb_web.write(chr);
64+
}
65+
4366
void loop()
4467
{
45-
// delay(1000);
46-
// digitalWrite(LED_BUILTIN, 1-digitalRead(LED_BUILTIN));
68+
// from WebUSB to both Serial & webUSB
69+
if (usb_web.available()) echo_all(usb_web.read());
70+
71+
// From Serial to both Serial & webUSB
72+
if (Serial.available()) echo_all(Serial.read());
4773
}
4874

4975
void line_state_callback(bool connected)

0 commit comments

Comments
 (0)