This sample demonstrates receiving packets over the LoRaWAN protocol. (For EU version.)
To make Raspberry Pi communicate with the LoRa module, you should swap the serial ports of the Raspbian OS. Set "/dev/ttyAMA0" to 'serial0'. Also, disable the console on 'serial0'. For a how-to, visit swapping the serial ports topic.
Copy the sample code to a folder on the Raspberry Pi.
Open terminal, and then go to the folder you copied the sample.
Run the sample with the following command:
python3 lora_eu_rx.py
Sample Code
#!/usr/bin/env python3#This sample demonstrates receiving packets over the LoRaWAN protocol. (For EU version.)#Install LoRa HAT library with "pip3 install turta-lorahat"#Raspberry Pi Configuration# - You should enable SPI and I2C from the Raspberry Pi's configuration.# To do so, type 'sudo raspi-config' to the terminal, then go to 'Interfacing Options' and enable both SPI and I2C.# - You should swap the serial ports of the Raspberry Pi.# Set "/dev/ttyAMA0" to 'serial0'. Also, disable the console on 'serial0'.# For a how-to, visit our documentation at https://docs.turta.io/how-tos/raspberry-pi/raspbian/swapping-the-serial-portsfrom time import sleepfrom turta_lorahat import Turta_LoRa#Initializelora = Turta_LoRa.RN2XX3(region = Turta_LoRa.REGIONS.EU_RN2483, auto_config = Turta_LoRa.CONFIG_MODES.LORA_RX)print("Radio is set to receive.")try:whileTrue:#Check for serial port buffer buffer = lora.check_data()#If data is received, print itif buffer isnotNone:print(buffer)#Exit on CTRL+CexceptKeyboardInterrupt:print('Bye.')
Result
When you run the sample, it prints the incoming data, if any, from the default radio frequency. When incoming data is captured, the example output should be like this: