ilf

Untitled

ilf
May 24th, 2017
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <NMEAGPS.h>
  3. #include <lmic.h>
  4. #include <SPI.h>
  5.  
  6. #include <Wire.h>
  7. #include <Adafruit_LSM303_U.h>
  8. #include <Adafruit_BMP085_U.h>
  9. #include <Adafruit_Sensor.h>
  10. #include <Adafruit_Sensor_Set.h>
  11. #include <Adafruit_Simple_AHRS.h>
  12. #include <Madgwick.h>
  13. #include <Mahony.h>
  14.  
  15. // Accelerometer + Giro + ...
  16.  
  17. // Create sensor instances.
  18. Adafruit_LSM303_Accel_Unified accel(30301);
  19. Adafruit_LSM303_Mag_Unified mag(30302);
  20. Adafruit_BMP085_Unified bmp(18001);
  21.  
  22. // Create simple AHRS algorithm using the above sensors.
  23. Adafruit_Simple_AHRS ahrs(&accel, &mag);
  24.  
  25. // Update this with the correct SLP for accurate altitude measurements
  26. float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
  27.  
  28. // GPS
  29.  
  30. #if defined( UBRR1H ) | defined( ID_USART0 )
  31. // Default is to use NeoSerial1 when available. You could also
  32. #include <NeoHWSerial.h>
  33. // NOTE: There is an issue with IDEs before 1.6.6. The above include
  34. // must be commented out for non-Mega boards, even though it is
  35. // conditionally included. If you are using an earlier IDEs,
  36. // comment the above include.
  37. #else
  38. // Only one serial port is available, uncomment one of the following:
  39. //#include <NeoICSerial.h>
  40. #include <NeoSWSerial.h>
  41. //#include <SoftwareSerial.h> /* NOT RECOMMENDED */
  42. #endif
  43. #define RX_PIN 4
  44. #define TX_PIN 5
  45. #include "GPSport.h"
  46.  
  47. #include "Streamers.h"
  48. #ifdef NeoHWSerial_h
  49. #define DEBUG_PORT NeoSerial
  50. #else
  51. #define DEBUG_PORT Serial
  52. #endif
  53.  
  54. // Check configuration
  55.  
  56. #ifndef NMEAGPS_INTERRUPT_PROCESSING
  57. #error You must define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
  58. #endif
  59.  
  60. static NMEAGPS gps;
  61.  
  62. static void GPSisr( uint8_t c )
  63. {
  64. gps.handle( c );
  65.  
  66. }
  67.  
  68. void setup()
  69. {
  70. Serial.begin(9600);
  71. Serial.println(F("Adafruit 10 DOF Board AHRS Example")); Serial.println("");
  72.  
  73. // GPS
  74.  
  75. // Start the normal trace output
  76. DEBUG_PORT.begin(115200);
  77. while (!DEBUG_PORT)
  78. ;
  79.  
  80. DEBUG_PORT.print( F("NMEA_isr.INO: started\n") );
  81. DEBUG_PORT.print( F("fix object size = ") );
  82. DEBUG_PORT.println( sizeof(gps.fix()) );
  83. DEBUG_PORT.print( F("NMEAGPS object size = ") );
  84. DEBUG_PORT.println( sizeof(gps) );
  85. DEBUG_PORT.println( F("Looking for GPS device on " USING_GPS_PORT) );
  86.  
  87. trace_header( DEBUG_PORT );
  88.  
  89. DEBUG_PORT.flush();
  90.  
  91. // GPS
  92.  
  93. // Start the UART for the GPS device
  94. gps_port.attachInterrupt( GPSisr );
  95. gps_port.begin( 9600 );
  96.  
  97. ////////////////////// Setup End ///////////////////////////
  98.  
  99. // Initialize the sensors.
  100. accel.begin();
  101. mag.begin();
  102. bmp.begin();
  103.  
  104. }
  105.  
  106. void loop(void)
  107. {
  108. sensors_vec_t orientation;
  109.  
  110. // Use the simple AHRS function to get the current orientation.
  111. if (ahrs.getOrientation(&orientation))
  112. {
  113. /* 'orientation' should have valid .roll and .pitch fields */
  114. Serial.print(F("Orientation: "));
  115. Serial.print(orientation.roll);
  116. Serial.print(F(" "));
  117. Serial.print(orientation.pitch);
  118. Serial.print(F(" "));
  119. Serial.print(orientation.heading);
  120. Serial.println(F(""));
  121. }
  122.  
  123. // Calculate the altitude using the barometric pressure sensor
  124. sensors_event_t bmp_event;
  125. bmp.getEvent(&bmp_event);
  126. if (bmp_event.pressure)
  127. {
  128. /* Get ambient temperature in C */
  129. float temperature;
  130. bmp.getTemperature(&temperature);
  131. /* Convert atmospheric pressure, SLP and temp to altitude */
  132. Serial.print(F("Alt: "));
  133. Serial.print(bmp.pressureToAltitude(seaLevelPressure,
  134. bmp_event.pressure,
  135. temperature));
  136. Serial.println(F(""));
  137. /* Display the temperature */
  138. Serial.print(F("Temp: "));
  139. Serial.print(temperature);
  140. Serial.println(F(""));
  141.  
  142. if (gps.available()) {
  143. // Print all the things!
  144. trace_all( DEBUG_PORT, gps, gps.read() );
  145. }
  146.  
  147. if (gps.overrun()) {
  148. gps.overrun( false );
  149. DEBUG_PORT.println( F("DATA OVERRUN: took too long to use gps.read() data!") );
  150.  
  151. }
  152.  
  153. }
  154.  
  155. // delay(3000);
  156. }
Advertisement
Add Comment
Please, Sign In to add comment