Sat Aug 27, 2016 5:09 pm
Sat Aug 27, 2016 7:51 pm
Mon Aug 29, 2016 7:50 pm
#include <Gamebuino.h>
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial GPS(A4, A5); //GPS is connected on i2c port
//gps stuff
#define GPSBUFFSIZE 100
char gpsBuff[GPSBUFFSIZE];
//char time[7];
//Variable for MENU
#define MENULENGTH 3
const char strLiveDATA[] PROGMEM = "View GPS DATA";
const char strLogDATA[] PROGMEM = "Start GPS Logger";
const char strEXIT[] PROGMEM = "EXIT";
const char* const menu[MENULENGTH] PROGMEM = {
strLiveDATA,
strLogDATA,
strEXIT,
};
Gamebuino gb;
char folderName[9] = "GPSLOG";
void setup() {
GPS.begin(9600);
delay(500);
gb.begin();
gb.titleScreen(F("GPS Position :)"));
gb.popup(F("Welcome :)"), 100);
gb.battery.show = true;
GPS.print(F("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"));
delay(500);
GPS.print(F("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"));
}
void loop() {
switch(gb.menu(menu, MENULENGTH)) {
case -1: {
gb.titleScreen(F("GPS Position :)"));
break;
}
case 0: {
liveDATA();
break;
}
case 1: {
logDATA();
break;
}
case 2: {
gb.changeGame();
break;
}
default: {
break;
}
}
}
void liveDATA() {
while(1) {
if(gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
return;
}
if (!processGPS(false)) {
gb.display.println(F("Searching..."));
Serial.println(F("NO FIX"));
}
}
}
}
void logDATA() {
gb.keyboard(folderName, 9);
while(1) {
if(gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
return;
}
gb.display.print(F("Folder name: "));
gb.display.println(folderName);
}
}
}
boolean processGPS(boolean toLOG) {
byte i = 0;
memset(gpsBuff, '\0', GPSBUFFSIZE);
while(GPS.available()) GPS.read(); //Empty the buffer before we read and parse!
while(1) {
if (GPS.available() > 0) {
char c = GPS.read();
gpsBuff[i] = c;
//Serial.print(c);
i++;
if (c == '\n') {
gpsBuff[i] = 0;
break;
}
if (i == GPSBUFFSIZE -1) {
gpsBuff[i] = 0;
break;
}
}
}
if (gpsBuff[18] != 'A') {
return false;
} else if (gpsBuff[18] == 'A') { //We have a FIX!
char time[7];
float flat, flong;
//$GPRMC,190411.000,A,4815.0434,N,01417.4215,E,2.99,100.48,271015,,,A*67\r\n
strtok_P(gpsBuff, PSTR (","));
strcpy(time, strtok_P(NULL, PSTR (".")));
strtok_P(NULL, PSTR (","));
strtok_P(NULL, PSTR (","));
flat = atof(strtok_P(NULL, PSTR (",")));
flat = conv_coords(flat);
if (strtok_P(NULL, PSTR (",")) != "N") {
flat = flat * -1;
}
flong = atof(strtok_P(NULL, PSTR (",")));
flong = conv_coords(flong);
if (strtok_P(NULL, PSTR (",")) != "E") {
flat = flat * -1;
}
gb.display.print(F("UTC time: "));
gb.display.print(time[0]);
gb.display.print(time[1]);
gb.display.print(F(":"));
gb.display.print(time[2]);
gb.display.print(time[3]);
gb.display.print(F(":"));
gb.display.print(time[4]);
gb.display.println(time[5]);
gb.display.print(F("LAT: ")); gb.display.println(flat, 6);
gb.display.print(F("LON: ")); gb.display.println(flong, 6);
return true;
}
return false;
}
float conv_coords(float in_coords) {
//Initialize the location.
float f = in_coords;
// Get the first two digits by turning f into an integer, then doing an integer divide by 100;
// first two digits should be 77 at this point.
int firsttwodigits = ((int)f)/100; //This assumes that f < 10000.
float nexttwodigits = f - (float)(firsttwodigits*100);
float theFinalAnswer = (float)(firsttwodigits + nexttwodigits/60.0);
return theFinalAnswer;
}
Tue Aug 30, 2016 8:27 pm
if (file.writeLn(gpsBuff)) {
count++;
} else {
errCount++;
}
Tue Aug 30, 2016 9:17 pm
if (file.writeLn(gpsBuff) == NO_ERROR) {
count++;
} else {
errCount++;
}
file.writeLn("I will log battery voltage every 10 minutes");
Wed Aug 31, 2016 8:14 pm
Sat Sep 03, 2016 7:17 pm
#include <Gamebuino.h>
#include <SPI.h>
#include <SoftwareSerial.h>
//#include <tinyFAT.h> //requires the tinyFAT library. You can download it here : http://www.henningkarlsen.com/electronics/library.php?id=37
#include <SdFat.h>
#define SD_CS_PIN SS
SoftwareSerial GPS(A4, A5); //GPS is connected on i2c port
extern const byte font3x3[]; //a really tiny font
extern const byte font3x5[]; //a small but efficient font (default)
extern const byte font5x7[]; //a large, comfy font
//gps stuff
#define GPSBUFFSIZE 90
char gpsBuff[GPSBUFFSIZE];
//char time[7];
//Variable for MAIN MENU
#define MENULENGTH 3
const char strLiveDATA[] PROGMEM = "View GPS DATA";
const char strLogDATA[] PROGMEM = "Start GPS Logger";
const char strEXIT[] PROGMEM = "EXIT";
const char* const menu[MENULENGTH] PROGMEM = {
strLiveDATA,
strLogDATA,
strEXIT,
};
//Variable for MAIN MENU
#define INTERVALMENULENGTH 3
const char str5[] PROGMEM = "5s";
const char str10[] PROGMEM = "10s";
const char str20[] PROGMEM = "20S";
const char* const intervalMenu[MENULENGTH] PROGMEM = {
str5,
str10,
str20,
};
Gamebuino gb;
SdFat SD;
File myFile;
char fileNAME[15] = "GPSLOG";
boolean light = false;
long timer = 0;
void setup() {
GPS.begin(9600);
delay(500);
gb.begin();
gb.backlight.automatic = false;
gb.backlight.set(0);
//gb.display.setFont(font5x7);
gb.display.setFont(font3x5);
gb.display.fontSize = 2;
gb.titleScreen(F("GPS Position :)"));
//gb.popup(F("Welcome :)"), 100);
gb.battery.show = true;
GPS.print(F("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"));
delay(500);
GPS.print(F("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"));
//gb.setFrameRate(1);
}
void loop() {
switch(gb.menu(menu, MENULENGTH)) {
case -1: {
gb.titleScreen(F("GPS Position :)"));
break;
}
case 0: {
liveDATA();
break;
}
case 1: {
logDATA();
break;
}
case 2: {
gb.changeGame();
break;
}
default: {
break;
}
}
}
void liveDATA() {
while(1) {
if(gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
return;
}
if (gb.buttons.pressed(BTN_DOWN)) {
light = !light;
}
if (light) {
gb.backlight.set(200);
} else {
gb.backlight.set(0);
}
if (!processGPS(false)) {
gb.display.println(F("Searching..."));
}
}
}
}
void logDATA() {
boolean light = false;
int count = 0;
byte errCount = 0;
if (!SD.begin(SD_CS_PIN)) {
gb.display.clear();
gb.display.update();
gb.display.println(F("NO SD!"));
gb.display.update();
while(1);
}
delay(500);
gb.keyboard(fileNAME, 8);
char fname[15];
sprintf_P(fname, PSTR ("%s.TXT"), fileNAME);
int interval = 0;
//while(1) {
switch(gb.menu(intervalMenu, INTERVALMENULENGTH)) {
case -1: {
interval = 100;
break;
}
case 0: {
interval = 100;
break;
}
case 1: {
interval = 200;
break;
}
case 2: {
interval = 400;
break;
}
default: {
interval = 100;
break;
}
}
//}
myFile = SD.open(fname, FILE_WRITE);
if (!myFile) {
gb.display.clear();
gb.display.update();
gb.display.println(F("File ERROR!"));
gb.display.println(fname);
gb.display.update();
while(1);
}
while(1) {
if(gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
myFile.close();
return;
}
if (gb.buttons.pressed(BTN_DOWN)) {
light = !light;
}
if (light) {
gb.backlight.set(200);
} else {
gb.backlight.set(0);
}
if (gb.frameCount - timer >= interval) {
if (processGPS(true)) {
if (myFile.print(gpsBuff)) {
count++;
} else {
errCount++;
}
} else {
gb.display.println(F("Searching..."));
}
timer = gb.frameCount;
}
gb.display.print(F("Stored: ")); gb.display.println(count);
gb.display.print(F("failed: ")); gb.display.println(errCount);
//gb.display.println(gb.frameCount);
gb.display.cursorX = 0;
gb.display.cursorY = 42;
gb.display.print(F("Voltage: ")); gb.display.println(gb.battery.voltage);// gb.display.println(F(" mV"));
}
}
}
boolean processGPS(boolean toLOG) {
byte i = 0;
memset(gpsBuff, '\0', GPSBUFFSIZE);
while(GPS.available()) GPS.read(); //Empty the buffer before we read and parse!
while(1) {
if (GPS.available() > 0) {
char c = GPS.read();
gpsBuff[i] = c;
//Serial.print(c);
i++;
if (c == '\n') {
gpsBuff[i] = 0;
break;
}
if (i == GPSBUFFSIZE -1) {
gpsBuff[i] = 0;
break;
}
}
}
if (gpsBuff[18] != 'A') {
return false;
} else if (gpsBuff[18] == 'A') { //We have a FIX!
if (toLOG) {
return true;
} else {
char time[7];
float flat, flong, fspeed;
//$GPRMC,190411.000,A,4815.0434,N,01417.4215,E,2.99,100.48,271015,,,A*67\r\n
strtok_P(gpsBuff, PSTR (","));
strcpy(time, strtok_P(NULL, PSTR (".")));
strtok_P(NULL, PSTR (","));
strtok_P(NULL, PSTR (","));
flat = atof(strtok_P(NULL, PSTR (",")));
flat = conv_coords(flat);
if (strtok_P(NULL, PSTR (",")) != "N") {
flat = flat * -1;
}
flong = atof(strtok_P(NULL, PSTR (",")));
flong = conv_coords(flong);
if (strtok_P(NULL, PSTR (",")) != "E") {
flat = flat * -1;
}
fspeed = atof(strtok_P(NULL, PSTR (",")));
fspeed = fspeed * 1.852;
gb.display.print(F("UTC time: "));
gb.display.print(time[0]);
gb.display.print(time[1]);
gb.display.print(F(":"));
gb.display.print(time[2]);
gb.display.print(time[3]);
gb.display.print(F(":"));
gb.display.print(time[4]);
gb.display.println(time[5]);
gb.display.print(F("LAT: ")); gb.display.println(flat, 6);
gb.display.print(F("LON: ")); gb.display.println(flong, 6);
gb.display.print(F("Speed: ")); gb.display.print(fspeed); gb.display.println(F("Km/h"));
//gb.display.println(gb.getCpuLoad());
gb.display.cursorX = 0;
gb.display.cursorY = 42;
gb.display.print(F("Voltage: ")); gb.display.println(gb.battery.voltage);// gb.display.println(F(" mV"));
return true;
}
}
return false;
}
float conv_coords(float in_coords) {
//Initialize the location.
float f = in_coords;
// Get the first two digits by turning f into an integer, then doing an integer divide by 100;
// first two digits should be 77 at this point.
int firsttwodigits = ((int)f)/100; //This assumes that f < 10000.
float nexttwodigits = f - (float)(firsttwodigits*100);
float theFinalAnswer = (float)(firsttwodigits + nexttwodigits/60.0);
return theFinalAnswer;
}