Grove LoRa Radio Compile Error

I want to use the Grove LoRa Radio library using SoftwareSerial.
And I get the following error:

sketch\rf95_client.ino.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\rr\AppData\Local\Temp\arduino_modified_sketch_514036/rf95_client.ino:18: undefined reference to `RH_RF95<SoftwareSerial>::RH_RF95(SoftwareSerial&)'
sketch\rf95_client.ino.cpp.o: In function `setup':
C:\Users\rr\AppData\Local\Temp\arduino_modified_sketch_514036/rf95_client.ino:42: undefined reference to `RH_RF95<SoftwareSerial>::init()'
C:\Users\rr\AppData\Local\Temp\arduino_modified_sketch_514036/rf95_client.ino:54: undefined reference to `RH_RF95<SoftwareSerial>::setFrequency(float)'
sketch\rf95_client.ino.cpp.o: In function `loop':
C:\Users\rr\AppData\Local\Temp\arduino_modified_sketch_514036/rf95_client.ino:61: undefined reference to `RH_RF95<SoftwareSerial>::send(unsigned char*, unsigned char)'
C:\Users\rr\AppData\Local\Temp\arduino_modified_sketch_514036/rf95_client.ino:71: undefined reference to `RH_RF95<SoftwareSerial>::recv(unsigned char*, unsigned char*)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Seeeduino Wio Terminal.

My code:

#include <RH_RF95.h>
#include <SoftwareSerial.h>

SoftwareSerial SSerial(0, 1); // RX, TX
#define COMSerial SSerial
#define ShowSerial Serial

RH_RF95<SoftwareSerial> rf95(COMSerial);

void setup() {
    ShowSerial.begin(115200);
    ShowSerial.println("RF95 client test.");

    if (!rf95.init()) {
        ShowSerial.println("init failed");
        while (1);
    }

    // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

    // The default transmitter power is 13dBm, using PA_BOOST.
    // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
    // you can set transmitter powers from 5 to 23 dBm:
    //rf95.setTxPower(13, false);

    rf95.setFrequency(434.0);
}

void loop() {
    ShowSerial.println("Sending to rf95_server");
    // Send a message to rf95_server
    uint8_t data[] = "Hello World!";
    rf95.send(data, sizeof(data));

    rf95.waitPacketSent();

    // Now wait for a reply
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.waitAvailableTimeout(3000)) {
        // Should be a reply message for us now
        if (rf95.recv(buf, &len)) {
            ShowSerial.print("got reply: ");
            ShowSerial.println((char*)buf);
        } else {
            ShowSerial.println("recv failed");
        }
    } else {
        ShowSerial.println("No reply, is rf95_server running?");
    }

    delay(1000);
}

I also know that it is possible to use SoftwareSerial on Wio Terminal.
Is there a solution?

@salman
can you help him?I think this compilation should be fine.

Sure @Baozhu,

Hi @blizzard, I tried to compile the example code provided Grove_LoRa_433MHz_and_915MHz_RF for Wio Terminal and I didn’t found any error.

and In your code, you are using macros for the Arduino AVR architecture. since you are using WIO terminal which is an ARDUINO_SAMD_VARIANT you need to change the macros like

#define COMSerial Serial1
#define ShowSerial SerialUSB

RH_RF95<Uart> rf95(COMSerial);

The full edited code looks like this.

#include <RH_RF95.h>
#include <SoftwareSerial.h>

//SoftwareSerial SSerial(0, 1); // RX, TX
//#define COMSerial SSerial1
//#define ShowSerial Serial
//RH_RF95<SoftwareSerial> rf95(COMSerial);



#define COMSerial Serial1
#define ShowSerial SerialUSB

RH_RF95<Uart> rf95(COMSerial);

void setup() {
  ShowSerial.begin(115200);
  ShowSerial.println("RF95 client test.");

  if (!rf95.init()) {
    ShowSerial.println("init failed");
    while (1);
  }

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  //rf95.setTxPower(13, false);

  rf95.setFrequency(434.0);
}

void loop() {
  ShowSerial.println("Sending to rf95_server");
  // Send a message to rf95_server
  uint8_t data[] = "Hello World!";
  rf95.send(data, sizeof(data));

  rf95.waitPacketSent();

  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000)) {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len)) {
      ShowSerial.print("got reply: ");
      ShowSerial.println((char*)buf);
    } else {
      ShowSerial.println("recv failed");
    }
  } else {
    ShowSerial.println("No reply, is rf95_server running?");
  }

  delay(1000);
}

Let me know your thought, Thanks

1 Like

Thanks @salman
I tested this code before. (In this example we use UART.)
But I want to use SoftwareSerial. In simpler terms, How can I use the Grove LoRa Radio library using SoftwareSerial on Wio Terminal?

PS: I also know that it is possible to use SoftwareSerial on Wio Terminal.

Here you can see that!

Yes, you can the software serial, share if you are facing any error!

Thanks, If your code is an example of SoftwareSerial, can I know where the SoftwareSerial pins are defined?

Hi, I want to test the same Grove LoRa Radio example, but I do not really understand all about serial communication stuff. I’m working with Arduino Mega carts, so is it really necessary that I use the Software Serial (which is used to simulate serial hardware, as I understand) since I have up to 4 serial ports in my Arduino?