Pin Assignment for LoRa transmission using RAK 4631 core module

I’m using a RAK 4631 module with a MQ2 gas sensor mounted to it. I am trying to use Lora P2P to send data to a T-Beam. Initially, I tried to use the SX126x-RAK4630 library to send data but I can’t seem to get it to work so I am trying to use the LoRa library by Sandeep mistry since it seems to be less complicated to me.
However, I can’t seem to understand the pin assignment for the LoRa in the RAK 4631. In the website they do mention the following but it is not clear enough which pin goes to which pin. Can someone explain the pin assignment since it seems there are 4 DIOx pins in RAK compared to the esp32 which has only 1. Attached below is the pin example on the website,
|P1.10|NSS|SPI NSS|
|P1.11|SCK|SPI CLK|
|P1.12|MOSI|SPI MOSI|
|P1.13|MISO|SPI MISO|
|P1.14|BUSY|BUSY signal|
|P1.15|DIO1|DIO1 event interrupt|
|P1.06|NRESET|NRESET manual reset of the SX1262|

In my arduino code, I am trying to define the pins in this way similar to the esp32

define SCK
#define MISO
#define MOSI
#define SS
#define RST
#define DI0
#define BAND 923E6

Thanks,
Lakindu.

Welcome to the forum @lakindu

If you mean the arduino-LoRa library, that library is not working with the RAK4631. The RAK4631 is using the Semtech SX1262 transceiver. Sandeepemstry’s library is only supporting the older Semtech SX1276/77/78/79 transceivers.

Jgromes RadioLib is supporting the Semtech SX1262 transceiver.

Thank you @beegee. I found out this library with credit to a wise man in the Arduino forum.

https://github.com/StuartsProjects/SX12XX-LoRa

According to him, this library allows us to establish connection between SX 126x LoRa module and SX 127x (T-Beam). However, the problem I face is I don’t understand the pin diagram and schematic of the RAK 4631 to enter to the code.

From the website, they have mentioned the pins for SX1262 as P1.10 which I don’t understand. I look at the schematic diagram and there isn’t a port number nor something marked as P1.10. If I could get help with that, it would be much appreciated thank you.



For example, the table mentions the NSS pin of the LoRa as P1.10 but I can’t find a P1.10 on the diagram if that makes sense.

That is because the SX1262 transceiver is on the RAK4631 and directly connected to the nRF52840 through the pins listed in documentation.
These connection are not accessible on the pads of the RAK4630.

Sorry for my wrong post earlier. I think I understand what you mean. I went to the datasheet for SX1262 on semtech website and this is what I found.


So according to this,
#define SCK 28
#define MISO 16
#define MOSI 17
… so forth yes?
Thanks for your assistance.

You are complete wrong.

Internal GPIO number of nRF52 Signal name Explanation Arduino GPIO number
P1.10 NSS SPI NSS GPIO 42
P1.11 SCK SPI CLK GPIO 43
P1.12 MOSI SPI MOSI GPIO 44
P1.13 MISO SPI MISO GPIO 45
P1.14 BUSY BUSY signal GPIO 46
P1.15 DIO1 DIO1 event interrupt GPIO 47
P1.06 NRESET NRESET manual reset of the SX1262 GPIO 38

And SPI pin assignment is not the only thing that needs to be setup correct:
The RF switch is controlled by GPIO 37 (power on/off).
SX1262 must be setup to use DIO2 as RF switch control (RX/TX)
SX1262 must be setup to use DIO3 to switch on/off its TCXO

I see. Thank you @beegee . I want to know where I can find this information because to be honest I still cannot find this information anywhere.
And one more thing, regarding the pin assignments for the RF control and TCXO. Would defining them like this be fine?
#define DIO2 37
#define DIO3 39

I do apologize since the pin mapping from nRF52 to Arduino is quite confusing to me.

For the SX1262 you must not define DIO2 or DIO3 from the MCU side.
The SX1262 has to be setup to use these pins as described.

You can get all this information from the SX1262 datasheet, from our documentation and from our preferred library SX126x-Arduino

Setup DIO2
Setup DIO3

The SX126x-Arduino Library looks good but the Read Me has not mentioned of support for the SX-127x. Since I’m trying to send LoRa signals to a T-Beam,I’m stuck in a little bit of a dilemma here. The library I am using that is,
GitHub - StuartsProjects/SX12XX-LoRa: Library for SX12XX LoRa devices , is said to support this communication but it was designed based on an Atmel processor and there isn’t any mention of the DIO2, DIO3 pins here in the program.

You can use different libraries for different devices and as long as the P2P parameters are the same on both sides they can communicate. You do not need to use the same library on the RAK4631 and on your T-Beam.

I used the library mentioned below, earlier for the matter yet the T-Beam didn’t receive the signals which is what led me to use similar libaries. Is this library used for LoRa p2p between RAK modules only?

No, this is a generic library for SX1262 transceivers and it works with ESP32, nRF52 and RP2040 MCU’s

I use it for communicating with LoRa transceivers as well.

I see if it can be used to send the LoRa data from RAK 4630 SX1262 to the ESP 32 based SX127x chip, I suppose I can try debugging the program again.

Hi @beegee , these are the 2 configurations for both my LoRa p2p programs. The receiving T-Beam doesn’t detect anything for some reason. Is it because of the parameters or the library?

#include <Arduino.h>
#include <SX126x-RAK4630.h>
#include <SPI.h>

// Function declarations
void OnTxDone(void);
void OnTxTimeout(void);


#ifdef NRF52_SERIES
#define LED_BUILTIN 35
#endif

// Define LoRa parameters
#define RF_FREQUENCY 923000000  // Hz
#define TX_OUTPUT_POWER 22		// dBm
#define LORA_BANDWIDTH 0		// [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
#define LORA_CODINGRATE 1		// [1: 4/5, 2: 4/6,  3: 4/7,  4: 4/8]
#define LORA_PREAMBLE_LENGTH 8  // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0   // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 3000
#define TX_TIMEOUT_VALUE 3000

static RadioEvents_t RadioEvents;
static uint8_t TxdBuffer[64];

I have used the same program as mentioned in the library and only added a 15 second delay to the end of the send(); loop to allow time for the T-Beam to detect it.

Below are the parameters and pin definitions for the T-Beam (SX1278) that is using LoRa library of sandeep mistry.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <LoRa.h>
//#include "Adafruit_SSD1306.h"

//defining the parameters for the lora peer to peer communication
#define SCK     5    // GPIO5  -- SX1278's SCK
#define MISO    19   // GPIO19 -- SX1278's MISO
#define MOSI    27   // GPIO27 -- SX1278's MOSI
#define SS      18   // GPIO18 -- SX1278's CS
#define RST     23   // GPIO14 -- SX1278's RESET
#define DI0     26   // GPIO26 -- SX1278's IRQ(Interrupt Request)
#define BAND    923E6
void setup()
{
	//pinMode(16, INPUT);
	//digitalWrite(16, LOW); 
	//delay(50);
  //digitalWrite(16, HIGH);
	Serial.begin(115200);
	while (!Serial)
	{
		delay(100); //delaying for 100 milliseconds indefinitely
	}
  //Wire.begin(OLED_SDA, OLED_SCL);
  // if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)){
  //   Serial.println("SSD1306 allocation failed");
  // }
	//***ADC121C021 ADC convert init ***********
	Serial.println("Lora Receiver Callback");
  SPI.begin(SCK,MISO,MOSI,DI0);
  LoRa.setPins(SS,RST,DI0);
  LoRa.setSpreadingFactor(7);
  LoRa.setSignalBandwidth(125000);
  LoRa.setCodingRate4(5);
  LoRa.setPreambleLength(8);
  if(!LoRa.begin(BAND)){
    Serial.println("Starting Lora failed!");
    while(1);
  }
  //Lora signal has been received
  Serial.println("init ok");
  //display.begin();
  //display.flipScreenVertically();  
  delay(1500);
}
void loop()
{
  LoRa.receive(50000);
	int packetSize = LoRa.parsePacket();
  Serial.printf("The tbeam has entered the loop cycle\n");
  if (packetSize) { 
    //received a packet
    //read packet
    while(LoRa.available()){
      LoraData = LoRa.readString();
      Serial.print(LoraData);
    }
    //print rssi of packet
    int rssi = LoRa.packetRssi();
    Serial.println(" with RSSI");
    Serial.println(rssi);
  }
  delay(30000);
}

Here I have added a 30 second delay between the loops too for the receiver. To my knowledge, I have set up the definitions correctly but nothing seems to work.
Thanks

If you have setup both devices with the same P2P parameters for frequency, bandwidth, spreading factor, coding rate, preamble length and syncword (should be the same by default) setup up one device to listen all the time and the other device to send only and test if it works.
Then switch the roles and test again.