The logger was put on the dashboard of my van in an attempt to detect pot holes.
GPS logging was pretty good and after messing about with some basic sample length = 60 filters, I got some coherent results for the IMU. Potholes should have been seen on the Y axis in the last two 'hillocks' of speed, but nothing was seen !! Maybe a better IMU is required with less noise and more G-Force capability?
The image below is a screenshot of a portion of the IMU data captured at 100 Hz. A and B show areas where there seems to be data loss when the system writes to the SD card. The bottom axis is milli-seconds and data seems to be being written once every second or so, with about a 200 milli-second loss each time. There will be some kind of compromise between data output frequency and the amount of data outputted and some optimisation will probably be made by 1. Upgrading the SD card and 2. Doing some onboard averaging to reduce the amount of data getting written to SD.
#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;
unsignedlong avSDWriteTime =0;
int SDwriteCycleTime;
unsignedlong start1;
unsignedlong finish1;
unsignedlong start2;
unsignedlong finish2;
unsignedlong currentMicros1;
unsignedlong previousMicros1 =0;
unsignedlong count2 = 0;
// string to buffer output
String buffer;
String filename;
unsignedlong 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);
voidsetup(){
// 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 cardif (!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();
}
voidloop(){
bool newData = false;
unsignedlong chars;
unsignedshort sentences, failed;
// For one second we parse GPS data and report some key valuesfor (unsignedlong currentMillis = millis(); millis() - currentMillis < 1000;)
{
while (ss.available())
{
start1 = micros();
char c = ss.read();
Serial.write(c);...
#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;
unsignedlong start;
unsignedlong finish;
// string to buffer output
String buffer;
String filename;
unsignedlong 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);
voidsetup(){
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 cardif (!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();
}
voidloop(){
bool newData = false;
unsignedlong chars;
unsignedshort sentences, failed;
// For one second we parse GPS data and report some key valuesfor (unsignedlong 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 flowingif (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 addedunsignedlong 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...