LoRaWAN library for SX1262

Hello,

I have custom made board with STM32L072RB processor and SX1262 LoRaWAN module. I am trying to find a LoRaWAN library to use with Arduino project in PlatformIO.

What library would you suggest for this? I have been checking multiple well known libs like MCCI LoRaWAN LMIC, Beelan-LoRaWAN and IBM LMIC Framework but as far as I understand those does not work with SX1262 or are not maintained anymore. Also it would be a huge plus if there are some examples for this library.

I would need to be able to join LoRaWAN network using OTAA with a class-A device to submit temperature measurements once every hour and device would be in low-power mode/sleep between submits.

Thank you!

should work fine I think.

Thank you I will test with that.

I installed that lib from pio but for some reason when trying to compile I get these errors:

.pio\libdeps\savi\SX126x-Arduino\src\boards\sx126x\sx126x-board.cpp:44:1: error: 'SPISettings' does not name a type

.pio\libdeps\savi\SX126x-Arduino\src\boards\sx126x\sx126x-board.cpp:52:9: error: 'initSPI' was not declared in this scope; did you mean 'init'?

With what platformio.ini is that?

[env:savi]
platform = ststm32@17.3.0
board = custom_savi
framework = arduino
debug_tool = stlink
upload_protocol = stlink
debug_port = 127.0.0.1:3333
lib_deps =
    beegee-tokyo/SX126x-Arduino@^2.0.24
board_build.variants_dir = custom_variants

I’m basically using this as base and I’m now trying to extend it to send those BME280 measurements using LoRaWAN stack: Problem reading BME280 using I2C on custom board - #26 by maxgerhardt

Right. So that library actually implements the base SPI and timers function only for a subset of microcontrollers: nRF52, RP2040, ESP32 and ESP8266 (source). Not STM32.

I’ve attempted to give it a simple implementation using the SPI and STM32 timer libary and enabled debug statements. This makes it compile, but of course I can’t test for sure if it works. Especially unsure about the timers part.

Here’s the project (EU868 region, OTAA join).

https://github.com/maxgerhardt/savi-lorawan-test

1 Like

Thank you for providing this example project. However it still seems to either not be able to upload program with following error

err1

Or sometimes when re-opening project it is able to upload the code but it gets stuck in Reset_Handler(): and following errors/warnings are shown in Debug Console

Do you know could either of these work? It looks like these could be compatible if I understand enough

This will still need an implementation for its GPIO, SPI, RTC etc layer, unless you want to take their implementation verbatim, which might conflict with the Arduino implementation (example).

Looks promising with https://github.com/jgromes/RadioLib/tree/master/examples/LoRaWAN, check it out.

1 Like

Thanks again for input. I tried with radiolib but for some reason I don’t understand I get this error:

state = node.activateOTAA();

class “LoRaWANNode” has no member “activateOTAA”

The project from the link you posted is using version 6.5.0 of jgromes/RadioLib - the missed method was introduced in 6.6.0

1 Like

Haha that’s right. I was using new example code but Radiolib in pio library manager was probably updated to new version after I installed it first time.

Managed to get past radio.begin(); and node.beginOTAA(joinEUI, devEUI, nwkKey, appKey); but seems to get stuck on node.activateOTAA();

I probably have wrong SPI pin configuration or wrong OTAA join information but I have hard time debugging with only SWD port available :sweat_smile:

Sorry for asking even though this is not strictly related to any library but I have this Waveshare-SX1262 hooked to processor in this way:

and in savi-lorawan-radiolib\custom_variants\SAVI\variant_SAVI.h I have SPI pins defined like this:

// SPI Definitions
#ifndef PIN_SPI_SS
#define PIN_SPI_SS PA4
#endif
#ifndef PIN_SPI_MOSI
#define PIN_SPI_MOSI PA7
#endif
#ifndef PIN_SPI_MISO
#define PIN_SPI_MISO PA6
#endif
#ifndef PIN_SPI_SCK
#define PIN_SPI_SCK PA5
#endif

So does this configuration look correct in savi-lorawan-radiolib/blob/main/include/config.h#L39?

// SX1262  pin order: Module(NSS/CS, DIO1, RESET, BUSY);
SX1262 radio = new Module(20, 16, 24, 25);

Using breakpoints I have the feeling that Radiolib is not able to detect or communicate with SX1262 module :thinking:

Thank you in advance

To vreify the pins, have you manually written some code to just use the SPI.h library to read a register from the SX1262? (reset must of course be driven in the right direction for the chip to respond).

See https://www.mouser.com/datasheet/2/761/DS_SX1261-2_V1.1-1307803.pdf and

1 Like

Thank you again! I will try to verify with code first

Hello again!

I updated my project to use regular lora to start with simpler way of verifying that sending messages work. At the moment I am able to successfully call radio.begin() with following pins when creating radio module:

SX1262 radio = new Module(PA4, PA3, PC4, PC5);

Where PA4 and PC4 were required for this to work. I think this is enough to verify that Radiolib is able to detect my lora module. However I am not able to transmit messages and it will always give status code -5 (RADIOLIB_ERR_TX_TIMEOUT) for state when calling radio.transmit()

I can inspect following values from radio object in inspector after calling radio.begin()

For some reason chipType says “SX1261” even I am using SX1262

My first assumption is that maybe I have wrong pins declared when creating radio but I don’t understand which should I put there and how is it able to detect lora module with PA4 and PC4 in place :thinking:

This is just a fixed string, you can ignore it

So this one should come from

So it doesn’t see the interrupt pin go HIGH.

Based on this example

and this code

The pin order is Chipselect/NSS, then IRQ, then reset, then “GPIO” pin, which the SX126x code expects to be the BUSY pin.

Thus, in accordance to your schematics the module should be constructed as

SX1262 radio = new Module(PA4, PA3 /* DIO1 if swapped */, PC4, PC5);

which is th esame as you have… so maybe try PA2 instead instead of PA3 if DIO1 and DIO2 are maybe not swapped?

Also this seems to be important to have turned on and be PA0, PA1?

Thank you again. This was a good catch that I totally missed. It still seems to give -5 for status but I will spend some time trying to debug :+1: