Arduino - problema con acelerometro y gps

 
Vista:

problema con acelerometro y gps

Publicado por MANUEL FERNANDO (1 intervención) el 13/09/2022 16:21:28
hola a todos , tengo un codigo muy basico con un arduino mega que usa el acelerometro mpu 6050 y el gps neo gps, el problema que tengo es que juntos anda y luego de un rato aleatorio se detiene , por separados andan bien ,alguien me podria dar una mano ??

#include <Wire.h>
#define MPU 0x68

int j = 0;
bool k = true;
int updates;
int failedUpdates;
int pos;
int stringplace = 0;
int az = 0;
String timeUp;
String nmea[15];
String labels[12] {"Time: ", "Status: ", "Latitude: ", "Hemisphere: ", "Longitude: ", "Hemisphere: ", "Speed: ", "Track Angle: ", "Date: "};
int acz[100] ;

void setup()
{
Serial.begin(9600);

Wire.begin(); // join i2c bus (address optional for master)
#if defined(WIRE_HAS_TIMEOUT)
Wire.setWireTimeout(3000 /* us */, true /* reset_on_timeout */);
#endif
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0x00);
Wire.endTransmission(true);

}

void loop() {

while(k == false )
{
while (Serial1.available() > 0)
{
Serial1.read();
}

if (Serial1.find("$GPRMC,"))
{
Serial1.flush();
String tempMsg = Serial1.readStringUntil('\n');
Serial1.end();
Wire.begin();
for (int i = 0; i < tempMsg.length(); i++) {
if (tempMsg.substring(i, i + 1) == ",") {
nmea[pos] = tempMsg.substring(stringplace, i);
stringplace = i + 1;
pos++;
}
if (i == tempMsg.length() - 1) {
nmea[pos] = tempMsg.substring(stringplace, i);
}
}

for (int i = 6; i < 8; i++) {
Serial.print(labels[i]);
Serial.print(nmea[i]);
Serial.println("");
}

}
else
{

failedUpdates++;
Serial.println(failedUpdates);
}
stringplace = 0;
pos = 0;
k = true;
}

while( k == true)
{
// if(Serial1.available() == false)
// {
Wire.beginTransmission(0x68);
Wire.write(0x3F); //Pedir el registro 0x3B - corresponde al AcX

byte error = Wire.endTransmission(false); // run transaction

if (error) {
Wire.end();
Wire.begin();
Serial.println(error);
Serial.println("Error occured when writing 1");
if (error == 5)
Serial.println("It was a timeout 1");
}
// delay(65);
/* Then, read the result */
#if defined(WIRE_HAS_TIMEOUT)
Wire.clearWireTimeoutFlag();
#endif
byte len = Wire.requestFrom(0x68, 2, false); // request 1 byte from device #8
if (len == 0) {
Wire.end();
Wire.begin();
Serial.println("Error occured when reading");
#if defined(WIRE_HAS_TIMEOUT)
if (Wire.getWireTimeoutFlag())
Serial.println("It was a timeout");
#endif

}
az = Wire.read();
az = az << 8;
az |= Wire.read();
Wire.endTransmission();
Serial.print("acelerometro : ");Serial.println(az);
// }
// }
j++;
if(j>=100)
{
Wire.end();
Serial1.begin(9600);
j = 0;
k = false;
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder