Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 and LoRa-Based GNSS and IMU Data Logger with Wireless Transmission

View and Edit Project In Cirkit DesignerImage of ESP32 and LoRa-Based GNSS and IMU Data Logger with Wireless Transmission

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)

LoRa Ra-02 SX1278

Adafruit BNO055 STEMMA QT

L89HA Breakout

Wiring Details

ESP32 (Primary)

ESP32 (Secondary)

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);
  }
}