[Resolved] Code does not compile for Grove UART on WIO GPS Tracker

I figured out how to get the Grove UART to work on the WIO GPS Tracker (I suspect it is the same for many Seeed boards), here is the code for it.

I also resolved the problem with Seeed demos for the same board not compiling because of error: SerialDBG’ was not declared in this scope (#define SerialUSB Serial)



The secret to getting the Grove UART port to work was declaring the hardware uart on those pins and putting them into one of their alternative modes.



This demo assumes you have connected the Grove UART to something with a text display, I used a typical USB to serial cable and opened Tera Term to watch the output from the Grove serial port. Then I can type in the Serial Monitor in the Arduino IDE and type things out to the serial port and see that appear on my terminal to check all the connections.

[code]

#include “wiring_private.h” // pinPeripheral() function

// Instantiate the Serial2 class
Uart Serial2(&sercom1, 31ul, 30ul, SERCOM_RX_PAD_3, UART_TX_PAD_2);

void SERCOM1_Handler()
{
Serial2.IrqHandler();
}

void setup()
{
Serial.begin(115200); // FYI: I fixed this scope error in some WIO libraries with: #define SerialUSB Serial

//getting Grove UART port on WIO GPS Tracker
//Power the port
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);

// Assign pins 44 & 45 SERCOM functionality
pinPeripheral(44, PIO_SERCOM_ALT);
pinPeripheral(45, PIO_SERCOM_ALT);

Serial2.begin(9600);
}

void loop()
{

if (Serial2.available())
{
Serial.println(Serial2.read(), HEX);
}
if (Serial.available())
{
Serial2.write(Serial.read());
}
Serial.println(“Serial”);
Serial2.println(“Serial2”);
delay(1000);
}[/code]