Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <NMEAGPS.h>
- #include <lmic.h>
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_LSM303_U.h>
- #include <Adafruit_BMP085_U.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_Sensor_Set.h>
- #include <Adafruit_Simple_AHRS.h>
- #include <Madgwick.h>
- #include <Mahony.h>
- // Accelerometer + Giro + ...
- // Create sensor instances.
- Adafruit_LSM303_Accel_Unified accel(30301);
- Adafruit_LSM303_Mag_Unified mag(30302);
- Adafruit_BMP085_Unified bmp(18001);
- // Create simple AHRS algorithm using the above sensors.
- Adafruit_Simple_AHRS ahrs(&accel, &mag);
- // Update this with the correct SLP for accurate altitude measurements
- float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
- // GPS
- #if defined( UBRR1H ) | defined( ID_USART0 )
- // Default is to use NeoSerial1 when available. You could also
- #include <NeoHWSerial.h>
- // NOTE: There is an issue with IDEs before 1.6.6. The above include
- // must be commented out for non-Mega boards, even though it is
- // conditionally included. If you are using an earlier IDEs,
- // comment the above include.
- #else
- // Only one serial port is available, uncomment one of the following:
- //#include <NeoICSerial.h>
- #include <NeoSWSerial.h>
- //#include <SoftwareSerial.h> /* NOT RECOMMENDED */
- #endif
- #define RX_PIN 4
- #define TX_PIN 5
- #include "GPSport.h"
- #include "Streamers.h"
- #ifdef NeoHWSerial_h
- #define DEBUG_PORT NeoSerial
- #else
- #define DEBUG_PORT Serial
- #endif
- // Check configuration
- #ifndef NMEAGPS_INTERRUPT_PROCESSING
- #error You must define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
- #endif
- static NMEAGPS gps;
- static void GPSisr( uint8_t c )
- {
- gps.handle( c );
- }
- void setup()
- {
- Serial.begin(9600);
- Serial.println(F("Adafruit 10 DOF Board AHRS Example")); Serial.println("");
- // GPS
- // Start the normal trace output
- DEBUG_PORT.begin(115200);
- while (!DEBUG_PORT)
- ;
- DEBUG_PORT.print( F("NMEA_isr.INO: started\n") );
- DEBUG_PORT.print( F("fix object size = ") );
- DEBUG_PORT.println( sizeof(gps.fix()) );
- DEBUG_PORT.print( F("NMEAGPS object size = ") );
- DEBUG_PORT.println( sizeof(gps) );
- DEBUG_PORT.println( F("Looking for GPS device on " USING_GPS_PORT) );
- trace_header( DEBUG_PORT );
- DEBUG_PORT.flush();
- // GPS
- // Start the UART for the GPS device
- gps_port.attachInterrupt( GPSisr );
- gps_port.begin( 9600 );
- ////////////////////// Setup End ///////////////////////////
- // Initialize the sensors.
- accel.begin();
- mag.begin();
- bmp.begin();
- }
- void loop(void)
- {
- sensors_vec_t orientation;
- // Use the simple AHRS function to get the current orientation.
- if (ahrs.getOrientation(&orientation))
- {
- /* 'orientation' should have valid .roll and .pitch fields */
- Serial.print(F("Orientation: "));
- Serial.print(orientation.roll);
- Serial.print(F(" "));
- Serial.print(orientation.pitch);
- Serial.print(F(" "));
- Serial.print(orientation.heading);
- Serial.println(F(""));
- }
- // Calculate the altitude using the barometric pressure sensor
- sensors_event_t bmp_event;
- bmp.getEvent(&bmp_event);
- if (bmp_event.pressure)
- {
- /* Get ambient temperature in C */
- float temperature;
- bmp.getTemperature(&temperature);
- /* Convert atmospheric pressure, SLP and temp to altitude */
- Serial.print(F("Alt: "));
- Serial.print(bmp.pressureToAltitude(seaLevelPressure,
- bmp_event.pressure,
- temperature));
- Serial.println(F(""));
- /* Display the temperature */
- Serial.print(F("Temp: "));
- Serial.print(temperature);
- Serial.println(F(""));
- if (gps.available()) {
- // Print all the things!
- trace_all( DEBUG_PORT, gps, gps.read() );
- }
- if (gps.overrun()) {
- gps.overrun( false );
- DEBUG_PORT.println( F("DATA OVERRUN: took too long to use gps.read() data!") );
- }
- }
- // delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment