Industrial ESP32 Devices With LoRa Add-On | Norvi Agent 1
by NORVI Controllers in Circuits > Microcontrollers
930 Views, 1 Favorites, 0 Comments
Industrial ESP32 Devices With LoRa Add-On | Norvi Agent 1
Norvi Agent 1 devices are ESP32 WROVER-B embedded industrial nodes. These devices come with range of features with different models that make them ideal for automation and IoT applications. ESP32 WROVER-B chip includes external ram (PSRAM), which provides enough memory for user programs with large files like as JSON or HTML, among other things.
Check out our previous instructable on getting started with the Norvi Agent1 device to know more about this model.
In this instructable, we'll be looking at Norvi Agent 1 AT01-BM1 model with LoRA add-on. LoRa is a wireless data communication technology which allows allows long distance communication with low power requirements.This makes LoRa ideal for battery-operated sensors and low-power applications in the internet of Things (IoT), smart home, and more.
Here, we'll be looking at how to transfer data between two LoRa module equipped Norvi Agent 1 devices.
The features of this device are,
- 3 Digital Inputs, 24VDC
- 3 Analog Inputs, 0-10 V
- WiFi & Bluetooth
- RS-485 Communication
- RGB LED indicator for multiple status recognition
- LoRa add-on for additional communication
So what do you need to get started?
- Norvi Agent 1 device
- USB cable (Type A to Type B mini)
- PC/Laptop
Understanding More About the LoRa Connection.
The device has a built-in SX1276 LoRa module. The SPI connection of the module with the Norvi Agent 1 device is as follows,
SCK 18 MISO 19 MOSI 23 CS 2
Installing ESP32 Board in Arduino IDE and Booting the Device.
Check step1 of this instructable.
Programming the Devices.
Install the Neopixel, Adafruit ADS1015 and the LoRa libraries in your Arduino IDE and upload the respective sketches to the Norvi Agent 1 sender and Norvi Agent 1 receiver.
- Lora Sender Sketch
include <SPI.h> // include libraries #include <LoRa.h> #include <Adafruit_NeoPixel.h> #define NUMPIXELS 1 #define PIN 25 // Digital IO pin connected to the NeoPixels. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define SCK 18 #define MISO 19 #define MOSI 23 #define SS 2 #define RST 5 #define DIO0 4 //433E6 for Asia //866E6 for Europe //915E6 for North America #define BAND 433E6 int counter = 0; void setup() { Serial.begin(115200); Serial.println("LoRa Receiver Test"); //SPI LoRa pins SPI.begin(SCK, MISO, MOSI, SS); LoRa.setPins(SS, RST, DIO0); //setup LoRa transceiver module delay(4000); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("LoRa Initializing OK!"); delay(500); pixels.begin(); } void loop() { Serial.print("Sending packet: "); Serial.println(counter); //Send LoRa packet to receiver LoRa.beginPacket(); LoRa.print("hello "); LoRa.print(counter); <p>pixels.setPixelColor(0, pixels.Color(0, 255, 0));<br> pixels.show(); delay(200); pixels.setPixelColor(0, pixels.Color(0, 0, 255)); pixels.show(); delay(200);</p> LoRa.endPacket(); counter++; delay(1000); // wait for a second }
- Lora Receiver Sketch
#include <SPI.h> // include libraries #include <LoRa.h> #include <Adafruit_NeoPixel.h> #define NUMPIXELS 1 #define PIN 25 // Digital IO pin connected to the NeoPixels. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define PIXEL_COUNT 1 #define SCK 18 #define MISO 19 #define MOSI 23 #define SS 2 #define RST 5 #define DIO0 4 //433E6 for Asia //866E6 for Europe //915E6 for North America #define BAND 433E6 bool oldState = HIGH; String LoRaData; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("LoRa Receiver Test"); //SPI LoRa pins SPI.begin(SCK, MISO, MOSI,SS); LoRa.setPins(SS, RST, DIO0); //setup LoRa transceiver module delay(4000); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("LoRa Initializing OK!"); delay(500); pixels.begin(); } void loop() { int packetSize = LoRa.parsePacket(); if (packetSize) { //received a packet Serial.print("Received packet "); //read packet while (LoRa.available()) { LoRaData = LoRa.readString(); Serial.print(LoRaData); pixels.setPixelColor(0, pixels.Color(0, 255, 0)); pixels.show(); delay(200); pixels.setPixelColor(0, pixels.Color(0, 0, 255)); pixels.show(); delay(200); } //print RSSI of packet int rssi = LoRa.packetRssi(); Serial.print(" with RSSI "); Serial.println(rssi); } }
Understanding the Code.
- We begin by adding the necessary libraries.
include <SPI.h> // include libraries #include <LoRa.h> #include <Adafruit_NeoPixel.h><br>
-
In the below lines, the number of RGB LEDs and the GPIO pin of ESP32 used to make the connection are defined.
#define NUMPIXELS 1 #define PIN 25 // Digital IO pin connected to the NeoPixels. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);<br>
-
In the following lines, the GPIOs for LoRa's SPI connection is defined.
#define SCK 18 #define MISO 19 #define MOSI 23 #define SS 2 #define RST 5 #define DIO0 4<br>
- Next the LoRa frequency is defined.
#define BAND 433E6<br>
-
You initialize the counter variable that starts at 0.(for sender)
int counter = 0;<br>
-
You define a string variable for receive the data .(for receiver)
String LoRaData;
-
Next, in setup(), we initialize the Serial Monitor at a baud rate of 115200.
Serial.begin(115200); Serial.println("LoRa Receiver Test");<br>
- Then the SPI pins for the LoRa module are set.
SPI.begin(SCK, MISO, MOSI,SS); LoRa.setPins(SS, RST, DIO0);
-
The following lines initializes the LoRa module with a specified frequency.
delay(4000); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("LoRa Initializing OK!");<br>
- Next the RGB Led is initialized.
pixels.begin();
*** NOTE: The above lines of codes are common for both he the receiver and the sender.
Loop explanation (for sender)
- Value of initialized counter is printed.
Serial.print("Sending packet: "); Serial.println(counter);
- Then, you send the LoRa packets by initializing initialize a packet with the beginPacket() method.
LoRa.beginPacket();<br>
-
Write the Counter data into the packet using the print() method. A hello message is sent followed by the counter.
LoRa.print("hello "); LoRa.print(counter);<br>
- For every data sent, a color change in RGB LED is observed.
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); pixels.show(); delay(200); pixels.setPixelColor(0, pixels.Color(0, 0, 255)); pixels.show(); delay(200);<br>
-
Then, close the packet with the endPacket() method and increase the counter value by1.
LoRa.endPacket(); counter++; delay(1000);
Loop explanation (for receiver)
-
In the loop() the code checks if a new packet has been received using the parsePacket() method.
int packetSize = LoRa.parsePacket(); if (packetSize) {Serial.print("Received packet ");<br>
-
We'll read the contents of any new packets while it is available and the readString() function is used to read in the data.
while (LoRa.available()) { LoRaData = LoRa.readString(); Serial.print(LoRaData);<br>
-
For every data received, a color change in RGB LED is observed.
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); pixels.show(); delay(200); pixels.setPixelColor(0, pixels.Color(0, 0, 255)); pixels.show(); delay(200);<br>
-
Finally, RSSI of the received packet in dB is printed.
int rssi = LoRa.packetRssi(); Serial.print(" with RSSI "); Serial.println(rssi); <br>
To check more about the Norvi line up - www.norvi.lk