CubeCell-AB02 without LoRaWan_APP.h

Can CubeCell-AB02 be used with another LoRa library than that which comes with LoRaWan_APP.h?
In my case I wanted to use RadioLib. Intention was to be able to detect CRC errors when packets are received. My program (a LoRa receiver) worked fine until I tried to show something on the display. I couldn’t translate the program successfully any longer after including LoRaWan_APP.h, which in my opinion is required to use the display.
Achim

RadioLib should be usable - what’s the problem with it?

I’m not suggesting that you should persevere with the LoRaWan_APP library, but it is not required to use the display. It may be that you’ve bumped into the problem described in the following post.

Program runs nicely on CubeCell AB01 and AB02 with

//#include “LoRaWan_APP.h”
//#include “cubecell_SH1107Wire.h”
//extern SH1107Wire myDisplay;

//myDisplay.init();

With:
#include “LoRaWan_APP.h”
#include “cubecell_SH1107Wire.h”
extern SH1107Wire myDisplay;

myDisplay.init();

I get the error message:

C:\Users\achim\AppData\Local\Arduino15\packages\CubeCell\hardware\CubeCell\1.2.0/cores/asr650x/device/sx126x/sx126x.h:36:53: error: expected unqualified-id before numeric constant
#define SX1262 2
^
Here the program:

// include the library
#include <RadioLib.h>

#include “LoRaWan_APP.h”

#include “cubecell_SH1107Wire.h”
extern SH1107Wire myDisplay;

// SX1262 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
//SX1262 myRadio = new Module(10, 2, 3, 9);

// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1262 myRadio = RadioShield.ModuleA;

// or using CubeCell
SX1262 myRadio = new Module(RADIOLIB_BUILTIN_MODULE);

float vr = 0; // remote voltage

void setup() {
Serial.begin(9600);

myDisplay.init();

// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing … "));
int myRadioStat = myRadio.begin();
if (myRadioStat == RADIOLIB_ERR_NONE) {
Serial.println(F(“success!”));
} else {
Serial.print(F("failed, code "));
Serial.println(myRadioStat);
while (true);
}
myRadioStat = myRadio.setFrequency(867.9);
if (myRadioStat == RADIOLIB_ERR_NONE) {
Serial.println(F(“success!”));
} else {
Serial.print(F("failed, code "));
Serial.println(myRadioStat);
while (true);
}
myRadioStat = myRadio.setBandwidth(125.0);
if (myRadioStat == RADIOLIB_ERR_NONE)
{
//Serial.println(“setBandwidth: success!”);
}
else
{
Serial.print("setBandwidth failed, code ");
Serial.println(myRadioStat);
while (true);
}
myRadioStat = myRadio.setSpreadingFactor(7);
if (myRadioStat == RADIOLIB_ERR_NONE)
{
//Serial.println(“setSpreadingFactor: success!”);
}
else
{
Serial.print("setSpreadingFactor failed, code ");
Serial.println(myRadioStat);
while (true);
}
myRadioStat = myRadio.setCodingRate(5);
if (myRadioStat == RADIOLIB_ERR_NONE)
{
//Serial.println(“setCodingRate: success!”);
}
else
{
Serial.print("setCodingRate failed, code ");
Serial.println(myRadioStat);
while (true);
}

// set the function that will be called
// when new packet is received
myRadio.setPacketReceivedAction(setFlag);

// start listening for LoRa packets
Serial.print(F("[SX1262] Starting to listen … "));
myRadioStat = myRadio.startReceive();
if (myRadioStat == RADIOLIB_ERR_NONE) {
Serial.println(F(“success!”));
} else {
Serial.print(F("failed, code "));
Serial.println(myRadioStat);
while (true);
}
}

// flag to indicate that a packet was received
volatile bool receivedFlag = false;

// this function is called when a complete packet
// is received by the module
// IMPORTANT: this function MUST be ‘void’ type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// we got a packet, set the flag
receivedFlag = true;
}

void loop()
{
// check if the flag is set
if(receivedFlag)
{
// reset flag
receivedFlag = false;
Serial.println(“Package received”);
// you can read received data as an Arduino String
/*
String str;
int myRadioStat = myRadio.readData(str);
*/
// you can also read received data as byte array
byte byteArr[30];
int numBytes = myRadio.getPacketLength();
int myRadioStat = myRadio.readData(byteArr, numBytes);

if (myRadioStat == RADIOLIB_ERR_NONE) 
{
  // packet was successfully received
  Serial.println(F("[SX1262] Received packet!"));

  // print data of the packet
  Serial.print(F("[SX1262] Data:\t\t"));
  for (int i=0; i < numBytes; i++)
  {
    Serial.print("0x");
    Serial.print(byteArr[i], 16);
    Serial.print(" ");
  }
  Serial.println();
  // all other plausibility chacks omitted ...
  if (byteArr[1] == 'R')
  {
    vr = ((float)(256*byteArr[2] + byteArr[3]))/1000.;
    Serial.print("vr: ");
    Serial.println(vr);
  }
} 
else 
if (myRadioStat == RADIOLIB_ERR_CRC_MISMATCH) 
{
  // packet was received, but is malformed
  Serial.println(F("CRC error!"));

} else {
  // some other error occurred
  Serial.print(F("failed, code "));
  Serial.println(myRadioStat);

}

}
}

void displayItems(int16_t rssi, int8_t snr)
{
int i;
char voltageR[] = “R:9.9”;

dtostrf(vr / 1000., 3, 1, &voltageR[2]); // received voltage
/*
myDisplay.clear();
myDisplay.setFont(ArialMT_Plain_10);
myDisplay.drawString(26, 0, voltageR);
myDisplay.display();
*/
}

To my knowledge, when using the AB02 display the following lines have to be included:

#include “LoRaWan_APP.h”
#include “cubecell_SH1107Wire.h”
extern SH1107Wire myDisplay;

I could imagine, if there were a separate library just for the AB02 display, the problem would not occur.

Achim

That error would appear to be something to do with the SX1262 driver code…

In the version of the sx126x.h file on my system (which appears to be identical to the version currently available in GitHub), the first few lines of code (there are several lines of comments preceding this) are as follows:

#ifndef __SX126x_H__
#define __SX126x_H__

#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include “gpio.h”
#include “spi-board.h”

#define SX1261 1
#define SX1262 2

In your case, it looks like the compiler is complaining about something in the line preceding

#define SX1262 2

I note that this is line 35 in my version of this file, but it would appear to be line 36 in your version. It might be worth having a look at that to see if there’s something there that’s not quite right.

Just for the record though, the libraries and display instantiation that I use are:

#include “LoRa_APP.h” // (or LoRaWan_APP.h)
#include <HT_SH1107Wire.h> // CubeCell Plus display library

// The CubeCell Plus Display object
SH1107Wire myDisplay(0x3c, 500000, SDA, SCL, GEOMETRY_128_64, GPIO10); // addr, freq, sda, scl, resolution, rst

then

myDisplay.init();
etc.

But I will certainly be having a look at the RadioLib option that @bns has been discussing in the near future.

1 Like

My investigation also lead to the line
#define SX1262 2
where the arrow in the error message points to the character ‘2’.

However, if the display is not used and therefore is not referenced, the program compiles and runs perfectly! This could lead to the assumption that including the display software results in a conflict between

  • SX1262 symbol of the RadioLib and
  • SX1262 definition in the sx1262.h file, which is provided by SemTech

This again could lead to the conclusion that a library for only the display would help. In this case the SemTech file sx1262.h would not be included.

Achim

OK, the formatting of the error message in the post above didn’t place the “^” where it should have been.

I’m not sure where the cubecell_SH1107Wire.h library comes into the picture though, so maybe just try using the HT_SH1107Wire.h library as noted above (it’s included in the CubeCell support files). That should be fine.

@UniquePete:
Thank you so much for your help!
Including “HT_SH1107Wire.h” resulted in
“SX126x_Receive:11:27: fatal error: HT_SH1107Wire.h: No such file or directory”

I will give up now. CRC detection is not crucial for my application. And life is too short in waisting so much time searching just for a library.

Achim

All I can conclude from that is that you don’t have the current CubeCell software installed…

If you look in the current GitHub repository:

https://github.com/HelTecAutomation/CubeCell-Arduino

it’s there in the directory libraries/DISPLAY/src. The README.md file contains all the relevant installation instructions.

See my reply here.

From the source code, it looks like you can attach a callback using Heltec’c CubeCell library in case a CRC-error happens.

@yen: Thank you for your hint! I added a callback routine pointed by RadioEvents.RxError as you proposed and now I am able to distinguish between good packets and those with receive errors.

Your help is greatly appreciated!

Regards Achim