2017-10-23 29 views
0

mpu6050 및 adafruit 궁극적 인 gps 브레이크 아웃 v3에 대한 코드가 있으며 arduino 때문에 잘 작동하지만 두 코드를 결합하려고하면 gps가 제대로 작동하지 않습니다. 고치다. 아무도 나를 도울 수 있습니까? 은 mpu6050에 대한 코드는Mpu6050 및 Adafruit Ultimate Gps가 Arduino Due와 함께 작동하지 않음

// MPU-6050 Short Example Sketch 
    // By Arduino User JohnChi 
    // August 17, 2014 
    // Public Domain 
#include<Wire.h> 
extern TwoWire Wire1; 
const int MPU_addr=0x68; // I2C address of the MPU-6050 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; 
int minVal=265; 
int maxVal=402; 
double x; 
double y; 
double z; 
double pitch,roll,delta_X,delta_Y,delta_Z; 
double old_AcX=0; 
double old_AcY=0; 
double old_AcZ=0; 
int led = 13; 

void setup(){ 
    Wire1.begin(); 
    Wire1.beginTransmission(MPU_addr); 
    Wire1.write(0x6B); // PWR_MGMT_1 register 
    Wire1.write(0);  // set to zero (wakes up the MPU-6050) 
    Wire1.endTransmission(true); 
    Serial.begin(9600); 
    pinMode(led, OUTPUT); 
} 
void loop(){ 
    Wire1.beginTransmission(MPU_addr); 
    Wire1.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) 
    Wire1.endTransmission(false); 
    Wire1.requestFrom(MPU_addr,14,true); // request a total of 14  registers 
    AcX=Wire1.read()<<8|Wire1.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)  
    AcY=Wire1.read()<<8|Wire1.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) 
    AcZ=Wire1.read()<<8|Wire1.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) 
    Tmp=Wire1.read()<<8|Wire1.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L) 
    GyX=Wire1.read()<<8|Wire1.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L) 
    GyY=Wire1.read()<<8|Wire1.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L) 
    GyZ=Wire1.read()<<8|Wire1.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L) 
    Serial.print("AcX = "); Serial.print(AcX); 
    Serial.print(" | AcY = "); Serial.print(AcY); 
    Serial.print(" | AcZ = "); Serial.print(AcZ); 
    Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet 
    Serial.print(" | GyX = "); Serial.print(GyX); 
    Serial.print(" | GyY = "); Serial.print(GyY); 
    Serial.print(" | GyZ = "); Serial.println(GyZ); 



    delay(1000); 
} 

아래에 주어진 그리고 그리고 Adafruit 궁극적 인 GPS를 브레이크 아웃의 코드는 separetely 잘 작동하는

#include <Adafruit_GPS.h> 
#define mySerial Serial1 
Adafruit_GPS GPS(&mySerial); 
#define GPSECHO true 
    boolean usingInterrupt = false; 
    void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy 


    void setup() 
    { 


     Serial.begin(9600); 
     GPS.begin(9600); 
     mySerial.begin(9600); 
     GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); 
     GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); 
     GPS.sendCommand(PGCMD_ANTENNA); 
    #ifdef __arm__ 
    usingInterrupt = false; 
#else 
    useInterrupt(true); 
    #endif 

    delay(1000); 

} 

#ifdef __AVR__ 
SIGNAL(TIMER0_COMPA_vect) { 
    char c = GPS.read(); 
#ifdef UDR0 
    if (GPSECHO) 
    if (c) UDR0 = c; 
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
#endif 
} 

void useInterrupt(boolean v) { 
    if (v) { 

    OCR0A = 0xAF; 
    TIMSK0 |= _BV(OCIE0A); 
    usingInterrupt = true; 
    } else { 
    // do not call the interrupt function COMPA anymore 
    TIMSK0 &= ~_BV(OCIE0A); 
    usingInterrupt = false; 
    } 
} 
#endif //#ifdef__AVR__ 

uint32_t timer = millis(); 
void loop()      
{ 

    if (! usingInterrupt) { 
    char c = GPS.read(); 
    } 

    // if a sentence is received, we can check the checksum, parse it... 
    if (GPS.newNMEAreceived()) { 
    // a tricky thing here is if we print the NMEA sentence, or data 
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data 
    //Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false 

    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false 
     return; // we can fail to parse a sentence in which case we should just wait for another 
    } 

    // if millis() or timer wraps around, we'll just reset it 
    if (timer > millis()) timer = millis(); 

    // approximately every 2 seconds or so, print out the current stats 
    if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer 

    Serial.print("\nTime: "); 
    Serial.print(GPS.hour, DEC); Serial.print(':'); 
    Serial.print(GPS.minute, DEC); Serial.print(':'); 
    Serial.print(GPS.seconds, DEC); Serial.print('.'); 
    Serial.println(GPS.milliseconds); 
    Serial.print("Date: "); 
    Serial.print(GPS.day, DEC); Serial.print('/'); 
    Serial.print(GPS.month, DEC); Serial.print("/20"); 
    Serial.println(GPS.year, DEC); 
    Serial.print("Fix: "); Serial.print((int)GPS.fix); 
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
    if (GPS.fix) { 
     //Serial.print("Location: "); 
     Serial.print(convertDegMinToDecDeg(GPS.latitude)); 
     Serial.print(", "); 
     Serial.println(convertDegMinToDecDeg(GPS.longitude)); 

     //Serial.print("Speed (knots): "); Serial.println(GPS.speed); 
     //Serial.print("Angle: "); Serial.println(GPS.angle); 
     //Serial.print("Altitude: "); Serial.println(GPS.altitude); 
     //Serial.print("Satellites: ");  Serial.println((int)GPS.satellites); 
    } 
    } 
} 

코드 모두 아래에 주어진하지만 난 그들과 실행을 결합 드릴 수 없습니다 하나의 코드로. 나는 그들을 결합하려고 애썼다. 궁극의 GPS 브레이크 아웃이 작동하지 않고 아무것도주지 않는다. 단일 코드로 작업하기 위해 이들을 결합 할 수있는 방법을 알고 싶습니다. 미리 감사드립니다.

답변

0

사용 NeoGPS 대신에 - 당신의 IMU 스케치에 추가 :

#include <NMEAGPS.h> 
NMEAGPS gps; 
#define gpsPort Serial1 

    ... 

void setup(){ 
    Wire1.begin(); 
    Wire1.beginTransmission(MPU_addr); 
    Wire1.write(0x6B); // PWR_MGMT_1 register 
    Wire1.write(0);  // set to zero (wakes up the MPU-6050) 
    Wire1.endTransmission(true); 
    Serial.begin(9600); 
    pinMode(led, OUTPUT); 

    gpsPort.begin(9600); 
} 

void loop(){ 
    if (gps.available(gpsPort)) { 
    gps_fix fix = gps.read(); // A new GPS update is ready, get all the pieces 
    // Print some of the pieces? 

    Serial.print(F("Location: ")); 
    if (fix.valid.location) { 
     Serial.print(fix.latitude(), 6); 
     Serial.print(','); 
     Serial.print(fix.longitude(), 6); 
    } 

    Serial.print(F(", Altitude: ")); 
    if (fix.valid.altitude) 
     Serial.print(fix.altitude()); 

    Serial.println(); 

    // Take an IMU sample too. 
    Wire1.beginTransmission(MPU_addr); 
     ... 
    Serial.print(" | GyZ = "); Serial.println(GyZ); 
    } 
} 

이 하나의 GPS 업데이트와 초당 IMU 샘플을 표시합니다.

또한 delay을 사용할 수 없습니다. Arduino는 지체없이 다른 작업을 수행하지 않으며 GPS 문자를 잃게됩니다. 위의 루프 구조는 항상 실행 중이며 GPS 데이터를 확인합니다. 마침내 GPS 업데이트가 준비되면 IMU 샘플을 가져 와서 모든 결과를 인쇄합니다.

또한 printing too much 정보에주의해야합니다. 결국, Arduino는 문자를 인쇄하기 위해 모든 시간을 할애 할 것입니다.

NeoGPS는 Arduino IDE 라이브러리 관리자의 스케치 -> 라이브러리 포함 -> 라이브러리 관리 메뉴에서 사용할 수 있습니다. NeoGPS는 다른 모든 GPS 라이브러리보다 빠르고, 작고, 신뢰성이 높으며 정확합니다. 예제는 적절하게 구조화되어 있습니다. 다른 라이브러리의 예제는 수정 될 때 아주 잘 나옵니다. 사용하지 않더라도 NeoGPS 설치 및 문제 해결 페이지에는 많은 정보가 있습니다.