In this page you will find the description of how to implement a GPS sensor with arduino and how to integrate both components in the multidimensional box.
If you need additional specific information about this topic or if you want to look it personally please write an email
// GPS pin connection
#define rxGPS 3
#define txGPS 5
SoftwareSerial serialGPS = SoftwareSerial(rxGPS, txGPS);
String stringGPS = "";
void setup() {
pinMode(rxGPS, INPUT);
pinMode(txGPS, OUTPUT);
Serial.begin(9600);
// GPS Setup
serialGPS.begin(4800);
digitalWrite(txGPS,HIGH); //init the device
// Cut first gibberish
while(serialGPS.available())
if (serialGPS.read() == '\r')
break;
}
void loop()
{
String s = checkGPS();
if(s && s.substring(0, 6) == "$GPGGA") //search for a valid NMEA string
{
Serial.println(s);
}
}
// Check GPS and returns string if full line recorded, else false
String checkGPS()
{
if (serialGPS.available())
{
char c = serialGPS.read();
if (c != '\n' && c != '\r')
{
stringGPS = c;
}
else
{
if (stringGPS != "")
{
String tmp = stringGPS;
stringGPS = "";
return tmp;
}
}
}
return false;
}
This is a very basic code and the NMEA string is found in a very basic way but is very useful for you in order to understand how it works.
#include "TinyGPS.h"
//create the GPS object
TinyGPS gps;
Now continuosly read data from the serial port connected to the GPS module and pass those bytes to the GPS object
if (Serial1.available()) {
char c = Serial1.read();
Serial.print(c); // uncomment to see raw GPS data
if (gps.encode(c)) {
newdata = true;
}
}
if (newdata == true){ ....
If the block received is valid you need to estabilish if it is a block with a valid fix (GPS signal) or not.
// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
if (fix_age == TinyGPS::GPS_INVALID_AGE){
SignalPresence = false;
Serial.println("Data in but no fix detected");
}
else if (fix_age > 5000){
SignalPresence = false;
Serial.println("Warning: possible old data. Wait for new data!");
}
else {
Serial.println("Data is current."); ...
Once data is correct you can play with the TinyGPS functions and have fun.
// time in hhmmsscc, date in ddmmyy
gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age);
// returns speed in 100ths of a knot
speed = gps.f_speed_kmph();
// course in 100ths of a degree
course = gps.course();
alt = gps.f_altitude();
//Delete the old string from the display
DrawStatus(DISPLAY_GPS, stringGPS, BLACK);
//write the new string
Serial.print(F("Write string"));
Serial.println(stringGPS);
#include
#include
#include
#include
//pin connected
#define OLED_MOSI 11
#define OLED_CLK 12
#define OLED_DC 9
#define OLED_CS 8
#define OLED_RESET 10
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
//Check if the display is the right one
#if (SSD1306_LCDHEIGHT != 64)
#error("wrong display used");
#endif
void setup() {
Serial.begin(9600);
// 3.3V volt
display.begin(SSD1306_SWITCHCAPVCC);
// delete the screen
display.clearDisplay();
// set WHITE as default
display.setTextColor(WHITE);
// set dimension
display.setTextSize(1);
// set the cursor
display.setCursor(32,32);
// print a message
display.print("Salve mondo");
// display the string
display.display();
}
As you can see in this easy example you can print text in any oled display with simple instructions thanks to the Adafruit Library. The same library can be used also to print graphic.
display.drawCircle(display.width() - 6, 5, 5, WHITE);
display.drawCircle(display.width() - 6, 5, 4, BLACK);
display.drawCircle(display.width() - 6, 5, 3, WHITE);
display.drawCircle(display.width() - 6, 5, 2, WHITE);
display.drawCircle(display.width() - 6, 5, 1, WHITE);
Using all these functions, I built a set of functions able to write GPS positions, Accellerometer values and the sonic distance measured using a sensor.