LoRa US Tx

This sample demonstrates transmitting board temperature over the LoRaWAN protocol. (For US 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.

To run the sample:

  1. Copy the sample code to a folder on the Raspberry Pi.

  2. Open terminal, and then go to the folder you copied the sample.

  3. Run the sample with the following command:

python3 lora_us_tx.py

Sample Code

lora_us_tx.py
#!/usr/bin/env python3
#This sample demonstrates transmitting board temperature over the LoRaWAN protocol. (For US 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-ports
from time import sleep
from turta_lorahat import Turta_LoRa
from turta_lorahat import Turta_Analog
#Initialize
analog = Turta_Analog.ADC()
lora = Turta_LoRa.RN2XX3(region = Turta_LoRa.REGIONS.US_RN2903, auto_config = Turta_LoRa.CONFIG_MODES.LORA_TX)
print("Radio is set to transmit.")
cnt = 0
try:
while True:
#Read LoRa HAT's borad temperature (This is not the ambient temperature)
board_temp_c = analog.read_temperature()
print("Board temp:", str(round(board_temp_c, 1)) + "C")
#Send the payload over the LoRaWAN Protocol
print("Sending packet...")
res = lora.send("LoRa board temp: " + str(round(board_temp_c, 1)) + "C")
print("Result:", res)
#Wait
sleep(5)
#Exit on CTRL+C
except KeyboardInterrupt:
print('Bye.')

Result

When you run the sample, it reads and prints the board temperature. Then, it passes the payload to the LoRa module to be sent using the default radio frequency. The example output should be like this:

Sending packet...
ok
radio_tx_ok

To stop the Python script, just press CTRL + C.