Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
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 | -147dBm@0.3Kbps (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 |
【Note】
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 transmits data when users send data to the UART interface. Wireless receiving is enabled to receive data and send it to the UART interface when idle.
3. Mode 1: When it is defined to Transmit, the user needs to add wakeup codes before transmitting, receiving is the 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, and the module enters deep sleep mode. The module will configure when switching to other modes.
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.
LoRaWAN is a low-power, wide-area networking (LPWAN) protocol based on LoRa Technology. It is 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.
LoRa devices and networks such as LoRaWAN enable smart IoT applications to help the planet's present challenges such as 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.
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 your python3 path, and install pyserial.
path=%path%;C:\Users\zhongshaohua\AppData\Local\Programs\Python\Python37\Scripts\ path=%path%;C:\Users\zhongshaohua\AppData\Local\Programs\Python\Python37\ pip3 install pyserial
3. Use the host 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 demo to the desktop, open the main.py file to modify the COM port, and then run the demo.
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.
1. Hardware connection: After powering on Raspberry Pi, connect LoRa HAT as shown below:
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 wget https://files.waveshare.com/upload/1/18/SX126X_LoRa_HAT_CODE.zip unzip SX126X_LoRa_HAT_CODE.zip
2. Enable serial port.
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 main.py
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, and no low power consumption.
【Note】 To test the Relay example, you require at least three LoRa HATs.
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 main.py
This demo uses STM32F103CBT6 based on the HAT function.
Connect the jumper cap to B, and remove the M0, and M1 jumper caps instead of using the GPIO of STM32F103C.
SX1268 LoRa HAT | STM32 |
---|---|
5V | 5V |
GND | GND |
RXD | PA10 |
TXD | PA9 |
M1 | PB15 |
M0 | PB14 |
2. Example
#define TRASNSPARENT
//#define RELAY
//#define WOR
In this section, we briefly describe the working process and Python program of this product.
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 # Initial the GPIO for M0 and M1 Pin GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.M0,GPIO.OUT) GPIO.setup(self.M1,GPIO.OUT) GPIO.output(self.M0,GPIO.LOW) GPIO.output(self.M1,GPIO.HIGH) # The hardware UART of Pi3B+,Pi4B is /dev/ttyS0 self.ser = serial.Serial(serial_num,9600) self.ser.flushInput() self.set(freq,addr,power,rssi,air_speed,net_id,buffer_size,crypt,relay,lbt,wor)
def set(self,freq,addr,power,rssi,air_speed=2400,\ net_id=0,buffer_size = 240,crypt=0,\ relay=False,lbt=False,wor=False): self.send_to = addr self.addr = addr # We should pull up the M1 pin when sets the module GPIO.output(self.M0,GPIO.LOW) GPIO.output(self.M1,GPIO.HIGH) time.sleep(0.1) 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 else: # 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 else: 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 adding 0x20 as follows # self.cfg_reg[7] = buffer_size_temp + power_temp + 0x20 self.cfg_reg[8] = freq_temp # # it will output a packet rssi value following the 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 self.ser.flushInput() for i in range(2): self.ser.write(bytes(self.cfg_reg)) r_buff = 0 time.sleep(0.2) if self.ser.inWaiting() > 0: time.sleep(0.1) r_buff = self.ser.read(self.ser.inWaiting()) if r_buff[0] == 0xC1: pass # 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') else: pass #print("parameters setting fail :",r_buff) break else: print("setting fail,setting again") self.ser.flushInput() time.sleep(0.2) print('\x1b[1A',end='\r') if i == 1: print("setting fail,Press Esc to Exit and run again") # time.sleep(2) # print('\x1b[1A',end='\r') GPIO.output(self.M0,GPIO.LOW) GPIO.output(self.M1,GPIO.LOW) time.sleep(0.1) *The serial port sends application data to the LoRa module and sends other LoRa nodes wirelessly. # The data format like as follows # "node address,frequency,payload" # "20,868, Hello World" def send(self,data): GPIO.output(self.M1,GPIO.LOW) GPIO.output(self.M0,GPIO.LOW) time.sleep(0.1) 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\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])) self.get_channel_rssi() else: pass #print('\x1b[2A',end='\r')
try: time.sleep(1) 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 select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): c = sys.stdin.read(1) # dectect key Esc if c == '\x1b': break # dectect key i if c == '\x69': send_deal() # 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) timer_task.start() while True: if sys.stdin.read(1) == '\x63': timer_task.cancel() print('\x1b[1A',end='\r') print(" "*100) print('\x1b[1A',end='\r') break sys.stdout.flush() node.receive() # timer,send messages automatically except: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
Set up the upper jumper cap to B; remove the lower jumper cap M2 and you can read the parameters:
No. 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 a 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 it only supports Lora but does not support Lorwan, point-to-point communication is supported. However, network connections with higher-standard do not support. If you want to establish LoRa network with larger scale, it is recommended to use LoWAN protocol.
It may be the serial port issue, the default serial port used by the program is ttyS0, Raspberry Pi serial port may not be, you can use the following command to confirm (serial0 corresponds to the selected serial port):
ls -l /dev/serial*
470M and 433M module demos are the same, and the default use of 433M program; 915M and 868M are used 868M program, the default program is 433M, change the comment:
In stream mode, LoRa devices do not wait for acknowledgment from the receiver after sending data. This mode is suitable for applications that require high real-time performance or have low requirements for data integrity.
In packet mode, LoRa devices wait for an acknowledgment (ACK) from the receiver after sending data. This mode is suitable for applications that need to ensure data integrity and reliability.