J'ai une sorte de latence de l'affichage lorsque je suis à 70 km/h, la distance parcourue ne se rafraichit que tout les 20-30 mètres et le reste de l'affichage un fois par seconde, je ne pense pas que cela soi lié aux sentences GPS qui arrivent toutes les secondes (mais à tout hasard

)
Ce qui me chagrine, c'est que j'ai eu un moment à 70 km/h un rafraichissement tous les mètres et que je n'ai rien rajouté comme mesure, j'ai même supprimé des calculs depuis.... et c'est devenu plus lent, mais je n'arrive pas à trouver la raison de ce ralentissement.
Par contre les enregistrements sur la SD sont toujours corrects, à chaque top rayon correspond une ligne.
Voici le code actuellement :
#include <SdFat.h>
#include <TinyGPS.h>
#include <LiquidCrystal.h> // Inclusion de la librairie pour afficheur LCD
SdFat sd;
SdFile myFile;
// Change the value of chipSelect if your hardware does
// not use the default value, SS_PIN. Common values are:
// Arduino Ethernet shield: pin 4
// Sparkfun SD shield: pin 8
// Adafruit SD shields and modules: pin 10
// Mega 53
const uint8_t chipSelect = SS_PIN;
const int RS=2; //declaration constante de broche
const int E=3; //declaration constante de broche
const int D4=4; //declaration constante de broche
const int D5=5; //declaration constante de broche
const int D6=6; //declaration constante de broche
const int D7=7; //declaration constante de broche
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);// Création d'un objet LiquidCrystal = initialisation LCD en mode 4 bits
const int SizeTop = 260;
const int inX= 1 ;
const int inY= 0 ;
const int inZ= 2 ;
float Speed = 0;
float FilteredSpeed = 0;
float filterVal = 0.9;
float odo=0;
float dist = 0;
float odoDist=0;
float SpeedVal [SizeTop]; // 625
float distance[SizeTop];
unsigned long TimeOldSpeed;
unsigned long timeold = 0;
unsigned long TimeOldDistance = 0;
unsigned long oldMillis=0;
unsigned long timeTop [SizeTop]; // 625
int rpmcount = 0;
int interTop = 0;
int top = 0;
int AxeX [SizeTop]; // 625
int AxeY [SizeTop]; // 625
int AxeZ [SizeTop]; // 625
boolean point = true;
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
bool newdata;
void setup()
{
//Serial.begin(115200);
Serial3.begin(9600);
// initialize pins on the board
// pinMode(groundpin, OUTPUT);
// pinMode(powerpin, OUTPUT);
// digitalWrite(groundpin, LOW);
// digitalWrite(powerpin, HIGH);
// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// change to SPI_FULL_SPEED for more performance.
//if (!sd.init(SPI_HALF_SPEED, chipSelect)) sd.initErrorHalt();
if (!sd.init(SPI_FULL_SPEED, chipSelect)) sd.initErrorHalt();
lcd.begin(20,2); // Initialise le LCD avec 20 colonnes x 4 lignes
lcd.setCursor(0, 0) ;
delay(10);
lcd.print("LCD OK") ;
delay(2000);
lcd.setCursor(0, 0) ;
lcd.print(" ") ;
lcd.setCursor(0, 1) ;
lcd.print(" ") ;
lcd.setCursor(0, 0) ;
lcd.print("No Sat") ;
Serial.print("Testing TinyGPS library v. ");
Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
Serial.print("Sizeof(gpsobject) = ");
Serial.println(sizeof(TinyGPS));
Serial.println();
dist = 201.8/36 ;
// re-open the file for reading:
if (!myFile.open("distance.txt", O_READ)) {
sd.errorHalt("opening distance.txt for read failed");
}
Serial.println("distance.txt:");
int data;
String thisString="";
// read from the file until there's nothing else in it:
while ((data = myFile.read()) > 0){
thisString+=char(data);
Serial.write(data);
}
char carray[thisString.length() + 1]; //determine size of the array
thisString.toCharArray(carray, sizeof(carray)); //put readStringinto an array
odo = (atof(carray)); //convert the array into a float /1000000
Serial.println (odo,3);
// close the file:
myFile.close();
distance[0]=0;
attachInterrupt(4, rpm_fun, FALLING);
}
void loop()
{
//if (millis() - timeold > 700 && FilteredSpeed > 0){ FilteredSpeed=0; }
odoDist=odo+distance[top]/100000;
if (millis() - timeold > 500 && Speed > 0){
Speed=0.00;
}
if (rpmcount >= 6) {
Speed = 0.002018/36/(millis() - timeold)*rpmcount*1000*3600;
/*
if (Speed > FilteredSpeed + 10 || Speed < FilteredSpeed - 10 )
{
Speed=FilteredSpeed;
}
FilteredSpeed=lpfilter(Speed*.9+(FilteredSpeed*.1), filterVal , FilteredSpeed);
*/
timeold = millis();
rpmcount = 0;
}
if (millis()-TimeOldSpeed >100) // && newdata == false)
{
if (Speed < 10){
lcd.setCursor(13, 0) ;
lcd.print(" ") ;
}
lcd.setCursor(10, 0) ;
//lcd.print(gps.f_speed_kmph()) ;
lcd.print(Speed,2) ; //lcd.print(FilteredSpeed) ;
lcd.setCursor(9, 1) ;
lcd.print(odoDist,3) ; // affiche la distance totale parcourue
TimeOldSpeed=millis();
}
if (millis()-TimeOldDistance >500){
if (!myFile.open("distance.txt", O_RDWR | O_CREAT)) {
sd.errorHalt("opening distance.txt for write failed");
}
myFile.println (float(odoDist),5);
// close the file:
myFile.close();
TimeOldDistance = millis();
}
newdata = false;
unsigned long start = millis();
// Every 0.1 seconds we print an update
while (millis() - start < 100)
{
if (feedgps())
newdata = true;
}
if (newdata)
{
gpsdump(gps); // GPS ok
}
}
void gpsdump(TinyGPS &gps)
{
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;
feedgps();
gps.get_position(&lat, &lon, &age);
gps.f_get_position(&flat, &flon, &age);
gps.get_datetime(&date, &time, &age);
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
/*
if (Speed < 10){
lcd.setCursor(13, 0) ;
lcd.print(" ") ;
}
*/
lcd.setCursor(0, 0) ;
lcd.print(" ") ;
lcd.setCursor(0, 1) ;
lcd.print(" ") ;
lcd.setCursor(0, 0) ;
lcd.print(flat,5) ;
lcd.setCursor(0, 1) ;
lcd.print(flon,5) ;
lcd.setCursor(10, 0) ;
//lcd.print(second,DEC) ; // affiche les secondes
//lcd.setCursor(13, 0) ;
//lcd.print(int(gps.f_course())) ; // altitude GPS
lcd.print(Speed,2) ; // lcd.print(FilteredSpeed) ;
lcd.setCursor(15, 0) ;
if (point ==true){
lcd.print("+");
}
else{
lcd.print("*");
}
point = !point;
// lcd.setCursor(14, 1) ;
//lcd.print(" ") ;
lcd.setCursor(9, 1) ;
//lcd.print(gps.f_speed_kmph()) ;
lcd.print(odoDist,3) ; // affiche la distance totale parcourue
// ici inscription des valeurs distances sur la SDcard
if (!myFile.open("data.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening data.txt for write failed");
}
// if the file opened okay, write to it:
// Serial.print("Writing to test.txt...");
for (int i=0;i<=top-1;i++)
{
myFile.print (timeTop [i]);
myFile.print(",");
myFile.print (distance[i]/100);
myFile.print(",");
myFile.print (SpeedVal [i]);
myFile.print(",");
myFile.print(AxeX[i]);
myFile.print(",");
myFile.print(AxeY[i]);
myFile.print(",");
myFile.println (AxeZ[i]);
}
myFile.print(year);
myFile.print("/");
myFile.print(static_cast<int>(month));
myFile.print("/");
myFile.print(static_cast<int>(day));
myFile.print(",");
myFile.print(static_cast<int>(hour));
myFile.print(":");
myFile.print(static_cast<int>(minute));
myFile.print(":");
myFile.print(static_cast<int>(second));
myFile.print(".");
myFile.print(static_cast<int>(hundredths));
myFile.print(",");
myFile.print(flat,5);
myFile.print(",");
myFile.print(flon,5);
myFile.print(",");
myFile.print(int(gps.f_course()));
myFile.print(",");
myFile.println(Speed); //myFile.println(FilteredSpeed);
// close the file:
myFile.close();
// Serial.println("done.");
oldMillis=millis();
top=0;
}
bool feedgps()
{
while (Serial3.available())
{
if (gps.encode(Serial3.read()))
return true;
}
return false;
}
void rpm_fun()
{
rpmcount++;
Top();
top++;
interTop++;
if( top >= SizeTop){
top=SizeTop-1;
}
}
float lpfilter(float data, float filterVal, float filteredVal){
if (filterVal > 1){
filterVal = .99;
}
else if (filterVal <= 0){
filterVal = 0;
}
filteredVal = (data * (1 - filterVal)) + (filteredVal * filterVal);
return filteredVal;
}
void Top(){
SpeedVal[top]=Speed; // SpeedVal[top]=FilteredSpeed;
timeTop[top]=millis()-oldMillis;
distance[top]=dist*interTop;
AxeX[top] = analogRead(inX);
AxeY[top] = analogRead(inY);
AxeZ[top] = analogRead(inZ);
}