An example LoRa radio responder for the Atmel ATmega2560 / Arduino Mega 2560.
This project communicates with a Semtech SX1276 LoRa tranceiver available on most Ardunio LoRa shields.
This project will listen for LoRa messages using the configured LoRa settings, waiting for a command from the initiating side. It will then process the command and return a result over LoRa.
I used this project as a kind of ping/pong responder while learning about LoRa and getting the hardware working.
This project does not use the Aduino/Wiring libraries. Instead, all I/O and communications are implemented with direct register reads/writes using internal libaries contained within this source code. The Arduino is treated as a hardware platform only; no Arduino-specific software or libraries are used. This project WILL NOT WORK with anything other than the ATmega2560 chip (Ardunio Mega 2560) without modification. Just becase the LoRa shield fits on your Arduino, doesn't mean this software will work unmodified.
The code files created in this project are:
- console.cpp/hpp - Console interface using the USART serial driver.
- lora.cpp/hpp - SC1276 LoRa radio driver.
- main.cpp - Main application that configures communications and processes commands.
- random.cpp/hpp - PRNG implementation using a linear feedback shift register and entropy input from the LoRa chip.
- serial.cpp/hpp - USART driver.
- spi.cpp/hpp - Hardware SPI driver.
- strings.cpp/hpp - String comparison functions, more robust or more functional than those in stdlib.
This project is configured to use an antenna connected to the SX1276's "PA_BOOST" pin. This is the high-power output of the chip. If your board uses the "RFO" pin instead, change the configuration in main.cpp. You may also need to adjust the power setting used.
This project also expects pin E4 on the ATmega2560 (pin 2 on the Arduino Mega 2560) to be connected to the SX1276's DIO0 pin. This is used to signal completion of LoRa chip functions. This project can be modified to not require this (by reading the REG_IRQ_FLAGS register for the required signals), but I have not implemented this.
- VSCode - For development and programming of the ATmega2560/Arduino.
- PlatformIO extension for VSCode - Includes tools like avr-gcc, avrdude, and the avr-c library.
- Install VSCode
- Install PlatformIO extension
- Open this project
- Edit platformio.ini and configure your serial ports (program/monitor)
- Build this project
- Program your microcontroller
- Monitor the serial terminal
Commands are not case sensitive. Currently, only one command is supported.
This command will generate a series of random bytes and transmit those bytes over LoRa. The number of random bytes generated is the byte immediately following the string "GetRandom".
I wanted to learn about LoRa, with an eye to eventually implementing LoRaWAN or a Meshtastic node on Arduino.
C++ allows me to use the Ardunio Wiring library's standard structure of "Module.Function()" calls. Things like the LoRa driver, serial driver, SPI driver etc... are all implemented with singleton classes.
The Arduino libraries are great for prototyping and learning about microcontrollers, but I found that when you have more experience, the Wiring library holds your hand too much. This is great for beginners, but makes the library incredibly inefficient with all the checks the library performs.
Probably, but it's more fun that way. :D
Yes. This code is freely available to use or modify, even commercially. An acknowledgement of my authorship would be nice in your attributions/about section, but is not required.
This project is licensed under the MIT License - see the LICENSE.md file for details
- ATmega2560 Datasheet - Datasheet for the ATmega2560 chip used on the Arduino Mega 2560.
- SC1276 Datasheet - Datasheet for the LoRa chip (on a module) on my LoRa shield.
- RMF92W Datasheet - Datasheet for the LoRa module on my LoRa shield.
- Arduino Mega 2560 schematic - Arduino Mega 2560 chematic used to work out which ATmega2560 pins are connected to which Arduino connectors.
- arduino-LoRa by Sandeep Mistry - Reference matrial used for guidance on setting the transmit power level and for the HF/LF RSSI offset values.