Software Serial taking lot of time (5ms++) to send over HC12

Hello,

I’m working on a, let say system, composed by a computer sending data to a transceiver (Arduino Nano), which then send via a HC12 (with softwareserial) to an other transceiver (this one a Arduino Nano Every) :

Computer — (serial) —> Arduino Nano ---- (softwareserial on HC12) ----> Arduino Nano Every

My problem is that the software serial is sometime taking a lot of time to send 7 to 31 bytes over the air (HC12), by a lot of time I mean 5000us and sometime more, while generally it took less than 2000us.

This slow transmission is always occurring when sending a lot of data within short interval. So I suspect that the problem caused by collisions or something taking to mush time. The function being sometime slow is SendOnTrx.

I know that using SoftwareSerial with Serial may not be a good way of doing things, but I didn’t find any other way of doing it so far (on Arduino Nano or Every).

Here is my code (in attachment), and below two samples log results.

Thanks !
Logs :

ONE NORMAL CALL

Call Id 40 sent.
sendOnTrx: 2840
trxReceiveData: 180
trxReceiveData: 8
trxReceiveData: 8
(Call Id 40 SUCCESS.
trxReceiveData: 36

HERE A SEQUENCE OF FAST CALLS (note the time took by sendOnTrx)

Call Id 41 sent.
sendOnTrx: 2840
trxReceiveData: 180
trxReceiveData: 8
trxReceiveData: 8
)Call Id 41 SUCCESS.
trxReceiveData: 36
Call Id 42 sent.
Call Id 43 sent.
Call Id 44 sent.
sendOnTrx: 6356
sendOnTrx: 6500
sendOnTrx: 6368
trxReceiveData: 180
trxReceiveData: 8
trxReceiveData: 8
*Call Id 42 SUCCESS.
trxReceiveData: 36
trxReceiveData: 36
trxReceiveData: 8
trxReceiveData: 8
+Call Id 43 SUCCESS.
trxReceiveData: 324
trxReceiveData: 20
trxReceiveData: 8
trxReceiveData: 8
,Call Id 44 SUCCESS.
trxReceiveData: 324
Call Id 45 sent.
sendOnTrx: 2836
trxReceiveData: 344
trxReceiveData: 8
trxReceiveData: 8
-Call Id 45 SUCCESS.
trxReceiveData: 36

USB-TRX-HC12-01.00.ino (26.2 KB)

Software serial doesn't work very well, or at all, at high baud rates, so the timing you see is about what you can expect for reliable transmission of 7 to 31 bytes.

The HC-12 is slow, too. For higher throughput, given only one hardware serial port on the smaller Arduinos, consider different radios with faster serial interfaces, like SPI.

What bit rate are you running software serial at? At 9600 it will take about 1ms per character, for example. You can divide down from there; however, running at higher bit rates with software serial may be unreliable.

jremington, any suggestion ? I thought of some SX127X, any better options ? (GitHub - sandeepmistry/arduino-LoRa: An Arduino library for sending and receiving data using LoRa radios.)

Todd, I was running at 57600, and for my requirment it's the lowest I can go, but I'm ok to test some other device.

I was running at 57600

Software Serial rarely works well at that Baud rate. I'm surprised that you seem to be successful most of the time.

It takes at least 5.4 ms to send 31 bytes at 57600 Baud (RS232-TTL serial sends 10 or 11 bits per byte, depending on the number of stop bits).

There are other options, summarized here.