LoRa 32 (v2) with SX1262 LoRa HAT

Hello to everyone, i’m new using the LoRa 32 (v2)
Im trying to communicate the LoRa 32 (v2) module with SX1262 LoRa HAT using the 915Mhz Bandwidth, I’ve tried following the instructions shown in this wiki:

https://www.waveshare.com/wiki/SX1262_868M_LoRa_HAT

It seems to change de bandwidth from the HAT is not allowed,the python code shown is working, but when i try with the steps that are on the terminal section, using the software provided when i get the parameters trows me 868MHz bandwidth.

I use the example codes provided on Arduino IDE to program either the receiver or the sender, with the esp32 module.

What can i do to solve this?
How to change from 868Mhz to 915Mhz HAT bandwidth ?

Are we talking about bandwidth or frequency? 915MHz vs 868MHz is about frequency, not bandwidth, and setting the frequency seems to be pretty straightforward (with reference to the link you provide).

Hello, yes frequency , i tried changing the line 180 its respective com port and the frequency to 915 Mhz, and im trying to communicate the ESP32 LoRa 32 v2 with the HAT, here is the Arduino code

/*
This is a simple example show the Heltec.LoRa sended data in OLED.

The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
ware to OLED’s reset pin, the low-level signal at least 5ms.

OLED pins to ESP32 GPIOs via this connecthin:
OLED_SDA – GPIO4
OLED_SCL – GPIO15
OLED_RST – GPIO16

by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司

*/

#include “heltec.h”
#include “images.h”

#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6

unsigned int counter = 0;
String rssi = “RSSI --”;
String packSize = “–”;
String packet ;

void logo()
{
Heltec.display->clear();
Heltec.display->drawXbm(0,5,logo_width,logo_height,logo_bits);
Heltec.display->display();
}

void setup()
{
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /DisplayEnable Enable/, true /Heltec.Heltec.Heltec.LoRa Disable/, true /Serial Enable/, true /PABOOST Enable/, BAND /long BAND/);

Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
logo();
delay(1500);
Heltec.display->clear();

Heltec.display->drawString(0, 0, “Heltec.LoRa Initial success!”);
Heltec.display->display();
delay(1000);
}

void loop()
{
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);

Heltec.display->drawString(0, 0, "Sending packet: ");
Heltec.display->drawString(90, 0, String(counter));
Heltec.display->display();

// send packet
LoRa.beginPacket();

/*

  • LoRa.setTxPower(txPower,RFOUT_pin);
  • txPower – 0 ~ 20
  • RFOUT_pin could be RF_PACONFIG_PASELECT_PABOOST or RF_PACONFIG_PASELECT_RFO
    • RF_PACONFIG_PASELECT_PABOOST – LoRa single output via PABOOST, maximum output 20dBm
    • RF_PACONFIG_PASELECT_RFO – LoRa single output via RFO_HF / RFO_LF, maximum output 14dBm
      */
      LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
      LoRa.print("hello ");
      LoRa.print(counter);
      LoRa.endPacket();

counter++;
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

and here is the Python code Provided on the link i’ve put on the past post

#!/usr/bin/python

-- coding: UTF-8 --

this is an UART-LoRa device and thers is an firmware on Module

users can transfer or receive the data directly by UART and dont

need to set parameters like coderate,spread factor,etc.

|============================================ |

| It does not suport LoRaWAN protocol !!! |

| ============================================|

This script is mainly for Raspberry Pi 3B+, 4B, and Zero series

Since PC/Laptop does not have GPIO to control HAT, it should be configured by

GUI and while setting the jumpers,

Please refer to another script pc_node_main.py

import time

import sys

import serial

import msvcrt

class sx126x:

# if the header is 0xC0, then the LoRa register settings dont lost when it poweroff, and 0xC2 will be lost.

# cfg_reg = [0xC0,0x00,0x09,0x00,0x00,0x00,0x62,0x00,0x17,0x43,0x00,0x00]

cfg_reg = [0xC2,0x00,0x09,0x00,0x00,0x00,0x62,0x00,0x12,0x43,0x00,0x00]

get_reg = bytes(12)

rssi = False

addr = 65535

serial_n = ""

addr_temp = 0

#

# start frequence of two lora module

#

# E22-400T22S           E22-900T22S

# 410~493MHz      or    850~930MHz

start_freq = 850

#

# offset between start and end frequence of two lora module

#

# E22-400T22S           E22-900T22S

# 410~493MHz      or    850~930MHz

offset_freq = 18        # 850(start_freq) + 18(offset_freq) = 868MHz

                        # 410(start_freq) + 23(offset_freq) = 433MHz

# power = 22

# air_speed =2400

SX126X_UART_BAUDRATE_1200 = 0x00

SX126X_UART_BAUDRATE_2400 = 0x20

SX126X_UART_BAUDRATE_4800 = 0x40

SX126X_UART_BAUDRATE_9600 = 0x60

SX126X_UART_BAUDRATE_19200 = 0x80

SX126X_UART_BAUDRATE_38400 = 0xA0

SX126X_UART_BAUDRATE_57600 = 0xC0

SX126X_UART_BAUDRATE_115200 = 0xE0

SX126X_PACKAGE_SIZE_240_BYTE = 0x00

SX126X_PACKAGE_SIZE_128_BYTE = 0x40

SX126X_PACKAGE_SIZE_64_BYTE = 0x80

SX126X_PACKAGE_SIZE_32_BYTE = 0xC0

SX126X_Power_22dBm = 0x00

SX126X_Power_17dBm = 0x01

SX126X_Power_13dBm = 0x02

SX126X_Power_10dBm = 0x03

lora_air_speed_dic = {

    1200:0x01,

    2400:0x02,

    4800:0x03,

    9600:0x04,

    19200:0x05,

    38400:0x06,

    62500:0x07

}

lora_power_dic = {

    22:0x00,

    17:0x01,

    13:0x02,

    10:0x03

}

lora_buffer_size_dic = {

    240:SX126X_PACKAGE_SIZE_240_BYTE,

    128:SX126X_PACKAGE_SIZE_128_BYTE,

    64:SX126X_PACKAGE_SIZE_64_BYTE,

    32:SX126X_PACKAGE_SIZE_32_BYTE

}

def __init__(self,serial_num,freq,addr,power,rssi,air_speed=2400,\

             net_id=0,buffer_size = 240,crypt=0,\

             relay=False,lbt=False,wor=False):

    self.rssi = rssi

    self.addr = addr

    self.freq = freq

    self.serial_n = serial_num

    self.power = power

    self.ser = serial.Serial(serial_num,9600)

    self.ser.flushInput()

the data format like as following

“node address,frequence,payload”

“20,868,Hello World”

def send(self,data):

    self.ser.write(data)

    # if self.rssi == True:

        # self.get_channel_rssi()

    time.sleep(0.1)

def receive(self):

    if self.ser.inWaiting() > 0:

        time.sleep(0.5)

        r_buff = self.ser.read(self.ser.inWaiting())

        print("receive message from node address with frequence %d,%d.125MHz"%((r_buff[0]<<8)+r_buff[1],r_buff[2]+self.start_freq),end='\r\n',flush = True)

        print("message is "+str(r_buff[3:-1]),end='\r\n',flush = True)

       

        # print the rssi

        if self.rssi:

            # print('\x1b[3A',end='\r')

            print("the packet rssi value: -{0}dBm".format(256-r_buff[-1:][0]),flush = True)

            self.get_channel_rssi()

        else:

            pass

            #print('\x1b[2A',end='\r')

def get_channel_rssi(self):

    time.sleep(0.1)

    self.ser.flushInput()

    self.ser.write(bytes([0xC0,0xC1,0xC2,0xC3,0x00,0x02]))

    time.sleep(0.5)

    re_temp = bytes(5)

    if self.ser.inWaiting() > 0:

        time.sleep(0.1)

        re_temp = self.ser.read(self.ser.inWaiting())

    if re_temp[0] == 0xC1 and re_temp[1] == 0x00 and re_temp[2] == 0x02:

        print("the current noise rssi value: -{0}dBm".format(256-re_temp[3]),flush = True)

        # print("the last receive packet rssi value: -{0}dBm".format(256-re_temp[4]))

    else:

        # pass

        print("receive rssi value fail",flush = True)

        # print("receive rssi value fail: ",re_temp)

def free_serial(self):

    self.ser.close()

Need to disable the serial login shell and have to enable serial interface

command sudo raspi-config

When the LoRaHAT is attached to RPi, the M0 and M1 jumpers of HAT should be removed.

serial_num

PiZero, Pi3B+, and Pi4B use “/dev/ttyS0”

Frequency is [850 to 930], or [410 to 493] MHz

address is 0 to 65535

under the same frequence,if set 65535,the node can receive

messages from another node of address is 0 to 65534 and similarly,

the address 0 to 65534 of node can receive messages while

the another note of address is 65535 sends.

otherwise two node must be same the address and frequence

The tramsmit power is {10, 13, 17, and 22} dBm

RSSI (receive signal strength indicator) is {True or False}

It will print the RSSI value when it receives each message

node = sx126x(serial_num = “COM8”,freq=433,addr=100,power=22,rssi=True)

node = sx126x(serial_num = “COM3”,freq=915,addr=0,power=22,rssi=True)

def send_deal():

get_rec = ""

print("input a string such as  0,868,Hello World,it will send `Hello World` to lora node device of address 20 with 868MHz ")

print("please input and press Enter key:",end='',flush=True)

get_rec = input()

get_t = get_rec.split(",")

offset_frequence = int(get_t[1])-(850 if int(get_t[1])>850 else 410)

#

# the sending message format

#

#         receiving node              receiving node                   receiving node           own high 8bit           own low 8bit                 own

#         high 8bit address           low 8bit address                    frequency                address                 address                  frequency             message payload

data = bytes([int(get_t[0])>>8]) + bytes([int(get_t[0])&0xff]) + bytes([offset_frequence]) + bytes([node.addr>>8]) + bytes([node.addr&0xff]) + bytes([node.offset_freq]) + get_t[2].encode()

node.send(data)

try:

print("Prueba haber si jala Press Ctrl+C to exit")

print("Press i to send")

while True:

    # get_input = sys.stdin.read(1)

    # if get_input != None:

        # # dectect key i

        # if get_input == '\x69':

            # send_deal()

        # sys.stdout.flush()

    if msvcrt.kbhit() and msvcrt.getch()==b'\x69':

        send_deal()

    node.receive()

# node.free_serial()

except:

node.free_serial()

pass

the Python code works with the CMD console but it is not receiving anything

Well, there seems to be a lot going on in that Python code, which just means there’s a lot of room for things to go wrong. One thing that jumps out at me though is the reference to a node address. I’m not aware of any such thing in ‘standard’ LoRa communications, so I wonder if these LoRaHATs are doing something more than vanilla LoRa. This might be fine if you have two LoRaHATs working together, but not so good if you’ve got a third party, like your Heltec node, in there that’s not using the LoRaHAT’s version of LoRa.

I do have my own [Raspberry Pi/Python] Pi-Hat working with a WiFi LoRa 32 node, but my Pi-Hat is based on the HopeRF95W module (SX1276), so the software I use is probably not going to be compatible with an SX1262, but you can check it out here if it helps.