Can't access HardwareSerial2 unless IDE Serial Monitor is showing?

Alnitak
Posts: 4
Joined: Mon Sep 25, 2017 9:44 am

Can't access HardwareSerial2 unless IDE Serial Monitor is showing?

Postby Alnitak » Sun Nov 12, 2017 1:40 am

I'm using a Heltec WiFi Lora32 module, with a NEO-6M GPS module attached to serial 2, albeit with RX configured to use GPIO Pin 0 instead of Pin 16 since the Lora32 uses Pin 16 as its OLED Reset pin.

I've found that I can't establish communication with the GPS unless the IDE's USB serial monitor is connected (on serial 0?). Can anyone explain why?

The relevant code is as follows - without the console it always hits the 10s timeout :

Code: Select all

HardwareSerial uart(2);
U8X8_SSD1306_128X64_NONAME_SW_I2C oled(15, 4, 16);
TinyGPSPlus gps;

void setup()
{
  uart.begin(9600, SERIAL_8N1, 0, 17);

  oled.begin();
  oled.setFont(u8x8_font_victoriamedium8_r);
  oled.drawString(0, 0, "Listening");
}

void loop()
{
  while (uart.available() > 0) {
    if (gps.encode(uart.read())) {
      displayInfo();
    }
  }

  if (millis() > 10000 && gps.charsProcessed() < 10)
  {
    oled.drawString(0, 0, "No GPS detected");
    while(true);
  }
}

Alnitak
Posts: 4
Joined: Mon Sep 25, 2017 9:44 am

Re: Can't access HardwareSerial2 unless IDE Serial Monitor is showing?

Postby Alnitak » Thu Nov 23, 2017 2:15 pm

This appears to be an interaction with an existing usage of Pin 0 itself, although it's unclear to me from the Lora32 pinout exactly which function I overloaded.

I moved the Serial RX to GPIO pin 23 instead, and now all works fine.

Who is online

Users browsing this forum: No registered users and 61 guests