Skip to content

Commit 09bf8d6

Browse files
committed
first
0 parents  commit 09bf8d6

File tree

10 files changed

+649
-0
lines changed

10 files changed

+649
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# M5Cardputer GPS Logger
2+
3+
This project is a GPS logger using the M5Cardputer platform. It reads GPS data, displays it on the screen, and optionally saves the data to an SD card. The device operates in two modes: NORMAL mode and SLEEP mode. The SLEEP mode conserves power while still logging GPS data.
4+
5+
## Installation
6+
7+
- <b>M5Burner</b> : Search into M5CARDPUTER section and simply burn it
8+
- <b>Old school</b> : Build or take the firmware.bin from the github release and flash it
9+
10+
11+
## Usage
12+
13+
14+
- You will need a UART GPS module connected to the M5Cardputer and an inserted SD card.
15+
This has been tested with the [Grove GPS module](https://wiki.seeedstudio.com/Grove-GPS-Air530/)
16+
17+
- Select NORMAL or SLEEP mode
18+
19+
- <b>Normal:</b> Displays the GPS data on the screen every 3 seconds while saving the GPS data to the SD card every minute (can be turned off).
20+
21+
- <b>Sleep:</b> Saves the GPS data to the SD card every minute before entering light sleep mode. The Cardputer's screen is turned off, and it appears to be OFF.
22+
23+
- The GPS data will be saved in the file `gps_data.csv` at the root of the SD card.
24+
25+
## Controls
26+
27+
For NORMAL mode
28+
- <b> OK </b> Toggles SD card on/off.
29+
- <b>S</b> Toggles screen on/off.
30+
- <b>- and =</b> Adjusts brightness.

platformio.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:m5stack-stamps3]
12+
platform = espressif32
13+
board = m5stack-stamps3
14+
framework = arduino
15+
lib_deps =
16+
m5stack/M5Cardputer@^1.0.3
17+
mikalhart/TinyGPSPlus@^1.0.3
18+

src/display.cpp

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#include "display.h"
2+
3+
const int lineSpacing = 20; // Set the line spacing for the display
4+
const int leftMargin = 10; // Set the left margin for the display
5+
const int infoAreaTop = 0; // Top position of the GPS info area
6+
const int infoAreaHeight = 100; // Height of the GPS info area
7+
int lastSecond = -1;
8+
int brightness = M5Cardputer.Display.getBrightness();
9+
10+
11+
void displayWelcomeScreen() {
12+
M5Cardputer.Display.setRotation(1);
13+
14+
M5Cardputer.Display.drawRect(20, 20, 200, 40, TFT_LIGHTGRAY);
15+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
16+
M5Cardputer.Display.setCursor(32, 28);
17+
M5Cardputer.Display.setTextSize(3.4);
18+
M5Cardputer.Display.printf("GPS to SD");
19+
20+
M5Cardputer.Display.setTextSize(1.2);
21+
M5Cardputer.Display.setCursor(20,70);
22+
M5Cardputer.Display.setTextColor(TFT_ORANGE);
23+
M5Cardputer.Display.printf("Save GPS data");
24+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
25+
M5Cardputer.Display.printf(" to your SD card");
26+
M5Cardputer.Display.setCursor(26, 85);
27+
M5Cardputer.Display.printf("in a .csv file");
28+
M5Cardputer.Display.setTextColor(TFT_ORANGE);
29+
M5Cardputer.Display.printf(" every minute");
30+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
31+
delay(1000);
32+
}
33+
34+
void displaySaveState(bool isSdSaving) {
35+
M5Cardputer.Display.fillRect(180, infoAreaHeight, M5Cardputer.Display.width(), M5Cardputer.Display.height(), TFT_BLACK); // Reset area
36+
37+
M5Cardputer.Display.drawRect(20, 104, 150, 1, TFT_DARKGRAY); // delimiter
38+
39+
M5Cardputer.Display.setTextSize(1);
40+
M5Cardputer.Display.setCursor(20, 110);
41+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
42+
M5Cardputer.Display.printf("Log on SD each min [ ok ]");
43+
44+
if (isSdSaving) {
45+
M5Cardputer.Display.drawRect(178, 103, 35, 27, TFT_GREEN);
46+
M5Cardputer.Display.setCursor(189, 113);
47+
M5Cardputer.Display.setTextColor(TFT_GREEN);
48+
M5Cardputer.Display.printf("ON");
49+
} else {
50+
M5Cardputer.Display.drawRect(178, 103, 35, 27, TFT_RED);
51+
M5Cardputer.Display.setCursor(187, 113);
52+
M5Cardputer.Display.setTextColor(TFT_RED);
53+
M5Cardputer.Display.printf("OFF");
54+
}
55+
M5Cardputer.Display.setCursor(20, 122);
56+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
57+
M5Cardputer.Display.printf("Turn off the screen [ S ]");
58+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
59+
}
60+
61+
62+
void displaySelectionScreen(bool isSleepMode) {
63+
M5Cardputer.Display.clear();
64+
M5Cardputer.Display.setTextSize(1.5);
65+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
66+
M5Cardputer.Display.setCursor(70, 10);
67+
M5Cardputer.Display.printf("Select Mode:");
68+
M5Cardputer.Display.setTextSize(3);
69+
70+
// Draw Normal Mode Button
71+
if (isSleepMode == false) {
72+
M5Cardputer.Display.fillRect(20, 30, 200, 40, TFT_LIGHTGRAY);
73+
M5Cardputer.Display.drawRect(20, 30, 200, 40, TFT_BLACK);
74+
M5Cardputer.Display.setTextColor(TFT_BLACK);
75+
} else {
76+
M5Cardputer.Display.fillRect(20, 30, 200, 40, TFT_BLACK);
77+
M5Cardputer.Display.drawRect(20, 30, 200, 40, TFT_LIGHTGRAY);
78+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
79+
}
80+
M5Cardputer.Display.setCursor(70, 40);
81+
M5Cardputer.Display.printf("Normal");
82+
83+
// Draw Sleep Mode Button
84+
if (isSleepMode == true) {
85+
M5Cardputer.Display.fillRect(20, 80, 200, 40, TFT_LIGHTGRAY);
86+
M5Cardputer.Display.drawRect(20, 80, 200, 40, TFT_BLACK);
87+
M5Cardputer.Display.setTextColor(TFT_BLACK);
88+
} else {
89+
M5Cardputer.Display.fillRect(20, 80, 200, 40, TFT_BLACK);
90+
M5Cardputer.Display.drawRect(20, 80, 200, 40, TFT_LIGHTGRAY);
91+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
92+
}
93+
M5Cardputer.Display.setCursor(77, 90);
94+
M5Cardputer.Display.printf("Sleep");
95+
}
96+
97+
98+
void displayNormalScreen(TinyGPSPlus &gps) {
99+
int currentLine = 0;
100+
int margin = 20;
101+
int spacing = 17;
102+
103+
int currentSecond = gps.time.second();
104+
105+
// Vérifier si 3 secondes se sont écoulées depuis la dernière exécution
106+
if ((currentSecond < lastSecond && (currentSecond + 60 - lastSecond) < 3) ||
107+
(currentSecond >= lastSecond && (currentSecond - lastSecond) < 3)) {
108+
109+
if (lastSecond != -1) // if -1, it's the first render
110+
return;
111+
}
112+
113+
lastSecond = currentSecond;
114+
115+
M5Cardputer.Display.fillRect(0, infoAreaTop, M5Cardputer.Display.width(), infoAreaHeight, TFT_BLACK); // Clear the info area
116+
M5Cardputer.Display.setTextSize(2);
117+
118+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
119+
M5Cardputer.Display.printf("Lat: %.8f", gps.location.lat()); // Print the latitude to the LCD
120+
121+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
122+
M5Cardputer.Display.printf("Long: %.8f", gps.location.lng()); // Print the longitude to the LCD
123+
124+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
125+
M5Cardputer.Display.printf("Speed: %.2f km/h", gps.speed.kmph()); // Print the speed to the LCD
126+
127+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
128+
M5Cardputer.Display.printf("Satellites: %d", gps.satellites.value()); // Print the number of satellites to the LCD
129+
130+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
131+
M5Cardputer.Display.printf("Date: %02d/%02d/%02d", gps.date.day(), gps.date.month(), gps.date.year()); // Print the date to the LCD
132+
133+
int hour = gps.time.hour() - 4; // Adjust the hour for the time zone
134+
if (hour < 0)
135+
hour += 24; // If the hour is negative, add 24
136+
137+
M5Cardputer.Display.setCursor(margin, spacing * currentLine++);
138+
M5Cardputer.Display.printf("Time: %02d:%02d:%02d", hour, gps.time.minute(), gps.time.second()); // Print the time to the LCD
139+
}
140+
141+
142+
void displaySleepScreen() {
143+
M5Cardputer.Display.drawRect(15, 15, 210, 40, TFT_LIGHTGRAY);
144+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
145+
M5Cardputer.Display.setCursor(23, 23);
146+
M5Cardputer.Display.setTextSize(3.4);
147+
M5Cardputer.Display.printf("Sleep Mode");
148+
149+
M5Cardputer.Display.setTextSize(1.5);
150+
M5Cardputer.Display.setCursor(42, 70);
151+
M5Cardputer.Display.printf("Press");
152+
153+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
154+
M5Cardputer.Display.fillRect(91, 68, 27, 15, TFT_DARKGRAY);
155+
M5Cardputer.Display.printf(" OK ");
156+
157+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
158+
M5Cardputer.Display.printf("to start");
159+
160+
M5Cardputer.Display.setTextSize(1);
161+
M5Cardputer.Display.setCursor(26, 92);
162+
M5Cardputer.Display.printf("Save position on SD every 1 min");
163+
164+
M5Cardputer.Display.fillRect(10, 108, 220, 15, TFT_RED);
165+
M5Cardputer.Display.setCursor(15, 112);
166+
M5Cardputer.Display.printf("The Cardputer will appear to be off");
167+
}
168+
169+
170+
void displayStartSleepScreen(bool gpsState) {
171+
M5Cardputer.Display.clear();
172+
M5Cardputer.Display.drawRect(1, 1, 239, 134, TFT_RED); // Red frame all over the screen
173+
M5Cardputer.Display.setTextSize(1);
174+
175+
if (!gpsState) {
176+
displayNoGps();
177+
M5Cardputer.Display.setTextSize(1);
178+
M5Cardputer.Display.setCursor(30, 77);
179+
M5Cardputer.Display.println("We can't proceed without a GPS");
180+
M5Cardputer.Display.setCursor(32, 92);
181+
M5Cardputer.Display.println("Please plug it in to continue");
182+
return;
183+
}
184+
185+
M5Cardputer.Display.setCursor(27, 60);
186+
M5Cardputer.Display.println("Cardputer will enter sleep mode");
187+
M5Cardputer.Display.setCursor(21, 73);
188+
M5Cardputer.Display.println("Logging the position every minute");
189+
delay(1000);
190+
191+
M5Cardputer.Display.setTextSize(3);
192+
M5Cardputer.Display.setCursor(73, 90);
193+
for (int i = 0; i < 5; i++) {
194+
M5Cardputer.Display.printf(".");
195+
delay(1000);
196+
}
197+
delay(3000);
198+
displayClear();
199+
M5Cardputer.Display.sleep(); // Turn off the display
200+
delay(1000);
201+
}
202+
203+
204+
void displayDecrementBrightness() {
205+
brightness -= 30;
206+
if (brightness < 0) brightness = 0;
207+
M5Cardputer.Display.setBrightness(brightness);
208+
}
209+
210+
211+
void displayIncrementBrightness() {
212+
brightness += 30;
213+
if (brightness > 255) brightness = 255;
214+
M5Cardputer.Display.setBrightness(brightness);
215+
}
216+
217+
218+
void displayGpsState(bool state) {
219+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
220+
M5Cardputer.Display.setTextSize(1.1);
221+
M5Cardputer.Display.setCursor(153, 105);
222+
M5Cardputer.Display.printf("GPS : ");
223+
224+
if (state) {
225+
M5Cardputer.Display.setTextColor(TFT_GREEN);
226+
M5Cardputer.Display.printf("OK");
227+
} else {
228+
M5Cardputer.Display.setTextColor(TFT_RED);
229+
M5Cardputer.Display.printf("NO");
230+
}
231+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
232+
}
233+
234+
235+
void displaySdCardState(bool state) {
236+
M5Cardputer.Display.fillRect(35, 104, 220, 30, TFT_BLACK);
237+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
238+
M5Cardputer.Display.setTextSize(1.1);
239+
M5Cardputer.Display.setCursor(36, 105);
240+
M5Cardputer.Display.printf("SD Card : ");
241+
242+
if (state) {
243+
M5Cardputer.Display.setTextColor(TFT_GREEN);
244+
M5Cardputer.Display.printf("MOUNTED");
245+
} else {
246+
M5Cardputer.Display.setTextColor(TFT_RED);
247+
M5Cardputer.Display.printf(" IS NOT MOUNTED");
248+
}
249+
250+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
251+
}
252+
253+
254+
void displayClear() {
255+
M5Cardputer.Display.clear();
256+
}
257+
258+
void displayNoGps() {
259+
M5Cardputer.Display.setTextSize(3);
260+
M5Cardputer.Display.setTextColor(TFT_RED);
261+
M5Cardputer.Display.setCursor(65, 45);
262+
M5Cardputer.Display.printf("NO GPS");
263+
M5Cardputer.Display.setTextColor(TFT_LIGHTGRAY);
264+
}

src/display.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef DISPLAY_H
2+
#define DISPLAY_H
3+
4+
#include <M5Cardputer.h>
5+
#include <TinyGPSPlus.h>
6+
7+
void displayNormalScreen(TinyGPSPlus &gps);
8+
void displaySaveState(bool isSdSaving);
9+
void displayWelcomeScreen();
10+
void displaySleepScreen();
11+
void displaySelectionScreen(bool isSleepMode);
12+
void displayStartSleepScreen(bool gpsState);
13+
void displayDecrementBrightness();
14+
void displayIncrementBrightness();
15+
void displayGpsState(bool state);
16+
void displaySdCardState(bool state);
17+
void displayClear();
18+
void displayNoGps();
19+
20+
#endif

0 commit comments

Comments
 (0)