ESP32 -> SWARM MODEM SERIAL COMMUNICATION ISSUES

Hello,

I have been attempting to get serial communication working on various ESPs for a bit now. I have spent many hours looking through various types of documentation, and I am hoping someone can simply fill me in on something I am fundamentally missing here.

So, my intent is to simply communicate with the Modem using an ESP8266 or a ESP32. My latest attempt is using an ESP32, this one to be particular.

https://www.amazon.ca/DIYmalls-Transcei … NrPXRydWU=

For my wiring, I have GND → GND, 5V → VIN, PIN 16 (RX) → TX0, PIN 17 (TX) → RXI. Yes I have broken the PCB jumpers, and yes I have checked via measuring continuity across them.

I have spent some time testing the output serial port (pins 16/17) of my board (by communicating with another of the same board) and have successfully sent data via serial by setting up my serial port this way "

HardwareSerial Sender(1);   // Define a Serial port instance called 'Sender' using serial port 1

#define Sender_Txd_pin 17
#define Sender_Rxd_pin 16

void setup() {
  //Serial.begin(Baud Rate, Data Protocol, Txd pin, Rxd pin);
  Serial.begin(115200);                                             // Define and start serial monitor
  Sender.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin); // Define and start Sender serial port

The above setup does appear to send data that I can receive on the other board, running a similar code, but rather opening a port (on the same pins) and listening for data coming in.

I am attempting to run any of the programs in the Swam example code (and I have added the Swarm library), espcially Example1 or Example14 and I cannot get the connection to be established. I keep getting the “Could not communicate with the modem. It may still be booting…”

I am noticing the difference between how the serial port is declared in the example

#define swarmSerial Serial1

vs mine

HardwareSerial Receiver(1);

And to get mine to work, I have been also using the "

#define Sender_Txd_pin 17
#define Sender_Rxd_pin 16

The question then becomes, how would I add in the

swarmSerial.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin);
``` equivalent??

Would it be the above code, and then add in "

bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem


after it?

Either way, I have tried it in many configurations of this code. I have tried different serial port pin declarations, different port declarations, and many attempts at getting this to work. 

Any glaring issues here, or things you would recommend I attempt? I have also tried the following to "hardcode" serial communication to the modem, to see if I could get any response. I have not yet. I'm assuming it's because I am missing fundamental things happening in the background inside the library this example code is using (My SWARM). 

Here is the "hardcode" attempt.

// Sending/Receiving example

HardwareSerial Sender(1); // Define a Serial port instance called ‘Sender’ using serial port 1

#define Sender_Txd_pin 17
#define Sender_Rxd_pin 16

const char payload=“$CS*10”;

void setup() {
//Serial.begin(Baud Rate, Data Protocol, Txd pin, Rxd pin);
Serial.begin(115200); // Define and start serial monitor
Sender.begin(115200, SERIAL_8N1, Sender_Txd_pin, Sender_Rxd_pin); // Define and start Sender serial port

}

void loop() {
//float sensor_temperature = 22.141; // Set an example value
Sender.println(payload); // Send it to Sender serial port
Serial.println(“sent”);
delay(200);
if (Sender.available()) { // Wait for the Receiver to get the characters
String received = Sender.readString(); // Display the Receivers characters
Serial.println(received); // Display the result on the serial monitor
}
else {
Serial.println(“not connected yet”);
};
delay(2000);
}


Please note, in the code above, it always prints "not connected yet" which to me means the serial port does not see active data, although it should see some from a response from the command issued just before it. I have played around with a few timings of delays (both before and after the send data command) and I have the same issue. 

... One last data point, I have confirmed the modem is still working by connecting the USB and running the Python GUI, and once I connect the jumpers again, I am able to run it like normal. 

This appears to be an issue in my serial configuration or code initialization that doesn't work.

Let me know what you think. Thanks!

Hello @ElecTheEng,

It’s tricky getting the syntax and pin definitions exactly right… Based on the things you’ve already tried, I believe the following code should work:

// #define swarmSerial Serial1 // Comment or delete this line

HardwareSerial swarmSerial(1);   // Define a Serial port instance called ' swarmSerial ' using serial port 1

#define esp_Txd_pin 17 // Labelled U2_TXD on the board pinout diagram
#define esp_Rxd_pin 16 // Labelled U2_RXD on the board pinout diagram

void setup() {
  Serial.begin(115200); // Define and start serial monitor
  swarmSerial.begin(115200, SERIAL_8N1, esp_Rxd_pin, esp_Txd_pin); // Define and start swarmSerial port. Note the Rxd, Txd ordering
  bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

Note the ordering of Rxd and Txd in the swarmSerial begin. Rx comes before Tx. Just for interest, Serial begin is defined here:

https://github.com/espressif/arduino-es … ial.h#L109

If the above doesn’t work, get back in touch and we’ll try and help further. Please let us know which Espressif ESP32 board package you have installed. v2.0.5 is the latest. Please also let us know which board definition you are using. ESP32 Dev Module? Or something else?

Best wishes,

Paul

Hello,

Unfortunately I have the same issue. I have tried reversing the RX TX each time I attempt as well, to see if the declaration may be wrong.

I have this modem / dev setup https://www.sparkfun.com/products/19236

The board library I am using is Heltec ESP32 Series Dev-Boards Version 0.0.5. I am selecting the WiFi Lora 32 board.

One other data point. I ran more tests tonight and have got a new message, see below. This is using the extended debugging mode (adding in the commented debugging mode).

sendCommandWithResponse: ====>
sendCommand: Command: $CS*10

waitForResponse: $RT RSSI=-110*1d
$RT RSSI=-110*1d

sendCommandWithResponse: <====
Could not communicate with the modem. It may still be booting...

Is it just me, or is it strange that it shows what appears to be a response, but yet shows that I could not communicate with the modem?

OK. Well, it is half-working…! You must have enabled the RT RSSI messages when you were using USB and the GUI? The messages stay enabled until you disable them again. “Receive Test Stop” (RT 0) will disable those again.

The library begin function sends a “CS” message to the modem and expects a CS message in return (something like $CS DI=0x00e57,DN=M138*43). It will ignore the RT messages while it looks for the CS reply. If it does not get a CS reply within a timeout, it thinks the modem is not connected.

I’m guessing there is a problem with the link from your ESP32 TX pin to the modem’s RXI pin. (We know modem TXO to ESP32 RX is working.) Or the pin numbering through the Heltec ESP32 board package is not as expected. Or the Heltec board uses those pins for something else? Or you have two things connected to the modem RXI pin? (I know you said you opened the jumpers and checked with a meter, but if the CH340 TXO was still connected, that would cause problems.)

This won’t help - if you try to use the OLED at the same time:

Screenshot 2022-12-07 090714.jpg

You can try a simple loop-back test to confirm if the TX and RX pins are working. Disconnect the Swarm modem and then use a jumper wire to link pin 16 to 17. Run this code:

HardwareSerial swarmSerial(1);   // Define a Serial port instance called ' swarmSerial ' using serial port 1

#define esp_Txd_pin 17 // Labelled U2_TXD on the board pinout diagram
#define esp_Rxd_pin 16 // Labelled U2_RXD on the board pinout diagram

void setup() {
  Serial.begin(115200); // Define and start serial monitor
  swarmSerial.begin(115200, SERIAL_8N1, esp_Rxd_pin, esp_Txd_pin);
}

void loop() {
  swarmSerial.println("Hello");
  delay(100);
  while (swarmSerial.available()) {
    Serial.write(swarmSerial.read());
  }
}

I hope this gets you going,

Paul

I’m probably stating the obvious, but just in case… commands must be terminated with \n. Maybe your send function appends it by default, but if not then you must do it.

I’d suspect that issue if you’re receiving messages (like the RTs) but can’t get a response to any of your commands.

I got burned on this myself - about 7 of my commands were working great but 1 was just ignoring everything I tried. Then I realized I’d forgotten the \n.

Hello @ElecTheEng,

I don’t think this explains the issue you were seeing, but we have just fixed an error in the Swarm library:

https://github.com/sparkfun/SparkFun_Sw … ag/v1.1.10

It’s possible that if you had a lot of unsolicited messages enabled, then the begin CS message checksum calculation may have been failing as it was being performed on the wrong data. If you’re still having issues, please do update to v1.1.10 and retest.

Best wishes,

Paul

Serial1 has given me some similar headache in the past (on other projects), Maybe this issue is happening because serial 1 is being mapped to the same pins as serial2? (which automatically expands to pins 16 and 17).

Also i like to use the esp GPIO type for setting the pin number (GPIO_NUM_xx), and make sure that the pins you are using are output capable for TX)and at input capable for the RX.