Swarm M138 - Software Serial Query - ESP32

Hello,

I have been experimenting with the Swarm M138 Transceiver Kit with an ESP32 dev kit, and have had no problems communicating with the modem via the Hardware Serial ports using the Sparkfun Arduino Library.

I noticed in the SparkFun_Swarm_Satellite_Arduino_Library.cpp file there seems to be some sort of support for communication over Software Serial. I have tried using the espsoftwareserial Arduino library (which works well with other UART devices) to initialise a software serial connection, then initialising the M138:

#include <SoftwareSerial.h>
#include <SparkFun_Swarm_Satellite_Arduino_Library.h> 
SoftwareSerial swarmSerial;
SWARM_M138 mySwarm;

#define TXD2 14
#define RXD2 13

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;  // Wait for the user to open the Serial console
  Serial.println(F("Swarm Satellite example"));

  swarmSerial.begin(115200, SWSERIAL_8N1, RXD2, TXD2);
  bool modemBegun = mySwarm.begin(swarmSerial);  // Begin communication with the modem

  while (!modemBegun)  // If the begin failed, keep trying to begin communication with the modem
  {
    Serial.println(F("Could not communicate with the modem. It may still be booting..."));
    delay(2000);
    modemBegun = mySwarm.begin(swarmSerial);
  }

I also tried to enable the software serial mode by calling: ```
#define SWARM_M138_SOFTWARE_SERIAL_ENABLED 1

However, I cannot get any method to work, and unfortunately I'm out of ideas. Is there a way to achieve this with an ESP32? Any information would be great. 

Thanks!

Hi,

We’ve noticed issues on some ESP32 boards where the RXD and TXD pin numbering definitions cause problems. Can you please try a simple loop-back test? Disconnect the modem. Use a jumper wire to link 14 to 13. Open the serial monitor. Whatever you type and send should be echoed straight back?

#include <SoftwareSerial.h>
SoftwareSerial swarmSerial;

#define TXD2 14
#define RXD2 13

void setup() {
  Serial.begin(115200);
  swarmSerial.begin(115200, SWSERIAL_8N1, RXD2, TXD2);
}

void loop(){
  if (Serial.available())
    swarmSerial.write(Serial.read());
  if (swarmSerial.available())
    Serial.write(swarmSerial.read());
}

RXD2 and TXD2 may be reserved names. Try changing them to something like pinRX and pinTX.

Thanks,

Paul

Hi,

Thanks for the quick response. So I was unable to get the loop-back test to work , however I was able to communicate between two ESP32 boards using software serial and the same pins (and names) as above, so I’m not sure what the issue might be.

Thanks

The Baud rate might be the issue. I got the SoftwareSerial loop-back test to work at 9600 Baud. But it fails at 115200…

I hope this helps,

Paul

I think you’re right, the SoftwareSerial loop back works up until 57600 Baud, but like you said it fails at 115200. The espsoftwareserial documentation claims support up to 115200, but maybe that’s more of a maximum. Is it possible to set the M138 to communicate at a lower baud rate?

Cheers

Sadly, no. The modem baud rate is fixed at 115200.

Are you sure you need software serial? ESP32 has many hardware-serial-capable pins…

You could use a second board as a speed-converter! :wink:

Best wishes,

Paul

All good, no I absolutely don’t need software serial, I’ve been using hardware serial with the M138 up until now and it works flawlessly, it was more just curiosity.

Cheers for your advice!