ESP32-S3 GPS and Wind Speed Logger with Dual OLED Displays and CAN Bus
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed around an ESP32-S3-DevKitC-1-N8R2 microcontroller, which interfaces with various peripherals including an SD card module, two OLED displays, a GPS module, and a CAN bus module. The primary functionalities include recording GPS data to an SD card, displaying speed in knots on one OLED display, and displaying wind speed from the CAN bus in NMEA 2000 format on the second OLED display.
Component List
ESP32-S3-DevKitC-1-N8R2
- Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: GND, 5Vin, 14, 13, 12, 11, 10, 9, 46, 3, 8, 18, 17, 16, 15, 7, 6, 5, 4, 3v3, TX, RX, 1, 2, 42, 41, 40, 39, 38, 37, 36, 35, 0, 45, 48, 47, 21, 20, 19
BE - 880
- Description: A GPS module.
- Pins: GND, VCC, SDA, TX, RX, SCL
SD SDHC
- Description: An SD card module for data storage.
- Pins: 3V3, CS, MOSI, CLK, MISO, GND
128x64 OLED Display (I2C IIC SPI Serial)
- Description: A 128x64 pixel OLED display.
- Pins: GND, SDA, SCL, VCC
CAN BUS
- Description: A CAN bus module for communication.
- Pins: INT, SCK, SI, SO, CS, GND, VCC, J1, J11, H, L, VDD
Wiring Details
ESP32-S3-DevKitC-1-N8R2
- GND: Connected to GND of OLED Display 1, OLED Display 2, SD SDHC, BE - 880, and CAN BUS.
- 3v3: Connected to VCC of OLED Display 1, OLED Display 2, SD SDHC, BE - 880, and CAN BUS.
- 5: Connected to CS of SD SDHC.
- 8: Connected to SDA of OLED Display 1 and OLED Display 2.
- 9: Connected to SCL of OLED Display 1 and OLED Display 2.
- 21: Connected to CS of CAN BUS.
- 42: Connected to MOSI of SD SDHC.
- 41: Connected to CLK of SD SDHC.
- 40: Connected to MISO of SD SDHC.
- 45: Connected to SCK of CAN BUS.
- 48: Connected to SI of CAN BUS.
- 47: Connected to SO of CAN BUS.
- TX: Connected to TX of BE - 880.
- RX: Connected to RX of BE - 880.
BE - 880
- GND: Connected to GND of ESP32-S3-DevKitC-1-N8R2.
- VCC: Connected to 3v3 of ESP32-S3-DevKitC-1-N8R2.
- TX: Connected to TX of ESP32-S3-DevKitC-1-N8R2.
- RX: Connected to RX of ESP32-S3-DevKitC-1-N8R2.
SD SDHC
- GND: Connected to GND of ESP32-S3-DevKitC-1-N8R2.
- 3V3: Connected to 3v3 of ESP32-S3-DevKitC-1-N8R2.
- CS: Connected to 5 of ESP32-S3-DevKitC-1-N8R2.
- MOSI: Connected to 42 of ESP32-S3-DevKitC-1-N8R2.
- CLK: Connected to 41 of ESP32-S3-DevKitC-1-N8R2.
- MISO: Connected to 40 of ESP32-S3-DevKitC-1-N8R2.
128x64 OLED Display (I2C IIC SPI Serial) - Display 1
- GND: Connected to GND of ESP32-S3-DevKitC-1-N8R2.
- SDA: Connected to 8 of ESP32-S3-DevKitC-1-N8R2.
- SCL: Connected to 9 of ESP32-S3-DevKitC-1-N8R2.
- VCC: Connected to 3v3 of ESP32-S3-DevKitC-1-N8R2.
128x64 OLED Display (I2C IIC SPI Serial) - Display 2
- GND: Connected to GND of ESP32-S3-DevKitC-1-N8R2.
- SDA: Connected to 8 of ESP32-S3-DevKitC-1-N8R2.
- SCL: Connected to 9 of ESP32-S3-DevKitC-1-N8R2.
- VCC: Connected to 3v3 of ESP32-S3-DevKitC-1-N8R2.
CAN BUS
- GND: Connected to GND of ESP32-S3-DevKitC-1-N8R2.
- VCC: Connected to 3v3 of ESP32-S3-DevKitC-1-N8R2.
- SCK: Connected to 45 of ESP32-S3-DevKitC-1-N8R2.
- SI: Connected to 48 of ESP32-S3-DevKitC-1-N8R2.
- SO: Connected to 47 of ESP32-S3-DevKitC-1-N8R2.
- CS: Connected to 21 of ESP32-S3-DevKitC-1-N8R2.
Code Documentation
/*
* This Arduino Sketch is for an ESP32-S3-DevKitC-1-N8R2 connected to various
* peripherals. It records GPS position to an SD card every second, displays
* speed in knots on the first OLED display, and displays wind speed from the
* CAN bus in NMEA 2000 format on the second OLED display.
*/
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <CAN.h>
// Pin definitions
#define SD_CS 5
#define OLED1_SDA 8
#define OLED1_SCL 9
#define OLED2_SDA 8
#define OLED2_SCL 9
#define CAN_CS 21
#define CAN_SCK 45
#define CAN_MISO 47
#define CAN_MOSI 48
// OLED display objects
Adafruit_SSD1306 display1(128, 64, &Wire, -1);
Adafruit_SSD1306 display2(128, 64, &Wire, -1);
// GPS data
String gpsData = "";
void setup() {
// Initialize serial communication
Serial.begin(115200);
while (!Serial);
Serial.println("Starting...");
// Initialize SD card
if (!SD.begin(SD_CS)) {
Serial.println("SD card initialization failed!");
while (1);
}
// Initialize OLED displays
Wire.begin(OLED1_SDA, OLED1_SCL);
if (!display1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED1 initialization failed!");
while (1);
}
if (!display2.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {
Serial.println("OLED2 initialization failed!");
while (1);
}
display1.clearDisplay();
display2.clearDisplay();
// Initialize CAN bus
CAN.setPins(CAN_CS, CAN_MISO, CAN_MOSI, CAN_SCK); // Move this line before CAN.begin()
if (!CAN.begin(500E3)) {
Serial.println("CAN bus initialization failed!");
while (1);
}
}
void loop() {
// Record GPS data to SD card
File dataFile = SD.open("gps.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(gpsData);
dataFile.close();
} else {
Serial.println("Error opening gps.txt");
}
// Display speed in knots on OLED1
display1.clearDisplay();
display1.setTextSize(1);
display1.setTextColor(SSD1306_WHITE);
display1.setCursor(0, 0);
display1.print("Speed: ");
display1.print(getSpeedInKnots());
display1.print(" knots");
display1.display();
// Display wind speed from CAN bus on OLED2
display2.clear