SX1268 433M LoRa HAT

From Waveshare Wiki
Jump to: navigation, search

SX1268 433M LoRa HAT
SX1268 433M LoRa HAT




Onboard Interfaces


  • This product is a Raspberry Pi expansion board based on SX1268/SX1262 chip, wireless serial port module with LoRa modulation function
  • With multi-level relay to achieve ultra-long-distance communication, low power consumption wake-up communication, encrypted transmission, etc.
  • This product uses a private protocol and does not support LoRaWAN


  • Support global license-free ISM 433/470/868/915MHz frequency band
  • Supports wake-on-air, that is, ultra-low power consumption, suitable for battery-powered applications
  • Support point-to-point transmission, broadcast transmission, channel monitoring, multi-level relayimg for ultra-long-distance communication
  • Support RSSI signal indicator for evaluating signal quality and improving communication network
  • Support LBT function, monitor the channel environmental noise before sending, which can greatly improve the communication success rate of the module in harsh environments
  • LoRa spread spectrum technology, up to 84 channels/81 channels (SX1268, SX1262) optional
  • Support waking on radio, online configuration, carrier sense, automatic relay, communication key, low power sleep
  • In ideal environment, the communication distance can reach 5KM


Specification of SX1268 433M LoRa HAT
Consumption Transmit Current 100mA (Transient current)
Receive Current 11mA
Sleep Current 2uA (LoRa module deep sleep)
MAX Transmit Power 22.0dBm(10, 13, 17, 22dBm Selectable)
Transmit Length 240 Bytes (32, 64, 128, 240 Bytes Selectable)
Buffer 1000 Bytes
Working bands 410.125~493.125MHz or 850.125~930.125MHz
Receive Sensitivity [email protected] (On air)
Air Speed 0.3K~62.5Kbps (software selectable)
Interface UART
Range 5KM(Sunny day; open area; Antenna: AUX 5dBi, Height 2.5m; Air Speed: 2.4kbps)
Working voltage 5V
Logic voltage 3.3V
Working Temperature -40 ~ 85°C

Hardware description

Hardware description of SX1268 LoRa HAT
  1. SX1268/SX1262 LoRa module
  2. 74HC125V: voltage level translator
  3. CP2102: USB TO UART converter
  4. Raspberry Pi GPIO connector: for connecting with Raspberry Pi
  5. USB TO UART port
  6. UART header: for connecting MCU
  7. SMA antenna connector
  8. IPEX antenna connector
  9. Indicators:
    • RXD/TXD: UART RX/TX indicator
    • AUX: auxiliary indicator
    • PWR: power indicator
  10. UART selection jumpers
    • A: control the LoRa module through USB TO UART
    • B: control the LoRa module through Raspberry Pi
    • C: access Raspberry Pi through USB TO UART
  11. LoRa mode selection jumpers
    • short M0, short M1: transmission mode
    • short M0, open M1: configuration mode
    • open M0, short M1: WOR mode
    • open M0, open M1: deep sleep mode

1. Combine M1 and M0 with high and low levels to determine the working mode. M1 and M0 are high when they are not connected to the jumper cap. After switching the working mode, if the module is idle, it will enter the new working mode, otherwise the current transmission will be processed and enter the new working mode after receiving.
2. Mode 0: Transmission mode, Module transmit data when users send data to UART interface. Wireless receiving is enabled to receive data and send to UART interface when idle.
3. Mode 1:When it is defined to Transmit, user need to add wakeup codes before transmitting, receiving is same as Mode 0.
4. Mode 2: Wireless transmit and wireless receive are disabled, users can configure configuration according to #Registers Configuration
5. Mode 3: Wireless transmit and wireless receive are disabled, module enter deep sleep mode. Module will configure when switching to other modes.

LoRa & LoRaWAN

What's LoRa

Semtech's LoRa is IoT wireless platform with long-distance and low-power , generally referring to radio frequency chips in LoRa. The main features are as follows

  • The spread spectrum modulation technology used by LoRa (abbreviation of long range) is derived from chirp spread spectrum (CSS) technology, which is one of long-distance wireless transmission technology and LPWAN communication technology. At present, LoRa in ISM frequency band mainly includes 433 , 868, 915 MHz, etc.
  • Integrating digital spread spectrum, digital signal processing and forward error correction codes, the performance of long-distance communication in LoRa has been improved a lot. Moreover, the link budget in LoRa, the main factor that determines distance under a given environment, is better than any other standardized communication technology.
  • LoRa RF chips mainly include SX127X series, SX126X series, SX130X series, of which SX127X, SX126X series are used for LoRa nodes, and SX130X is used for LoRa gateways. For details, please refer to Semtech's product list

What's LoRaWAN

LoRaWAN is a low power, wide area networking (LPWAN) protocol based on LoRa Technology. It designed to wirelessly connect battery operated ‘things’ to the internet in regional, national or global networks, and targets key Internet of things (IoT) requirements such as bi-directional communication, end-to-end security, mobility and localization services. The node wirelessly connected to the Internet has network access authentication, which is equivalent to establishing an encrypted communication channel between the node and the server. For details of network access, refer to source code. The LoRaWAN protocol level is shown in the figure below.

    • Class A/B/C node devices in the MAC basically cover all the application for the Internet of Things. The difference between them is that the time slots for nodes to send and receive are different
    • The band parameters in Modulation, such as EU868 and AS430, are differnt in differnt contries. The regional parameters refer to link


  • The LoRaWAN coverage in city or other areas requires node (LoRa node radio frequency chip), gateway (or base station, LoRa gateway radio frequency chip), server and cloud. As shown in the following figure:
    • First, DEVICE (node device) send network access data package to GATEWAY and then to the server. After the authentication is passed, it can send and receive application data with the server normally.
    • GATEWAY (gateway) can communicate with the server through wired network, 3/4/5G wireless network.
    • The main operators on the server side include TTN, etc. If you want to build cloud services by yourself, please refer to lorawan-stackchirpstack



LoRa devices and networks such as LoRaWAN enable smart IoT applications to help the planet's present challenges such as the energy management, natural resource reduction, pollution control, infrastructure efficiency, disaster prevention, and so on. Semtech's LoRa devices have been successfully applied in many aspects such as smart cities, homes and buildings, communities, metrology, supply chain and logistics, agriculture, and so on. LoRa networks reach hundreds of millions of devices in more than 100 countries for a smarter planet

Using with PC

SSCOM connection test

1. Prepare two SX126x LoRa HAT modules (here called Lora HAT), two Micro USB cables, assemble SMA antennas, place the jumper cap on A, and connect M0 and M1 to GND
2. Install the CP2102 driver on the WINDOWS PC, and connect the two Lora HATs to the PC using Micro USB
3. Open the PC device manager, find the two COM ports corresponding to the CP2102, use the SSCOM serial port software to connect the two Lora modules respectively, and set the baud rate to 9600
4. Input data in the input field of one SSCOM serial port software, click the send button, and you can see the data received by the LoRa module in the display field of the other SSCOM serial port software.
  • SX1262 LoRa HAT user manual-1.png
  • SX1262 LoRa HAT user manual-2.png


This test uses a Windows PC to connect to the LoRa HAT, and the jump settings will not change according to the factory location

1. Install python3 on Windows, then enter cmd in the startup bar to search and open the Windows terminal

2. Enter the path of python3 into the terminal, the default address is generally as shown in the picture below, pay attention to check the your own python3 path, and install pyserial

pip3 install pyserial

3. Use the upper computer software to set up LoRa HAT, unplug the M1 jumper when setting, connect to the M1 jumper and close the serial port of the upper computer after the setting is completed. Set the parameters as follows

4. Unzip the sample program to the desktop, open the file to modify the COM port, and then run the demo.

Using with Raspberry Pi

In this chapter, we will demonstrate two examples. Demo 1: the test of two LoRa HATs connect to two Raspberry Pis for receiving and sending. Demo 2: The test of using 3 LoRa HATs for relay communication receiving and sending.

Hardware Connection, Install Function, Enable Raspberry Pi Serial Port, Download Demo Program

1. Hardware connection After powering on Raspberry Pi, connect LoRa HAT as shown below:

  • SX1268-433M-LoRa-HAT-006.jpg

Enter the following commands one by one to install the python library, the first command enables the Raspberry Pi serial port

#The system higher than version 2021.10.30 no longer needs to install the serial library.
#sudo apt install python-serial
sudo raspi-config
cd Documents

2. Enable serial port

Open Terminal of Raspberry Pi
Run command sudo raspi-config to open Configure interface
Choose Interfacing Options -> Serial -> No -> Yes


Demo 1

After executing the following command, the node will automatically print to the terminal when it receives the data sent by other nodes. When the node needs to send data to other nodes, press the keyboard i, and then enter the input according to the prompt, as shown in the figure below:

cd ~/Documents/SX126X_LoRa_HAT_Code/raspberrypi/python/
sudo python3
  • first node
  • second node
  • transpareant transfer diagram

Demo 2

Relay communication is a method for ultra-long-distance communication. Setting up the LoRa module to relay mode, and its address register would be only for forwarding pairing, no more active transceiver function, no low power consumption.

【Note】 To test Relay example, you require at least three LoRa HATs.

  • Assume the three LoRa modules as LoRa module A, LoRa module B, and LoRa module C.
  • Directly connected LoRa module A to the Raspberry Pi, set up LoR module B and LoRa module C by Windows upper-computer
  • relay transfer diagram
  • lora module B setting
  • lora module C setting
  • lora module A setting
After LoRa module A is connected to the Raspberry Pi, open the file, change line 66, change realy=False to realy=True, execute the following command, LoRa module C will print the data from the serial port after receiving the data, and relay the LoRa module B will not print any data from the serial port, enter the following command:
cd ~/Documents/SX126X_LoRa_HAT_Code/RaspberryPi/python/
# node = sx126x.sx126x(serial_num = "/dev/ttyS0",freq=868,addr=0,power=22,rssi=True,air_speed=2400,relay=True)
sudo python3

Using with STM32

This demo use STM32F103CBT6 based on HAT function.

Hardware connection

Connect the jumper cap to B, remove the M0, M1 jumper caps instead of using the GPIO of STM32F103C

SX1268 LoRa HAT STM32
5V 5V
M1 PB15
M0 PB14
SX1262 LoRa HAT user manual-12.png

2. Example

  • The settings of the LoRa module connected to the computer USB are the same as the above three demos.
  • Open Keil project document and use different definitions in communication methods in lines 75 to 77 of the main.c file
//#define RELAY
//#define WOR

Demo Brief Analysis

In this section, we briefly describes the working process and python program of this product

  • After power on, set up /dev/ttyS0 serial port and 9600 baud rate, M0 (BCM22) pin of the module is in low level, M1 (BCM27) pin is in high level, the module enters the configuration mode
def __init__(self,serial_num,freq,addr,power,rssi,air_speed=2400,\
                net_id=0,buffer_size = 240,crypt=0,\
       self.rssi = rssi
       self.addr = addr
       self.freq = freq
       self.serial_n = serial_num
       self.power = power
       # Initial the GPIO for M0 and M1 Pin
       # The hardware UART of Pi3B+,Pi4B is /dev/ttyS0
       self.ser = serial.Serial(serial_num,9600)
  • Lines 11 to 77 in the following code set the LoRa module's low address, high address, network ID, frequency, airspeed size, cache size, power size, RSSI input enable, encryption key and whether it is enabled the relay mode parameters, click to check register descriptionand LoRa Configuration. Lines 79 to 113 are the serial port sending configuration commands to the LoRa module. If the configuration is correct, pull down the M1 pin to enter the transceiver mode.
def set(self,freq,addr,power,rssi,air_speed=2400,\
           net_id=0,buffer_size = 240,crypt=0,\
       self.send_to = addr
       self.addr = addr
       # We should pull up the M1 pin when sets the module
       low_addr = addr & 0xff
       high_addr = addr >> 8 & 0xff
       net_id_temp = net_id & 0xff
       if freq > 850:
           freq_temp = freq - 850
           self.start_freq = 850
           self.offset_freq = freq_temp
       elif freq >410:
           freq_temp = freq - 410
           self.start_freq  = 410
           self.offset_freq = freq_temp
       air_speed_temp = self.lora_air_speed_dic.get(air_speed,None)
       # if air_speed_temp != None
       buffer_size_temp = self.lora_buffer_size_dic.get(buffer_size,None)
       # if air_speed_temp != None:
       power_temp = self.lora_power_dic.get(power,None)
       #if power_temp != None:
       if rssi:
           # enable print rssi value 
           rssi_temp = 0x80
           # disable print rssi value
           rssi_temp = 0x00        
       # get crypt
       l_crypt = crypt & 0xff
       h_crypt = crypt >> 8 & 0xff
       if relay==False:
           self.cfg_reg[3] = high_addr
           self.cfg_reg[4] = low_addr
           self.cfg_reg[5] = net_id_temp
           self.cfg_reg[6] = self.SX126X_UART_BAUDRATE_9600 + air_speed_temp
           # it will enable to read noise rssi value when add 0x20 as follow
           self.cfg_reg[7] = buffer_size_temp + power_temp + 0x20
           self.cfg_reg[8] = freq_temp
           # it will output a packet rssi value following received message
           # when enable eighth bit with 06H register(rssi_temp = 0x80)
           self.cfg_reg[9] = 0x43 + rssi_temp
           self.cfg_reg[10] = h_crypt
           self.cfg_reg[11] = l_crypt
           self.cfg_reg[3] = 0x01
           self.cfg_reg[4] = 0x02
           self.cfg_reg[5] = 0x03
           self.cfg_reg[6] = self.SX126X_UART_BAUDRATE_9600 + air_speed_temp
           # it will enable to read noise rssi value when add 0x20 as follow
           self.cfg_reg[7] = buffer_size_temp + power_temp + 0x20
           self.cfg_reg[8] = freq_temp
           # it will output a packet rssi value following received message
           # when enable eighth bit with 06H register(rssi_temp = 0x80)
           self.cfg_reg[9] = 0x03 + rssi_temp
           self.cfg_reg[10] = h_crypt
           self.cfg_reg[11] = l_crypt
       for i in range(2):
           r_buff = 0
           if self.ser.inWaiting() > 0:
               r_buff =
               if r_buff[0] == 0xC1:
                   # print("parameters setting is :",end=)
                   # for i in self.cfg_reg:
                       # print(hex(i),end=' ')
                   # print('\r\n')
                   # print("parameters return is  :",end=)
                   # for i in r_buff:
                       # print(hex(i),end=' ')
                   # print('\r\n')
                   #print("parameters setting fail :",r_buff)
               print("setting fail,setting again")
               if i == 1:
                   print("setting fail,Press Esc to Exit and run again")
                   # time.sleep(2)
                   # print('\x1b[1A',end='\r')
  • The serial port sends application data to the LoRa module and sends other LoRa nodes wirelessly
# the data format like as following
# "node address,frequence,payload"
# "20,868,Hello World"
   def send(self,data):
       # if self.rssi == True:
           # self.get_channel_rssi()
  • Data received by the receiver send controller from serial output, and pay attention to the third line of code. If the amount of received data is too large, please increase the delay accordingly and wait for all the data to be received before reading. Lines 10 to 15 are based on whether RSSI Enable to print RSSI value
def receive(self):
       if self.ser.inWaiting() > 0:
           r_buff =
           print("receive message from node address with frequence\033[1;32m %d,%d.125MHz\033[0m"%((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')
           # print the rssi
           if self.rssi:
               # print('\x1b[3A',end='\r')
               print("the packet rssi value: -{0}dBm".format(256-r_buff[-1:][0]))
  • In the file, after the program runs, wait for the user to press the keyboard to perform the corresponding operation, enter Esc to exit the loop, enter i to enter the application information to be sent, and enter s to broadcast the CPU temperature every 10 seconds:
   print("Press \033[1;32mEsc\033[0m to exit")
   print("Press \033[1;32mi\033[0m   to send")
   print("Press \033[1;32ms\033[0m   to send cpu temperature every 10 seconds")
   # it will send rpi cpu temperature every 10 seconds 
   seconds = 10
   while True:
       if[sys.stdin], [], [], 0) == ([sys.stdin], [], []):
           c =
           # dectect key Esc
           if c == '\x1b': break
           # dectect key i
           if c == '\x69':
           # dectect key s
           if c == '\x73':
               print("Press \033[1;32mc\033[0m   to exit the send task")
               timer_task = Timer(seconds,send_cpu_continue)
               while True:
                   if == '\x63':
                       print(" "*100)
       # timer,send messages automatically       
   termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)



Demo codes



Why can't I read the parameters on the computer?

Set up upper jumper cap to B; remove the lower jumper cap M2 and you can read the parameters:


Do SX1268 and SX1268 support LoRaWAN network protocol?


If you need to support the LoRaWAN network protocol, buy this Pico-LoRa-SX1262-868M, which can be matched with LoRaWAN gateway SX1302 LoRaWAN Gateway HAT

Additional instructions: In the OSI model of computer network, LoRa is located in the bottom physical layer, which generally refers to the radio frequency chip using LoRa technology; LoRaWAN is a set of protocol standards based on the MAC layer based on the LoRa transmission technology. With this standard, LoRaWAN becomes a network technology.


If you require technical support, please go to the Support page and open a tickets.