ilf

Untitled

ilf
May 24th, 2017
193
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(9600);
  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. ////////////////////// Setup End ///////////////////////////
  92.  
  93. // Initialize the sensors.
  94. accel.begin();
  95. mag.begin();
  96. bmp.begin();
  97.  
  98. // GPS
  99.  
  100. // Start the UART for the GPS device
  101. gps_port.attachInterrupt( GPSisr );
  102. gps_port.begin( 9600 );
  103. }
  104.  
  105. void loop(void)
  106. {
  107. sensors_vec_t orientation;
  108.  
  109. // Use the simple AHRS function to get the current orientation.
  110. if (ahrs.getOrientation(&orientation))
  111. {
  112. /* 'orientation' should have valid .roll and .pitch fields */
  113. Serial.print(F("Orientation: "));
  114. Serial.print(orientation.roll);
  115. Serial.print(F(" "));
  116. Serial.print(orientation.pitch);
  117. Serial.print(F(" "));
  118. Serial.print(orientation.heading);
  119. Serial.println(F(""));
  120. }
  121.  
  122. // Calculate the altitude using the barometric pressure sensor
  123. sensors_event_t bmp_event;
  124. bmp.getEvent(&bmp_event);
  125. if (bmp_event.pressure)
  126. {
  127. /* Get ambient temperature in C */
  128. float temperature;
  129. bmp.getTemperature(&temperature);
  130. /* Convert atmospheric pressure, SLP and temp to altitude */
  131. Serial.print(F("Alt: "));
  132. Serial.print(bmp.pressureToAltitude(seaLevelPressure,
  133. bmp_event.pressure,
  134. temperature));
  135. Serial.println(F(""));
  136. /* Display the temperature */
  137. Serial.print(F("Temp: "));
  138. Serial.print(temperature);
  139. Serial.println(F(""));
  140.  
  141. if (gps.available()) {
  142. // Print all the things!
  143. trace_all( DEBUG_PORT, gps, gps.read() );
  144. }
  145.  
  146. if (gps.overrun()) {
  147. gps.overrun( false );
  148. DEBUG_PORT.println( F("DATA OVERRUN: took too long to use gps.read() data!") );
  149.  
  150. }
  151.  
  152. }
  153.  
  154. delay(1000);
  155. }
Advertisement
Add Comment
Please, Sign In to add comment