Bonjour a tous je souhaite utiliser un arduino avec ces module ci dessus j'ai récupérer 2 code (Un pour recupérer l'angle avec le MPU6050 et l'autre pour faire fonctionner le GPS) que j'ai essayer de "fusionner" ce qui me donne ceci :
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<Wire.h>
// Choose two Arduino pins to use for software serial
int RXPin = 7;
int TXPin = 8;
int GPSBaud = 9600;
//Gyro
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int minVal=265;
int maxVal=402;
double x;
double y;
double z;
//Gyro
// Create a TinyGPS++ object
TinyGPSPlus gps;
// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);
void setup()
{
Wire.begin(); //Gyro
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true); //Gyro
// Start the Arduino hardware serial port at 9600 baud
Serial.begin(115200);
// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
}
void loop()
{
//Gyro Debut
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
int xAng = map(AcX,minVal,maxVal,-90,90);
int yAng = map(AcY,minVal,maxVal,-90,90);
int zAng = map(AcZ,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
//Gyro Fin
// This sketch displays information every time a new sentence is correctly encoded.
while (gpsSerial.available() > 0)
if (gps.encode(gpsSerial.read()))
displayInfo();
// If 5000 milliseconds pass and there are no characters coming in
// over the software serial port, show a "No GPS detected" error
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("Le GPS n'est pas détecté");
while(true);
}
}
void displayInfo()
{ //////////////////////////////////////////////////////////////////////////////////////////////////////////
if (gps.location.isValid())
{
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
Serial.print("Altitude: ");
Serial.println(gps.altitude.meters());
}
else
{
Serial.println("Localisation non disponible");
}
Serial.print("Date: ");
if (gps.date.isValid())
{
Serial.print(gps.date.day());
Serial.print("/");
Serial.print(gps.date.month());
Serial.print("/");
Serial.println(gps.date.year());
}
else
{
Serial.println("Non disponible");
}
Serial.print("Time: ");
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print((gps.time.hour())+1);
Serial.print(":");
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(":");
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(".");
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.println(gps.time.centisecond());
}
else
{
Serial.println("Non disponible");
}
// Vitesse Debut
if (gps.speed.isValid())
{
Serial.print("Vitesse en KM/H : ");
Serial.println(gps.speed.kmph());
}
else
{
Serial.print("Données vitesse non disponible");
}
//Vitesse Fin
Serial.println();
Serial.print("AngleX= ");
Serial.println(x);
Serial.println();
delay(1000);
}
Le code se compile bien il n'y a pas d'erreur mais dans le moniteur série les valeurs s'affichent bien mais au bout de quelques secondes l'angle se fige mais pas l'heure ni les coordonnées.
Je ne vois vraiment pas d'où viens le problème.
Merci d'avance pour vos retours.