ESP32 and LoRa-Based GNSS and IMU Data Logger with Wireless Transmission
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves two ESP32 microcontrollers, a LoRa Ra-02 SX1278 module, an Adafruit BNO055 sensor, and an L89HA GNSS module. The primary ESP32 microcontroller interfaces with the BNO055 sensor, the GNSS module, and a LoRa module to collect and transmit data. The secondary ESP32 microcontroller is used to receive data via another LoRa module.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
LoRa Ra-02 SX1278
- Description: A long-range transceiver module for wireless communication.
- Pins: GND, NSS, MOSI, MISO, SCK, D105, DI04, 3.3V, RST, DI00, DI01, D102, DI03
Adafruit BNO055 STEMMA QT
- Description: A 9-DOF absolute orientation sensor.
- Pins: INT_3V, I2CADDR_3V, PS0_3V, PS1_3V, VCC, 3.3V, GND, SCL, SDA, RESET
L89HA Breakout
- Description: A GNSS module for GPS data.
- Pins: TX, RX, 3.3, GND
Wiring Details
ESP32 (Primary)
- D23 connected to LoRa Ra-02 SX1278 (MOSI)
- D22 connected to Adafruit BNO055 STEMMA QT (SCL)
- TX0 connected to L89HA Breakout (RX)
- RX0 connected to L89HA Breakout (TX)
- D21 connected to Adafruit BNO055 STEMMA QT (SDA)
- D19 connected to LoRa Ra-02 SX1278 (MISO)
- D18 connected to LoRa Ra-02 SX1278 (SCK)
- D5 connected to LoRa Ra-02 SX1278 (NSS)
- GND connected to Adafruit BNO055 STEMMA QT (GND), L89HA Breakout (GND), LoRa Ra-02 SX1278 (GND)
- 3V3 connected to Adafruit BNO055 STEMMA QT (3.3V), L89HA Breakout (3.3), LoRa Ra-02 SX1278 (3.3V)
ESP32 (Secondary)
- D23 connected to LoRa Ra-02 SX1278 (MOSI)
- D19 connected to LoRa Ra-02 SX1278 (MISO)
- D18 connected to LoRa Ra-02 SX1278 (SCK)
- D5 connected to LoRa Ra-02 SX1278 (NSS)
- GND connected to LoRa Ra-02 SX1278 (GND)
- 3V3 connected to LoRa Ra-02 SX1278 (3.3V)
Code Documentation
Primary ESP32 Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <HardwareSerial.h>
#include <SPI.h>
#include <LoRa.h>
#include <TinyGPS++.h>
// BNO055 sensor
Adafruit_BNO055 bno = Adafruit_BNO055(55);
// GNSS module
HardwareSerial GNSS(1);
TinyGPSPlus gps;
// LoRa module pins
#define LORA_SS 5
#define LORA_RST 14
#define LORA_DIO0 2
void setup() {
Serial.begin(115200);
GNSS.begin(9600, SERIAL_8N1, 16, 17); // RX, TX
// Initialize BNO055
if (!bno.begin()) {
Serial.println("No BNO055 detected!");
while (1);
}
bno.setExtCrystalUse(true);
// Initialize LoRa
SPI.begin(18, 19, 23);
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
if (!LoRa.begin(433E6)) { // Set frequency to 433 MHz
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSyncWord(0xF3); // Set sync word
}
void loop() {
// Get BNO055 data
sensors_event_t event;
bno.getEvent(&event);
// Get GNSS data
while (GNSS.available() > 0) {
gps.encode(GNSS.read());
}
// Ensure GNSS data is valid
String gnssData = "";
if (gps.location.isValid()) {
gnssData += String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + ",";
} else {
gnssData += "Invalid GNSS data,Invalid GNSS data,";
}
if (gps.date.isValid()) {
gnssData += String(gps.date.year()) + "," + String(gps.date.month()) + "," + String(gps.date.day()) + ",";
} else {
gnssData += "Invalid date,Invalid date,Invalid date,";
}
if (gps.time.isValid()) {
gnssData += String(gps.time.hour()) + "," + String(gps.time.minute()) + "," + String(gps.time.second()) + ",";
} else {
gnssData += "Invalid time,Invalid time,Invalid time,";
}
if (gps.speed.isValid()) {
gnssData += String(gps.speed.kmph()) + ",";
} else {
gnssData += "Invalid speed,";
}
if (gps.altitude.isValid()) {
gnssData += String(gps.altitude.meters()) + ",";
} else {
gnssData += "Invalid altitude,";
}
if (gps.course.isValid()) {
gnssData += String(gps.course.deg()) + ",";
} else {
gnssData += "Invalid course,";
}
// Format data as CSV
String data = String(event.orientation.x) + "," +
String(event.orientation.y) + "," +
String(event.orientation.z) + "," +
gnssData;
// Transmit data via LoRa
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
// Wait for 1 second
delay(1000);
}
Secondary ESP32 Code
#include <SPI.h>
#include <LoRa.h>
// LoRa module pins
#define LORA_SS 5
#define LORA_RST 14
#define LORA_DIO0 2
void setup() {
Serial.begin(115200);
// Initialize LoRa
SPI.begin(18, 19, 23);
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
if (!LoRa.begin(433E6)) { // Set frequency to 433 MHz
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSyncWord(0xF3); // Set sync word
}
void loop() {
// Try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// Read packet
String receivedData = "";
while (LoRa.available()) {
receivedData += (char)LoRa.read();
}
// Print received data
Serial.println("Received data: " + receivedData);
}
}