I used a " Seeeduino XIAO" board as it was said here:
I found "serialUSB.print()" didn't work in "setup()", and as it was told here: SerialUSB.print() in Output
I added "while (!SerialUSB.available());", then when I plug from programming port to native USB port and "Enter" in serial monitor, I found the "serialUSB.print()" works in "setup()".
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
//Serial.print("Hello, World!");
SerialUSB.begin(115200);
while (!SerialUSB.available());
SerialUSB.print("USB - Hello, World!");
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
//SerialUSB.println("USB - Hello, World! Again!");
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
my questions are:
- Is that true, the boards based on ARM now integrated the 2 ports on DUE into one USB plug?
- The seeed recommended a test example Seeeduino-XIAO/USB-to-Serial-Port.md :
/*
This example is used for USB to ttl.
update file Arduino15\packages\Seeeduino\hardware\samd\1.6.0\cores\arduino\USB\USBAPI.h
class Serial_ : public Stream
{
public:
......
......
//add
uint32_t getBaud(void);
......
}
update file Arduino15\packages\Seeeduino\hardware\samd\1.6.0\cores\arduino\USB\CDC.cpp
//add
uint32_t Serial_::getBaud(void)
{
return _usbLineInfo.dwDTERate;
}
*/
uint32_t baud;
uint32_t old_baud;
void setup() {
// put your setup code here, to run once:
SerialUSB.begin(115200);
baud = SerialUSB.getBaud();
old_baud = baud;
Serial1.begin(baud);
while (!Serial);
while (!SerialUSB);
}
void loop() {
// put your main code here, to run repeatedly:
baud = SerialUSB.getBaud();
if (baud != old_baud) {
Serial1.begin(baud);
while (!Serial);
old_baud = baud;
// SerialUSB.println(baud);
}
if (SerialUSB.available() > 0)
{
char c = SerialUSB.read();
Serial1.write(c);
}
if (Serial1.available() > 0) {
char c = Serial1.read();
SerialUSB.write(c);
}
}
who can explain it, why so much "while***" here?