Devices & Components
10 jumper wires 150mm male
Neo6m GPS Module
Breadboard 100x160
ESP32
0.91 Inch 128x32 IIC I2C Blue OLED LCD Display DIY Oled Module SSD1306 Driver IC DC 3.3V 5V For Arduino PIC
Software & Tools
ARDUINO IOT REMOTE
Arduino IDE
Arduino IoT Cloud
Project description
Code
Main Code
cpp
Copy this onto Arduino IOT Cloud
1#include <TinyGPS++.h> 2#include <SoftwareSerial.h> 3#include <Arduino.h> 4#include <U8g2lib.h> 5#include <Wire.h> 6#include "thingProperties.h" 7 8U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); 9 10float lat; 11float lat_NEW; 12 13float lon; 14float lon_NEW; 15 16float alt; 17float alt_NEW; 18 19float head; 20float head_NEW; 21 22float spd; 23float spd_NEW; 24 25int sat; 26int sat_NEW; 27 28long lastConnected; 29 30#define RXD2 16 31#define TXD2 17 32 33#define GPS_BAUD 9600 34 35TinyGPSPlus gps; 36HardwareSerial gpsSerial(2); 37 38 39void setup() 40{ 41 Serial.begin(9600); 42 43 gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2); 44 45 u8g2.begin(); 46 u8g2.firstPage(); 47 48 do 49 { 50 u8g2.setFont(u8g2_font_6x13_tf); 51 u8g2.drawStr(5, 25, "GPS Interface 0.2"); 52 u8g2.drawStr(5, 40, "Connecting . . ."); 53 } while (u8g2.nextPage()); 54 55 56 delay(1500); 57 58 initProperties(); 59 60 // Connect to Arduino IoT Cloud 61 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 62 63 setDebugMessageLevel(2); 64 ArduinoCloud.printDebugInfo(); 65} 66 67void loop() 68{ 69 ArduinoCloud.update(); 70 71 if (gpsSerial.available() > 0) 72 { 73 lastConnected = millis(); 74 75 if (gps.encode(gpsSerial.read())) 76 { 77 if (gps.course.isValid()) 78 { 79 head_NEW = gps.course.deg(); 80 81 if (head_NEW != head) 82 { 83 head = head_NEW; 84 } 85 } 86 87 if (gps.altitude.isValid()) 88 { 89 alt_NEW = gps.altitude.meters(); 90 91 if (alt_NEW != alt) 92 { 93 alt = alt_NEW; 94 } 95 } 96 97 if (gps.satellites.isValid()) 98 { 99 sat_NEW = gps.satellites.value(); 100 101 if (sat_NEW != sat) 102 { 103 sat = sat_NEW; 104 } 105 } 106 107 if (gps.location.isValid()) 108 { 109 lat_NEW = gps.location.lat(); 110 lon_NEW = gps.location.lng(); 111 112 if (lat_NEW != lat || lon_NEW != lon) 113 { 114 if (lat_NEW != lat) 115 { 116 lat = lat_NEW; 117 } 118 119 if (lon_NEW != lon) 120 { 121 lon = lon_NEW; 122 } 123 } 124 } 125 126 if (gps.speed.isValid()) 127 { 128 spd_NEW = gps.speed.mps(); 129 130 if (spd_NEW != spd) 131 { 132 spd = spd_NEW; 133 } 134 } 135 136 printAll(); 137 } 138 } 139 140 if ((millis() - lastConnected) > 2000) 141 { 142 u8g2.firstPage(); 143 144 do 145 { 146 u8g2.setFont(u8g2_font_6x13_tf); 147 u8g2.drawStr(5, 25, "GPS Interface 0.2"); 148 u8g2.drawStr(5, 40, "Reconnecting . . ."); 149 } while (u8g2.nextPage()); 150 } 151} 152 153void printAll() 154{ 155 location = {lat, lon}; 156 157 altitude = alt; 158 159 satellites = sat; 160 161 speed = spd; 162 163 heading = gps.cardinal(head); 164 165 u8g2.firstPage(); 166 167 do 168 { 169 u8g2.setFont(u8g2_font_6x13_tf); 170 171 u8g2.setCursor(3, 10); 172 u8g2.print("Lat: "); 173 174 u8g2.setCursor(3, 25); 175 u8g2.print(lat, 6); 176 177 u8g2.setCursor(3, 40); 178 u8g2.print("Lon: "); 179 180 u8g2.setCursor(3, 55); 181 u8g2.print(lon, 6); 182 183 u8g2.setCursor(70, 10); 184 u8g2.print("# Sats:"); 185 186 u8g2.setCursor(70, 25); 187 u8g2.print(sat); 188 189 u8g2.setCursor(70, 40); 190 u8g2.print("Speed:"); 191 192 u8g2.setCursor(70, 55); 193 u8g2.print(spd, 3); 194 195 } while (u8g2.nextPage()); 196}
Comments
Only logged in users can leave comments