Solved: Lora Between CubeCell and Wifi_Lora_32_V3 - RadioLib

CubeCell Radio = SX1262
Wifi_Lora_32_V3 Radio = SX1262

As mentioned in prior posts the Lora library supplied for the Wifi_Lora_32_V3 does not work because it was written for the SX1276 radio.

I am using the newly updated RadioLib that includes SX1262 which CubeCell uses as well.

If you are using PlatformIO you don’t have to download it, you can just reference it in your platformio.ini file by adding this:

lib_deps =
jgromes/RadioLib @ ^6.2.0

PlatformIO will download it and put the lib in your pio/libdips folder for you.

My examples are pulled from JGromes examples in his excellent GitHub repo.

RadioLib

Below I will include the following:

  1. Platformio.ini file
  2. SX126x_Transmit.cpp
  3. SX126x_Receive.cpp

I have choosen to use a CubeCell as the Sender and the Wifi_Lora_32_V3 as the Receiver.

1. Platformio.ini

[env:cubecell_AB02A_ant]
framework = arduino
board = cubecell_node
platform = heltec-cubecell
monitor_speed = 115200
lib_deps =
  jgromes/RadioLib @ ^6.2.0
build_src_filter = 
	+<SX126x_Transmit.cpp>

[env:heltec_wifi_lora_32_V3]
framework = arduino
board = heltec_wifi_lora_32_V3
platform = espressif32
monitor_speed = 115200
lib_deps =
  jgromes/RadioLib @ ^6.2.0

build_src_filter = 
	+<SX126x_Receive.cpp>

[env:cubecell_AB01]
framework = arduino
board = cubecell_board
platform = heltec-cubecell
monitor_speed = 115200
lib_deps =
  jgromes/RadioLib @ ^6.2.0
build_src_filter = 
	+<SX126x_Transmit.cpp>

2. SX126x_Transmit.cpp

#include <RadioLib.h>
//
//this is for the CubeCell !!!! not the heltec_wifi_lora_32_V3
//
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);

int transmissionState = RADIOLIB_ERR_NONE;
volatile bool transmittedFlag = false;
int msgCount = 0;
int loopDelay = 2500;

void SetupRadio();
void SendMessage();
void setFlag(void);

void setup() {
  Serial.begin(115200);
  delay(3000); //take a break while serial gets it's act together.
  SetupRadio();
}

void loop() {
  SendMessage();
}

void SendMessage()
{
  if(transmittedFlag) {
    transmittedFlag = false;

    if (transmissionState == RADIOLIB_ERR_NONE) {
      Serial.println("\ttransmission finished!\r\n");
    } else {
      Serial.print(F("failed, code "));
      Serial.println(transmissionState);

    }

    radio.finishTransmit();
    delay(loopDelay);
    Serial.print(F("Sending: "));
    String msg = "Hello! #" + String(msgCount++);
    transmissionState = radio.startTransmit(msg);
    Serial.println(msg);
  }

}
void SetupRadio()
{
  Serial.print(F("Initializing ... "));
  int state = radio.begin(908.0, 500.0, 10, 5, 0x12, 10, 8);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  radio.setPacketSentAction(setFlag);
  Serial.print(F("Sending first packet ... "));
  transmissionState = radio.startTransmit("Hello!");
}
void setFlag(void) {
  transmittedFlag = true;
}

3. SX126x_Receive.cpp

#include <RadioLib.h>

//
//this is for the heltec_wifi_lora_32_V3 not the CubeCell !!!!
//
 SX1262 radio = new Module(8, 14, 12, 13);

volatile bool receivedFlag = false;
void SetupRadio();
void CheckForMsg();
void PrintMsg(String);
void SetFlag(void);


void setup() {
  Serial.begin(115200);
  delay(3000); //take a break while serial gets it's act together.
  SetupRadio();
}

void loop() {
  CheckForMsg();
}


void SetupRadio(){
  Serial.print(F("Initializing ... "));

  int state = radio.begin(908.0, 500.0, 10, 5, 0x12, 10, 8); 

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!\r\n"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  radio.setPacketReceivedAction(SetFlag);
  Serial.println(F("Starting to listen ...\r\n"));
  state = radio.startReceive();
}

void CheckForMsg(){

  if(receivedFlag) {
    receivedFlag = false;

    String msg;
    int state = radio.readData(msg);

    if (state == RADIOLIB_ERR_NONE) {
      PrintMsg(msg);

  } else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
      Serial.println(F("CRC error! malformed"));

    } else {
        Serial.print(F("failed, code "));
      Serial.println(state);
    }
  }
}

void PrintMsg(String msg){

  Serial.print(F("Data:\t\t"));
  Serial.println(msg);

  Serial.print(F("RSSI:\t\t"));
  float rssi = radio.getRSSI();
  Serial.print(rssi);
  Serial.println(F(" dBm"));

  Serial.print(F("SNR:\t\t"));
  Serial.print(radio.getSNR());
  Serial.println(F(" dB"));
  Serial.println();
}

void SetFlag(void) {
  receivedFlag = true;
}

1 Like