Skip to content

Commit 59ffc27

Browse files
committed
Add logging menu and log file creation
1 parent d78ba26 commit 59ffc27

File tree

7 files changed

+359
-36
lines changed

7 files changed

+359
-36
lines changed

Firmware/RTK_Enclosed/RTK_Enclosed.ino

Lines changed: 117 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
(Fixed) Something wierd happened with v1.13. Fix type changed? LED is not turning on even in float mode. (Disable SBAS)
2525
(Done) Check for v1.13 of ZED firmware. Display warning if not matching.
2626
(Fixed) ESP32 crashing when in rover mode, when LEDs change? https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/issues/124
27-
Set static position based on user input
28-
Wait for better pos accuracy before starting a survey in
27+
(Done) Wait for better pos accuracy before starting a survey in
2928
Can we add NTRIP reception over Wifi to the ESP32 to aid in survey in time?
3029
Test lots of bt switching from setup switch. Test for null handles: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
31-
32-
BT cast batt, RTK status, etc
30+
(Done) Transmit battery level, RTK status, etc
31+
32+
Save settings to file
33+
I should be able to start a base anytime and have it log
34+
Test that we can log and do full BT + NTREIP reliably
35+
Update repo
36+
Clean up dirs
3337
3438
Menu System:
3539
Test system? Connection to GPS?
@@ -49,8 +53,8 @@ const int FIRMWARE_VERSION_MINOR = 6;
4953

5054
#include "settings.h"
5155

56+
//Hardware connections
5257
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
53-
//Hardware connections v11
5458
const int positionAccuracyLED_1cm = 2;
5559
const int baseStatusLED = 4;
5660
const int baseSwitch = 5;
@@ -70,19 +74,15 @@ const int batteryLevel_alert = 36;
7074
#include <SPI.h>
7175
#include <SdFat.h> //SdFat (FAT32) by Bill Greiman: http://librarymanager/All#SdFat
7276
SdFat sd;
73-
SdFile sensorDataFile; //File that all sensor data is written to
74-
SdFile serialDataFile; //File that all incoming serial data is written to
75-
//#define PRINT_LAST_WRITE_TIME // Uncomment this line to enable the 'measure the time between writes' diagnostic
77+
SdFile gnssDataFile; //File that all gnss data is written to
7678

77-
char sensorDataFileName[30] = ""; //We keep a record of this file name so that we can re-open it upon wakeup from sleep
78-
char serialDataFileName[30] = ""; //We keep a record of this file name so that we can re-open it upon wakeup from sleep
79-
const int sdPowerDownDelay = 100; //Delay for this many ms before turning off the SD card power
79+
unsigned long lastDataLogSyncTime = 0; //Used to record to SD every half second
8080
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
8181

8282
#include <Wire.h> //Needed for I2C to GPS
8383

84+
//GPS configuration
8485
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
85-
//All the I2C and GPS stuff
8686
#define MAX_PAYLOAD_SIZE 384 // Override MAX_PAYLOAD_SIZE for getModuleInfo which can return up to 348 bytes
8787

8888
#include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS
@@ -114,10 +114,10 @@ char latestZEDFirmware[] = "FWVER=HPG 1.13";
114114
uint8_t gnssUpdateRate = 4; //Increasing beyond 1Hz with SV sentence on can drown the BT link
115115
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
116116

117+
//Battery fuel gauge and PWM LEDs
117118
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
118-
//Bits for the battery level LEDs
119119
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library
120-
SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048
120+
SFE_MAX1704X lipo(MAX1704X_MAX17048);
121121

122122
// setting PWM properties
123123
const int freq = 5000;
@@ -126,11 +126,10 @@ const int ledGreenChannel = 1;
126126
const int resolution = 8;
127127
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
128128

129+
//Hardware serial and BT buffers
129130
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
130-
//Setup hardware serial and BT buffers
131131
#include "BluetoothSerial.h"
132132
BluetoothSerial SerialBT;
133-
char deviceName[20]; //The serial string that is broadcast. Ex: 'Surveyor Base-BC61'
134133

135134
HardwareSerial GPS(2);
136135
#define RXD2 16
@@ -141,6 +140,17 @@ uint8_t rBuffer[SERIAL_SIZE_RX]; //Buffer for reading F9P
141140
uint8_t wBuffer[SERIAL_SIZE_RX]; //Buffer for writing to F9P
142141
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
143142

143+
//External Display
144+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
145+
#include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED
146+
#include "icons.h"
147+
148+
#define PIN_RESET 9
149+
#define DC_JUMPER 1
150+
MicroOLED oled(PIN_RESET, DC_JUMPER);
151+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
152+
153+
144154
//Freeze and blink LEDs if we hit a bad error
145155
typedef enum
146156
{
@@ -179,13 +189,17 @@ enum returnStatus {
179189

180190
//Global variables
181191
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
192+
uint8_t unitMACAddress[6]; //Use MAC address in BT broadcast and display
193+
char deviceName[20]; //The serial string that is broadcast. Ex: 'Surveyor Base-BC61'
182194
const byte menuTimeout = 15; //Menus will exit/timeout after this number of seconds
183195
bool inTestMode = false; //Used to re-route BT traffic while in test sub menu
196+
int battLevel = 0; //SOC measured from fuel gauge, in %
184197

185198
uint32_t lastBluetoothLEDBlink = 0;
186199
uint32_t lastRoverUpdate = 0;
187200
uint32_t lastBaseUpdate = 0;
188201
uint32_t lastBattUpdate = 0;
202+
uint32_t lastDisplayUpdate = 0;
189203

190204
uint32_t lastTime = 0;
191205
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -229,6 +243,10 @@ void setup()
229243
setupLiPo(); //Configure battery fuel guage monitor
230244
checkBatteryLevels(); //Display initial battery level
231245

246+
//Get unit MAC address
247+
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
248+
unitMACAddress[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
249+
232250
SerialBT.register_callback(btCallback);
233251
if (startBluetooth() == false)
234252
{
@@ -293,11 +311,25 @@ void setup()
293311
Serial.println(F("GPS configuration complete"));
294312

295313
beginSD(); //Test if SD is present
296-
if(online.microSD == true)
314+
if (online.microSD == true)
297315
{
298316
Serial.println(F("microSD card online"));
299317
}
300318

319+
//Check if an external Qwiic OLED is attached
320+
beginDisplay();
321+
if (online.display == true)
322+
{
323+
Serial.println(F("Display online"));
324+
}
325+
326+
//Display splash of some sort
327+
if (online.display == true)
328+
{
329+
oled.drawIcon(1, 35, Antenna_Width, Antenna_Height, Antenna, sizeof(Antenna), true);
330+
oled.display();
331+
}
332+
301333
danceLEDs(); //Turn on LEDs like a car dashboard
302334

303335
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
@@ -362,11 +394,64 @@ void loop()
362394

363395
updateBattLEDs();
364396

397+
updateDisplay();
398+
365399
//Menu system via ESP32 USB connection
366400
if (Serial.available()) menuMain(); //Present user menu
367401

368-
delay(10); //Required if no other I2C or functions are called
402+
//Create files or close files as needed
403+
if (settings.zedOutputLogging == true && online.dataLogging == false)
404+
{
405+
beginDataLogging();
406+
}
407+
else if (settings.zedOutputLogging == false && online.dataLogging == true)
408+
{
409+
//Close down file
410+
gnssDataFile.sync();
411+
gnssDataFile.close();
412+
online.dataLogging = false;
413+
}
414+
415+
delay(10); //A small delay prevents panic if no other I2C or functions are called
416+
}
417+
418+
void updateDisplay()
419+
{
369420

421+
//Update the display if connected
422+
if (online.display == true)
423+
{
424+
if (millis() - lastDisplayUpdate > 1000)
425+
{
426+
lastDisplayUpdate = millis();
427+
Serial.println("Display update");
428+
429+
//oled.clear(PAGE); // Clear the display's internal memory
430+
//oled.clear(ALL); // Clear the library's display buffer
431+
432+
if (battLevel < 25)
433+
oled.drawIcon(45, 0, Battery_0_Width, Battery_0_Height, Battery_0, sizeof(Battery_0), true);
434+
else if (battLevel < 50)
435+
oled.drawIcon(45, 0, Battery_1_Width, Battery_1_Height, Battery_1, sizeof(Battery_1), true);
436+
else if (battLevel < 75)
437+
oled.drawIcon(45, 0, Battery_2_Width, Battery_2_Height, Battery_2, sizeof(Battery_2), true);
438+
else //batt level > 75
439+
oled.drawIcon(45, 0, Battery_3_Width, Battery_3_Height, Battery_3, sizeof(Battery_3), true);
440+
441+
//Bluetooth Address
442+
char macAddress[5];
443+
sprintf(macAddress, "%02X%02X", unitMACAddress[4], unitMACAddress[5]);
444+
Serial.printf("MAC: %s", macAddress);
445+
446+
//oled.setFontType(1);
447+
oled.setFontType(0); //Set font to smallest
448+
oled.setCursor(0, 4);
449+
// oled.print(macAddress);
450+
oled.print("O");
451+
452+
oled.display();
453+
}
454+
}
370455
}
371456

372457
void beginSD()
@@ -409,3 +494,17 @@ void beginSD()
409494
online.microSD = false;
410495
}
411496
}
497+
498+
void beginDisplay()
499+
{
500+
//0x3D is default on Qwiic board
501+
if (isConnected(0x3D) == true || isConnected(0x3C) == true)
502+
{
503+
online.display = true;
504+
505+
//Init display
506+
oled.begin(); // Initialize the OLED
507+
oled.clear(PAGE); // Clear the display's internal memory
508+
oled.clear(ALL); // Clear the library's display buffer
509+
}
510+
}

Firmware/RTK_Enclosed/System.ino

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ uint8_t settingPayload[MAX_PAYLOAD_SIZE]; //This array holds the payload data by
55
//This allows multiple units to be on at same time
66
bool startBluetooth()
77
{
8-
uint8_t mac[6];
9-
esp_read_mac(mac, ESP_MAC_WIFI_STA);
10-
mac[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
11-
128
if (digitalRead(baseSwitch) == HIGH)
139
{
1410
//Rover mode
15-
sprintf(deviceName, "Surveyor Rover-%02X%02X", mac[4], mac[5]);
11+
sprintf(deviceName, "Surveyor Rover-%02X%02X", unitMACAddress[4], unitMACAddress[5]);
1612
}
1713
else
1814
{
1915
//Base mode
20-
sprintf(deviceName, "Surveyor Base-%02X%02X", mac[4], mac[5]);
16+
sprintf(deviceName, "Surveyor Base-%02X%02X", unitMACAddress[4], unitMACAddress[5]);
2117
}
2218

2319
if (SerialBT.begin(deviceName) == false)
@@ -88,6 +84,24 @@ void F9PSerialReadTask(void *e)
8884
{
8985
SerialBT.write(rBuffer, s);
9086
}
87+
88+
//If user wants to log, record to SD
89+
if (settings.zedOutputLogging == true)
90+
{
91+
if (online.microSD == true)
92+
{
93+
gnssDataFile.write(rBuffer, s);
94+
95+
//Force sync every 500ms
96+
if (millis() - lastDataLogSyncTime > 500)
97+
{
98+
lastDataLogSyncTime = millis();
99+
gnssDataFile.sync();
100+
if (settings.frequentFileAccessTimestamps == true)
101+
updateDataFileAccess(&gnssDataFile); // Update the file access time & date
102+
}
103+
}
104+
}
91105
}
92106
taskYIELD();
93107
}
@@ -492,7 +506,7 @@ void checkBatteryLevels()
492506
{
493507
String battMsg = "";
494508

495-
int battLevel = lipo.getSOC();
509+
battLevel = lipo.getSOC();
496510

497511
battMsg += "Batt (";
498512
battMsg += battLevel;
@@ -536,6 +550,7 @@ void checkBatteryLevels()
536550
battMsg += "\n\r";
537551
SerialBT.print(battMsg);
538552
Serial.print(battMsg);
553+
539554
}
540555

541556
//Configure the on board MAX17048 fuel gauge
@@ -554,3 +569,12 @@ void setupLiPo()
554569

555570
Serial.println(F("MAX17048 configuration complete"));
556571
}
572+
573+
//Ping an I2C device and see if it responds
574+
bool isConnected(uint8_t deviceAddress)
575+
{
576+
Wire.beginTransmission(deviceAddress);
577+
if (Wire.endTransmission() == 0)
578+
return true;
579+
return false;
580+
}

Firmware/RTK_Enclosed/icons.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//Create a bitmap then use http://en.radzio.dxp.pl/bitmap_converter/ to generate output
2+
//Make sure the bitmap is n*8 pixels tall (pad white pixels to lower area as needed)
3+
//Otherwise the bitmap bitmap_converter will compress some of the bytes together
4+
5+
uint8_t CrossHair [] = {
6+
0x80, 0x80, 0xF0, 0x88, 0x84, 0x84, 0x84, 0x7F, 0x84, 0x84, 0x84, 0x88, 0xF0, 0x80, 0x80, 0x00,
7+
0x00, 0x07, 0x08, 0x10, 0x10, 0x10, 0x7F, 0x10, 0x10, 0x10, 0x08, 0x07, 0x00, 0x00,
8+
};
9+
int CrossHair_Height = 15;
10+
int CrossHair_Width = 15;
11+
12+
uint8_t Antenna [] = {
13+
0x7E, 0xC3, 0x03, 0x06, 0x04, 0x0C, 0x18, 0x38, 0x7C, 0xCE, 0x84, 0x00, 0x00, 0x01, 0x1F, 0x1E,
14+
0x1C, 0x0C, 0x08, 0x08, 0x0C, 0x04, 0x07, 0x07,
15+
};
16+
int Antenna_Height = 13;
17+
int Antenna_Width = 12;
18+
19+
uint8_t Rover [] = {
20+
0x3C, 0x24, 0x64, 0xF4, 0xF7, 0x61, 0x21, 0x21, 0x21, 0x61, 0xF7, 0xF4, 0x64, 0x3C, 0x18,
21+
};
22+
int Rover_Height = 8;
23+
int Rover_Width = 15;
24+
25+
uint8_t Base [] = {
26+
0x00, 0xFF, 0x23, 0x13, 0x08, 0x88, 0x88, 0x88, 0x88, 0x08, 0x10, 0x20, 0xC0, 0x00, 0x0E, 0x09,
27+
0x08, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x09, 0x0E,
28+
};
29+
int Base_Height = 12;
30+
int Base_Width = 14;
31+
32+
uint8_t Battery_3 [] = {
33+
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01,
34+
0x0F, 0x08, 0xF8, 0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B,
35+
0x0B, 0x0B, 0x08, 0x0F, 0x01, 0x01,
36+
};
37+
int Battery_3_Height = 12;
38+
int Battery_3_Width = 19;
39+
40+
uint8_t Battery_2 [] = {
41+
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
42+
0x0F, 0x08, 0xF8, 0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x08,
43+
0x08, 0x08, 0x08, 0x0F, 0x01, 0x01,
44+
};
45+
int Battery_2_Height = 12;
46+
int Battery_2_Width = 19;
47+
48+
uint8_t Battery_1 [] = {
49+
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
50+
0x0F, 0x08, 0xF8, 0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
51+
0x08, 0x08, 0x08, 0x0F, 0x01, 0x01,
52+
};
53+
int Battery_1_Height = 12;
54+
int Battery_1_Width = 19;
55+
56+
uint8_t Battery_0 [] = {
57+
0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
58+
0x0F, 0x08, 0xF8, 0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
59+
0x08, 0x08, 0x08, 0x0F, 0x01, 0x01,
60+
};
61+
int Battery_0_Height = 12;
62+
int Battery_0_Width = 19;

0 commit comments

Comments
 (0)