Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-USB serial connection trouble #35

Open
SWPhantom opened this issue Jun 2, 2024 · 0 comments
Open

Non-USB serial connection trouble #35

SWPhantom opened this issue Jun 2, 2024 · 0 comments

Comments

@SWPhantom
Copy link

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.

  1. 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)?
  2. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant