Professional Documents
Culture Documents
Workbook Russian
Workbook Russian
GY-GPS6MV2
1 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
tinyGPSPlus
TinyGPS
Read out
2 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
#include <TinyGPS.h>
TinyGPS gps;
#define debugSerial SerialUSB
void setup()
{
debugSerial.begin(9600);
Serial.begin(9600);
}
void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (Serial.available())
{
char c = Serial.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
debugSerial.print("LAT=");
debugSerial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
debugSerial.print(" LON=");
debugSerial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
debugSerial.print(" SAT=");
debugSerial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
debugSerial.print(" PREC=");
debugSerial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
}
3 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
LoRa
TheThingsNetwork
4 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
lat lon
5 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
#include <TheThingsNetwork.h>
#include <TinyGPS.h>
TinyGPS gps;
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
Serial.begin(9600); // connect Rx to D1 & Tx to D0
debugSerial.println("-- STATUS");
ttn.showStatus();
debugSerial.println("-- JOIN");
ttn.join(appEui, appKey);
void loop()
{
uint16_t temp = getTemperature();
6 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (Serial.available())
{
char c = Serial.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
SerialUSB.print("LAT=");
SerialUSB.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
SerialUSB.print(" LON=");
SerialUSB.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
SerialUSB.print(" SAT=");
SerialUSB.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
SerialUSB.print(" PREC=");
SerialUSB.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
}
SerialUSB.println(lat);
SerialUSB.println(lon);
byte payload[10];
payload[0] = highByte(temp);
payload[1] = lowByte(temp);
7 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
ttn.sendBytes(payload, sizeof(payload));
delay(10000);
}
uint16_t getTemperature()
{
//10mV per C, 0C is 500mV
float mVolts = (float)analogRead(TEMP_SENSOR) * 3300.0 / 1023.0;
int temp = (mVolts - 500) * 10;
else {
digitalWrite(LED_BUILTIN, HIGH);
}
8 of 9 3/31/2019, 6:46 PM
Localization with GPS | Localization using GPS | _ Courseware | LoR... https://course.lorawanacademy.com/courses/course-v1:_+_+V1/coursewa...
return {
temperature: temperature,
lat: lat,
lon: lon,
}
}
Mark as complete
9 of 9 3/31/2019, 6:46 PM