This circuit integrates an Arduino Nano microcontroller with a LoRa Ra-02 SX1278 module for long-range communication and an I2C LCD 16x2 Screen for display purposes. The Arduino Nano serves as the central processing unit, managing the communication between the LoRa module and the LCD display. The LoRa module enables the Arduino to send and receive data over long distances using radio waves, while the LCD screen displays information received from the LoRa module.
#include <NewPing.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <LoRa.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
String inString = "";
int counter = 0;
// Pinout on Arduino Nano
// LoRa module > Arduino: GND:GND, GND:GND, 3.3V:3.3V, RST:D9, DI00:D2, NSS:D10, MOSI:D11, MISO:D12, SCK:D13
// LCD 16x2 > Arduino: GND:GND, 5V:5V, SDA:A4, SCL:A5
void setup() {
// initialize display
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
// Begin Serial communication at a baudrate of 9600:
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSpreadingFactor(12);
LoRa.setSignalBandwidth(62.5E3);
}
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize)
{
// received a paket
Serial.println("");
Serial.println(".................");
Serial.println("Received packet: ");
// read packet
inString = "";
while (LoRa.available())
{
char incoming = (char)LoRa.read(); //read each chr
if( incoming == '*')
{break;} //breaks the appending action; if '*'
inString += incoming; //append all chr
counter ++;
}
}
int newlineIndex = inString.indexOf('\n');
String line1 = inString.substring(0, newlineIndex);
String line2 = inString.substring(newlineIndex + 1);
//if any string is captured
if (counter>0)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
Serial.print(inString); //display in monitor
}
counter =0;
}
This code is designed to run on the Arduino Nano and handles the initialization and communication with both the LoRa module and the I2C LCD screen. It sets up the LoRa module for receiving data at a frequency of 433 MHz and displays any received data on the LCD. The code also includes error handling for the LoRa module initialization and reads incoming data until a '*' character is received, indicating the end of a message.