0

I have a LoRa Click Module and Adafruit Ultimate GPS which both use Serial Communication.

I wish to just check the initial tests with all the components in on the Serial Console. Hence I have declared :

  • SoftwareSerial GPSSerial(10,11);
  • SoftwareSerial LoRaSerial(5,6);

Apparently when I declare them and upload the code on the board I do not obtain any information.

observations

  1. However when I comment out the LoRaSerial declaration I obtain the GPS coordinates.

  2. When I set the SoftwareSerial LoRaSerial(10,11) I retrieve the information.

  3. I thought 5,6 pins won't be the right choice and hence went on the set SoftwareSerial(8,9) but I retreive no information.

inference

Nano cannot take into consideration more than 1 SoftwareSerial Component. However the Official Documentation states that all Digital pins can be used for Software Serial.

Is it too much for a Nano to have overall 3 Serial ports (including Serial itself)?

sketch

#include <SoftwareSerial.h>
#include <TheThingsNetwork.h>

SoftwareSerial GPSSerial(10, 11); //RX , TX
SoftwareSerial LoRaSerial(8,9); // RX, TX (tried with 5,6 too)    
#define freqPlan TTN_FP_EU868


 TheThingsNetwork ttn(LoRaSerial, Serial, freqPlan);
void setup() {
  Serial.begin(115200);
  GPSSerial.begin(9600);
  LoRaSerial.begin(57600);
}
void loop() {
  delay(2000);
  while (GPSSerial.available()) {
    char c = GPSSerial.read();
    Serial.write(c);
  }
  delay(2000);
  while (LoRaSerial.available()) {
    ttn.showStatus();
  }
  delay(2000);
}
2

You cannot use two SoftwareSerial instances at the same time - or not for receiving anyway.

SoftwareSerial is a "last resort" system - only to be used if there is absolutely no other option. And then you need to be aware of certain information and rules:

  • Only one device can listen at any time, switchable using the SoftwareSerial::listen() method
  • When a byte is being received nothing else can happen - it takes over the entire CPU for the duration of reception
  • When a byte is being transmitted nothing else can happen - it takes over the entire CPU for the duration of transmission
  • There is a minimum required time between successive bytes when receiving that causes problems at higher baud rates

These limitations mean that, when using multiple devices, you have to know before hand which device will be sending you data so you can be ready to receive it. It also means that SoftwareSerial is effectively half duplex - it only really works properly when you are either only receiving, only transmitting, or using a "call-response" scenario like sending "AT" commands and looking for a response afterwards.

So the general recommendation is: use hardware UARTs whenever possible (and if you don't have enough, then consider using a different, more suitable, board with multiple UARTs), and if you must use SoftwareSerial then limit yourself to only one instance of it.

As a last resort you can always use multiple boards and connect them using a different system, such as I2C.

0

Sometimes, with some devices, SoftwareSerial can struggle at higher baud rates, there are quite a few posts on here about it. Would it be possible to set the LoRaSerial to 9600 too?

Can you try just the LoRaSerial on its own?

Do you have a second device, could you wire the SoftwareSerials on you Nano to two Software Serial ports on your second device and then squirt anything it receives to the hardware serial port (and then to the console). Then send some test messages from the Nano and see if the device picks them up?

ESP8266 have 2 and a half serial ports (Serial1 is Tx only), but unless you were going to hook the ESP to the Nano via I2C or use the ESP instead of the Nano, that's probably not going to help you in the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.