From 9c0f882007ac9e4f2d4298cd87160116650deaf8 Mon Sep 17 00:00:00 2001 From: James Devine Date: Sat, 20 Jun 2015 07:18:57 -0700 Subject: [PATCH] --- gistfile1.txt | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 gistfile1.txt diff --git a/gistfile1.txt b/gistfile1.txt new file mode 100644 index 0000000..2424e99 --- /dev/null +++ b/gistfile1.txt @@ -0,0 +1,145 @@ + +// HTU21D-F is on Arduino Due I2C Bus 2, followed the guidance on forum.arduino.cc/index.php?topic=216359.0 to make it work +//modifications to HTU21DF.h and .cpp not included in this file. Also commented out delay.h as it's AVR not ARM. + +#include + +#include +#include +#include +#include +#include + + +#include + + +/* Assign a unique ID to the sensors */ +Adafruit_10DOF dof = Adafruit_10DOF(); +Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301); +Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302); +Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(18001); +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); + +/* Update this with the correct SLP for accurate altitude measurements */ +float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; + +/**************************************************************************/ +/*! + @brief Initialises all the sensors used by this example +*/ +/**************************************************************************/ +void initSensors() +{ + if(!accel.begin()) + { + /* There was a problem detecting the LSM303 ... check your connections */ + Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!")); + while(1); + } + if(!mag.begin()) + { + /* There was a problem detecting the LSM303 ... check your connections */ + Serial.println("Ooops, no LSM303 detected ... Check your wiring!"); + while(1); + } + if(!bmp.begin()) + { + /* There was a problem detecting the BMP180 ... check your connections */ + Serial.println("Ooops, no BMP180 detected ... Check your wiring!"); + while(1); + } + if (!htu.begin()) { + Serial.println("Couldn't find HTU21DF sensor!"); + while (1); + } +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Adafruit 10 DOF Pitch/Roll/Heading Example with Humidity")); Serial.println(""); + + /* Initialise the sensors */ + initSensors(); +} + +/**************************************************************************/ +/*! + @brief Constantly check the roll/pitch/heading/altitude/temperature +*/ +/**************************************************************************/ +void loop(void) +{ + sensors_event_t accel_event; + sensors_event_t mag_event; + sensors_event_t bmp_event; + sensors_vec_t orientation; + + /* Calculate pitch and roll from the raw accelerometer data */ + accel.getEvent(&accel_event); + if (dof.accelGetOrientation(&accel_event, &orientation)) + { + /* 'orientation' should have valid .roll and .pitch fields */ + Serial.println("Data dump from raw sensors"); + Serial.print(F("Roll: ")); + Serial.print(orientation.roll); + Serial.print(F("; ")); + Serial.print(F("Pitch: ")); + Serial.print(orientation.pitch); + Serial.println(F("; ")); + Serial.print("GravX:"); + Serial.println(accel_event.acceleration.x); + Serial.print("Gravy:"); + Serial.println(accel_event.acceleration.y); + Serial.print("Gravz:"); + Serial.println(accel_event.acceleration.z); + + } + + /* Calculate the heading using the magnetometer */ + mag.getEvent(&mag_event); + if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation)) + { + /* 'orientation' should have valid .heading data now */ + Serial.print(F("Heading: ")); + Serial.print(orientation.heading); + Serial.println(F("; ")); + Serial.print("Magx:"); + Serial.println(mag_event.magnetic.x); + Serial.print("Magy:"); + Serial.println(mag_event.magnetic.y); + Serial.print("Magz:"); + Serial.println(mag_event.magnetic.z); + } + + /* Calculate the altitude using the barometric pressure sensor */ + 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(" m; ")); + /* Display the temperature */ + Serial.print(F("Temp1: ")); + Serial.print(temperature); + Serial.println(F(" C")); + + Serial.print("Temp2: "); Serial.println(htu.readTemperature()); + Serial.print("Hum: "); Serial.println(htu.readHumidity()); + } + + Serial.println(F("")); + delay(1000); +} \ No newline at end of file