MadManMarkAu/ArduinoLoRa

An example LoRa radio transmitter/receiver for the Atmel ATmega2560 / Arduino Mega 2560.

★ 0Forks 0C++GitHub ↗Compare

README

ArduinoLoRa

An example LoRa radio transmitter/receiver for the Atmel ATmega2560 / Arduino Mega 2560.

Description

This project communicates with a Semtech SX1276 LoRa tranceiver available on most Ardunio LoRa shields.

This project will display a configuration menu on the serial console. The user can modift LoRa parameters and send a predefined data packet (of configurable length). It also listens for incoming LoRa packets using the currently configured parameters.

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 shows the configuration menu and sends/receives packets.
  • 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.

Getting Started

Hardware

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.

Dependencies

  • VSCode - For development and programming of the ATmega2560/Arduino.
  • PlatformIO extension for VSCode - Includes tools like avr-gcc, avrdude, and the avr-c library.

Executing program

  • Install VSCode
  • Install PlatformIO extension
  • Open this project
  • Edit platformio.ini and configure your serial ports (program/monitor)
  • Build this project
  • Program your microcontroller
  • Interact with the serial temrinal

FAQs

Why?

I wanted to learn about LoRa, with an eye to eventually implementing LoRaWAN or a Meshtastic node on Arduino.

Why use C++?

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.

Why not use standard Arduino libraries?

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.

Are you insane?

Probably, but it's more fun that way. :D

Can I use your code in xxx project?

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments and Resources

Contributors

MadManMarkAu

Issues