This gadget will record GPS and IMU data at 50 Hz onto an SD card for further processing on a PC.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
The device was gently shaken up and down and, in theory, there should be a sine shaped plot on the Y axis, but it's obviously corrupted:
The logger was put on the dashboard of my van in an attempt to detect pot holes.
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver
#include"LIS3DHTR.h"
#include "RTC_SAMD51.h"
#include "DateTime.h"
#include <SPI.h>
#include <SD.h>
#include <FlashStorage_SAMD.h>
#define FLASH_DEBUG 0
#define TFT_GREY 0x5AEB
#define YELLOW 0xFFE0
#define RED 0xF800
FlashStorage(my_flash_store, int);
TFT_eSPI tft = TFT_eSPI(); // Invoke library
LIS3DHTR<TwoWire> lis;
RTC_SAMD51 rtc;
int captureTime;
int SDWriteTime;
unsigned long avSDWriteTime =0;
int SDwriteCycleTime;
unsigned long start1;
unsigned long finish1;
unsigned long start2;
unsigned long finish2;
unsigned long currentMicros1;
unsigned long previousMicros1 =0;
unsigned long count2 = 0;
// string to buffer output
String buffer;
String filename;
unsigned long lastMillis = 0;
int stateOne = 0;
float flat = 0.00000000;
float flon = 0.00000000;
float GPSspeed = 0.0;
int GPSsatelites = 0;
int GPSprecision = 0;
int flashNumber;
uint16_t address = 0;
// File object to represent file
File txtFile;
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
9600-baud serial GPS device hooked up on pins D0(rx) and D1(tx) - the
SIM28 Seed studio grove GPS module.
*/
TinyGPS gps;
SoftwareSerial ss(0, 1);
void setup()
{
// Read the content of emulated-EEPROM
EEPROM.get(address, flashNumber);
// Save into emulated-EEPROM the number increased by 1 for the next run of the sketch
EEPROM.put(address, (int) (flashNumber + 1));
if (!EEPROM.getCommitASAP())
{
// Serial.println("CommitASAP not set. Need commit()");
EEPROM.commit();
}
tft.init();
tft.setRotation(2);
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 2);
tft.setTextColor(YELLOW, TFT_BLACK); tft.setTextSize(2);
tft.println(" GPS + G-Force ");
tft.println(" Data Logger ");
tft.println(" V.1.01 ");
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(2);
Serial.begin(115200);
// while(!Serial){1;};
// tft.println("Serial started ...");
delay(5000);
ss.begin(9600);
lis.begin(Wire1);
rtc.begin();
DateTime now = DateTime(F(__DATE__), F(__TIME__));
Serial.println("adjust time!");
rtc.adjust(now);
// yyyy/MM/dd HH:mm:ss
// SD file name is restricted to 8 characters !!
// filename += now.year(); filename += "";
// filename += now.month(); filename += "";
filename += now.day(); filename += "";
filename += now.hour(); filename += "_";
// Use a flash stored variable to ensure unique filename:
filename += String(flashNumber);
filename += ".txt";
if (!lis)
{
Serial.println("ERROR");
while(1);
}
lis.setOutputDataRate(LIS3DHTR_DATARATE_50HZ); //Data output rate
lis.setFullScaleRange(LIS3DHTR_RANGE_2G); //Scale range set to 2g
// reserve 1kB for String used as a buffer
buffer.reserve(2048);
// set LED pin to output, used to blink when writing
pinMode(LED_BUILTIN, OUTPUT);
// init the SD card
if (!SD.begin())
{
tft.setTextColor(RED, TFT_BLACK); tft.setTextSize(2);
tft.println(" No SD card? ");
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
// If you want to start from an empty file,
// uncomment the next line:
// SD.remove(filename);
// try to open the file for writing
txtFile = SD.open(filename, FILE_WRITE);
if (!txtFile)
{
Serial.print("error opening ");
Serial.println(filename);
while (1);
}
txtFile.write("Millis,Timestamp,Accel_X,Accel_Y,Accel_Z,Satelites,Speed(km/h),Latitude,Longitude,GPSprecision \r\n");
Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
}
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 currentMillis = millis(); millis() - currentMillis < 1000;)
{
while (ss.available())
{
start1 = micros();
char c = ss.read();
Serial.write(c);...
Read more »
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver
#include"LIS3DHTR.h"
#include "RTC_SAMD51.h"
#include "DateTime.h"
#include <SPI.h>
#include <SD.h>
#define TFT_GREY 0x5AEB
#define YELLOW 0xFFE0
#define RED 0xF800
TFT_eSPI tft = TFT_eSPI(); // Invoke library
LIS3DHTR<TwoWire> lis;
RTC_SAMD51 rtc;
int captureTime;
unsigned long start;
unsigned long finish;
// string to buffer output
String buffer;
String filename;
unsigned long lastMillis = 0;
int stateOne = 0;
float flat = 0.00000000;
float flon = 0.00000000;
float GPSspeed = 0.0;
int GPSsatelites = 0;
int GPSprecision = 0;
// File object to represent file
File txtFile;
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
9600-baud serial GPS device hooked up on pins D0(rx) and D1(tx).
*/
TinyGPS gps;
SoftwareSerial ss(0, 1);
void setup()
{
tft.init();
tft.setRotation(2);
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 2);
tft.setTextColor(YELLOW, TFT_BLACK); tft.setTextSize(2);
tft.println(" GPS + G-Force ");
tft.println(" Data Logger ");
tft.println(" V.1.01 ");
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(2);
Serial.begin(115200);
// while(!Serial){1;};
// tft.println("Serial started ...");
delay(5000);
ss.begin(9600);
lis.begin(Wire1);
rtc.begin();
DateTime now = DateTime(F(__DATE__), F(__TIME__));
Serial.println("adjust time!");
rtc.adjust(now);
// yyyy/MM/dd HH:mm:ss
// SD file name is restricted to 8 characters !!
// filename += now.year(); filename += "";
// filename += now.month(); filename += "";
filename += now.day(); filename += "";
filename += now.hour(); filename += "";
filename += now.minute(); filename += "";
filename += now.second();
filename += ".txt";
if (!lis)
{
Serial.println("ERROR");
while(1);
}
lis.setOutputDataRate(LIS3DHTR_DATARATE_50HZ); //Data output rate
lis.setFullScaleRange(LIS3DHTR_RANGE_2G); //Scale range set to 2g
// reserve 1kB for String used as a buffer
buffer.reserve(2048);
// set LED pin to output, used to blink when writing
pinMode(LED_BUILTIN, OUTPUT);
// init the SD card
if (!SD.begin())
{
tft.setTextColor(RED, TFT_BLACK); tft.setTextSize(2);
tft.println(" No SD card? ");
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
// If you want to start from an empty file,
// uncomment the next line:
// SD.remove(filename);
// try to open the file for writing
txtFile = SD.open(filename, FILE_WRITE);
if (!txtFile)
{
Serial.print("error opening ");
Serial.println(filename);
while (1);
}
txtFile.write("Millis,Timestamp,Accel_X,Accel_Y,Accel_Z,Satelites,Speed(km/h),Latitude,Longitude,GPSprecision \r\n");
Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
}
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 currentMillis = millis(); millis() - currentMillis < 1000;)
{
while (ss.available())
{
start = micros();
char c = ss.read();
Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
finish = micros();
}
captureTime = finish - start;
float x_values, y_values, z_values;
x_values = lis.getAccelerationX();
y_values = lis.getAccelerationY();
z_values = lis.getAccelerationZ();
//////////////////////////////////////////////////////////////////
// check if it's been over 20 ms since the last line added
unsigned long currentMillisTwo = millis();
if ((currentMillisTwo - lastMillis) >= 20)
{
DateTime now = rtc.now();
// Serial.println("Write to the buffer !!");
// add a new line to the buffer
buffer += currentMillisTwo; buffer += ",";
// yyyy/MM/dd...
Read more »
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates