hola estoy tratando de hacer un robot autopilotado, una parte esencial del proyecto es lograr obtener datos de un gps y una brujula el problema que tengo es q puedo obtener datos del gps y la brujula por separado pero cuando intento ejecutar ambas tareas en un mismo codigo o la brujula no funciona o el gps no funciona
lo unico que he descubierto es q el gps no funciona junto a retardos de tiempo, en el codigo de lectura del gps si agrego un delay arduino deja de leer,
le dejo el codigo ojala me puedan ayudar
#include <Wire.h>
#include <nmea.h>
NMEA gps(GPRMC);
int compassAddress = 0x42 >> 1; // From datasheet compass address is 0x42
// shift the address 1 bit right, the Wire library only needs the 7
// most significant bits for the address
int reading = 0;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
pinMode(48, OUTPUT);
digitalWrite(48, HIGH);
}
void loop()
{
if (Serial1.available() > 0 ) {
// read incoming character from GPS
char c = Serial1.read();
// check if the character completes a valid GPS sentence
if (gps.decode(c)) {
// check if GPS positioning was active
if (gps.gprmc_status() == 'A') {
Serial.println(gps.gprmc_latitude());
}
}
}
// step 1: instruct sensor to read echoes
Wire.beginTransmission(compassAddress); // transmit to device
// the address specified in the datasheet is 66 (0x42)
// but i2c adressing uses the high 7 bits so it's 33
Wire.write('A'); // command sensor to measure angle
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delayMicroseconds(6000); // datasheet suggests at least 6000 microseconds
// step 3: request reading from sensor
Wire.requestFrom(compassAddress, 2); // request 2 bytes from slave device #33
// step 4: receive reading from sensor
if(2 <= Wire.available()) // if two bytes were received
{
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading += Wire.read(); // receive low byte as lower 8 bits
reading /= 10;
Serial.println(reading); // print the reading
}
delay(1000)
}