LilyGo-T-OI-PLUS
LilyGo-T-OI-PLUS copied to clipboard
Non-USB serial connection trouble
I'm trying to connect a GPS module to the v1.3 board on pins 20 and 21.
I don't have a lot of experience using UART devices, and it makes it difficult to understand the differences between this dev board vs the raw ESP32c3 chip vs other esp32 dev boards.
- Is it possible to communicate over Serial with a device connected to the TX and RX pins AND communicate over USB Serial with my computer (Using ArduinoIDE)?
- If so, what's the correct way to use the serial pins with a device that communicates over UART? What's the correct way to declare a HardwareSerial object to communicate over the pins?
Here is the code:
#include <HardwareSerial.h>
#include <TinyGPSPlus.h>
TinyGPSPlus gps;
HardwareSerial SerialPort(2); // use UART2
void setup()
{
Serial.begin(115200);
SerialPort.begin(9600, SERIAL_8N1, 20, 21);
delay(3000);
Serial.println("beginning!");
}
void updateSerial(){
delay(500);
while (Serial.available()) {
SerialPort.write(Serial.read()); // Forward what Serial received to Software Serial Port
}
while (SerialPort.available()) {
Serial.write(SerialPort.read()); // Forward what Software Serial received to Serial Port
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid()){
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
}
void loop() {
while (SerialPort.available() > 0) {
Serial.println("SerialPort is available");
if (gps.encode(SerialPort.read())) {
displayInfo();
}
}
if (millis() > 10000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Serial.println(gps.charsProcessed());
while (true);
}
}
My output is
20:38:37.481 -> beginning!
20:38:47.491 -> No GPS detected: check wiring.
20:38:47.491 -> 0