FA2022 USB-D11C-serial (Arduino IDE + Xiao)¶
Set up Seeed Xiao as DAPLInk¶
Ref. How to use Arduino Boards as DAPLink Device
Install the DAPLink Arduino Libraries (Mac/PC)¶
-
Seeed_Arduino_DAPLink -> Code -> Download ZIP -> Seeed_Arduino_DAPLink-master .zip
-
Open the Arduino IDE, and click sketch -> Include Library -> Add .ZIP Library, and choose Downloads/Seeed_Arduino_DAPLink-master.zip
Install the Adafruit_TinyUSB_Arduino Library¶
- Adafruit TinyUSB Library for Arduino -> Code -> Download ZIP -> Adafruit_TinyUSB_Arduino-master.zip
Note
If you have an error caused Adafruit_TinyUSB_Library when uploading sketch to Xiao, Use Adafruit_TinyUSB_Library Version 0.10.5 .
- Open the Arduino IDE, and click sketch -> Include Library -> Add .ZIP Library, and choose Downloads/Adafruit_TinyUSB_Arduino-master.zip
Setup Xiao in Arduino¶
-
Preference -> Additional Boards Manager URLs
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
-
Tool -> Boards -> Boards manager -> Search
Xiao
- Install
Seeed SAMD Boards
Open the sketch¶
- Unzip Seeed_Arduino_DAPLink-master.zip
- Open Seeed_Arduino_DAPLink-master/examples/simple_daplink/simple_daplink.ino
Upload the sketch to Xiao¶
- Upload the sketch to Xiao
- LEDs on Xiao one green -> two blue
Set up SAMD programming environment in Arduino IDE¶
-
Preferences -> Additional Board Manager URLs:
https://www.mattairtech.com/software/arduino/package_MattairTech_index.json
-
Tools -> Boards -> Board Manager -> Search
mattairtech
orsamd
- Install
mattairtech SAM D|L|C core for Arduino
Burn bootloader¶
settings¶
- Open new sketch and select settings
Connection¶
Xiao | USB-D11C-serial |
---|---|
GND A10 A9 A8 |
GND CLK DIO RST |
Burn bootloader¶
Recognizing SAMD11C board as USB device on Mac¶
% ls /dev | grep usb
cu.usbmodem14401
cu.usbmodem14601
tty.usbmodem14401
tty.usbmodem14601
//% brew install lsusb
% lsusb
Bus 020 Device 011: ID 2886:802f 2886 CMSIS-DAP Serial: 46AE2A4950575230372E3120FF151414
Bus 020 Device 014: ID 16d0:0557 16d0 Generic SAMD11C14A
Program SAMD11C from USB Connection¶
Download SAMD11Cserial
Code -> Download ZIP
% cd Downloads
% unzip SAMD11C_serial-main.zip
% ls
SAMD11C_serial-main.zip
SAMD11C_serial-main
% cd SAMD11C_serial-main
% ls
SAMD11C_serial
SAMD21E_serial
% cd SAMD11C_serial
% ls
SAMD11C_serial.ino
% open .
Double click to open it in Arduino
/*
SAMD USB to serial
Author : Quentin Bolsee
License : CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
Date : 2020-07-27
Version :
- 0.0 : first draft
*/
//#define DEBUG
#define BAUD_DEFAULT 9600
#define PIN_TX 4
const byte config_lookup[3][2][4] = {
{{SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1},
{SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2}},
{{SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1},
{SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2}},
{{SERIAL_5E1, SERIAL_6E1, SERIAL_7E1, SERIAL_8E1},
{SERIAL_5E2, SERIAL_6E2, SERIAL_7E2, SERIAL_8E2}},
};
typedef struct {
long unsigned baud;
uint8_t paritytype; // parity: 0=none, 1=odd, 2=even, 3=mark, 4=space
uint8_t stopbits; // stopbits: 0=1, 1=1.5, 2=2
uint8_t numbits; // databits: 5,6,7,8,16
} SerialConfig;
SerialConfig current_config = {BAUD_DEFAULT, 0, 1, 8};
void update_serial(SerialConfig new_config) {
if (new_config.paritytype > 2 || !(new_config.stopbits == 0 || new_config.stopbits == 2) || new_config.numbits < 5 || new_config.numbits > 8) {
return;
}
// lookup indexes
int i = new_config.paritytype;
int j = new_config.stopbits == 2 ? 1 : 0;
int k = (int)new_config.numbits - 5;
Serial2.flush();
Serial2.end();
Serial2.begin(new_config.baud, config_lookup[i][j][k]);
current_config.baud = new_config.baud;
current_config.paritytype = new_config.paritytype;
current_config.stopbits = new_config.stopbits;
current_config.numbits = new_config.numbits;
}
void setup() {
// prevents small voltage drops when Serial is closed then opened
pinMode(PIN_TX, OUTPUT);
digitalWrite(PIN_TX, HIGH);
SerialUSB.begin(BAUD_DEFAULT);
Serial2.begin(BAUD_DEFAULT);
}
void loop() {
// Detect config change
SerialConfig new_config = {SerialUSB.baud(), SerialUSB.paritytype(), SerialUSB.stopbits(), SerialUSB.numbits()};
if (new_config.baud != current_config.baud || new_config.paritytype != current_config.paritytype ||
new_config.stopbits != current_config.stopbits || new_config.numbits != current_config.numbits) {
update_serial(new_config);
}
#ifdef DEBUG
SerialUSB.println("Settings: ");
SerialUSB.print(current_config.baud);
SerialUSB.print(", ");
SerialUSB.print(current_config.paritytype);
SerialUSB.print(", ");
SerialUSB.print(current_config.stopbits);
SerialUSB.print(", ");
SerialUSB.println(current_config.numbits);
delay(1000);
#else
char c;
if (SerialUSB.available()) {
c = (char)SerialUSB.read();
Serial2.write(c);
}
if (Serial2.available()) {
c = (char)Serial2.read();
SerialUSB.write(c);
}
#endif
}
Upload the sketch into the SAMD11C_serial board¶
Program hello.t3216.echo.into from UPDI with SAMD11C_serial boards¶
Additional Board Manager URLs: http://drazzy.com/package_drazzy.com_index.json
Board Manager
Download hello.t3216.echo.ino from class page
Connection¶
Settings and upload¶
echo¶
Connection¶
echo in serial monitor¶
Next test¶
void setup() {
SerialUSB.begin(0);
Serial1.begin(57600, SERIAL_8E2); //Adjust baud rate and use SERIAL_8N1 for regular serial port usage
}
void loop() {
if (SerialUSB.available()) {
Serial1.write((char) SerialUSB.read()); //Send stuff from Serial port to USB
}
if (Serial1.available()) {
SerialUSB.write((char) Serial1.read()); //Send stuff from USB to serial port
}
} //end loop