![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
by L.F
Dependencies: ADXL345 DHT HMC5883L SerialGPS mbed
main.cpp@0:9bd930408c8c, 2017-01-03 (annotated)
- Committer:
- fadi_lad
- Date:
- Tue Jan 03 09:25:27 2017 +0000
- Revision:
- 0:9bd930408c8c
V 1.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fadi_lad | 0:9bd930408c8c | 1 | #include "mbed.h" |
fadi_lad | 0:9bd930408c8c | 2 | #include "HMC5883L.h" |
fadi_lad | 0:9bd930408c8c | 3 | #include "DHT.h" |
fadi_lad | 0:9bd930408c8c | 4 | #include "ADXL345.h" |
fadi_lad | 0:9bd930408c8c | 5 | #include "SerialGPS.h" |
fadi_lad | 0:9bd930408c8c | 6 | |
fadi_lad | 0:9bd930408c8c | 7 | SerialGPS gps(D1, D0); |
fadi_lad | 0:9bd930408c8c | 8 | DHT sensor(D7, DHT22); |
fadi_lad | 0:9bd930408c8c | 9 | Serial pc(D8, PA_10); // tx, rx |
fadi_lad | 0:9bd930408c8c | 10 | // Utility Boussole HMC5883L |
fadi_lad | 0:9bd930408c8c | 11 | #ifndef M_PI |
fadi_lad | 0:9bd930408c8c | 12 | #define M_PI 3.1415926535897932384626433832795 |
fadi_lad | 0:9bd930408c8c | 13 | #endif |
fadi_lad | 0:9bd930408c8c | 14 | #define PI2 (2*M_PI) |
fadi_lad | 0:9bd930408c8c | 15 | #define RAD_TO_DEG (180.0/M_PI) |
fadi_lad | 0:9bd930408c8c | 16 | #define DEG_TO_RAD (M_PI/180.0) |
fadi_lad | 0:9bd930408c8c | 17 | #define DECLINATION_ANGLE -0.02123 |
fadi_lad | 0:9bd930408c8c | 18 | #define SDA A4 |
fadi_lad | 0:9bd930408c8c | 19 | #define SCL A5 |
fadi_lad | 0:9bd930408c8c | 20 | |
fadi_lad | 0:9bd930408c8c | 21 | int main() |
fadi_lad | 0:9bd930408c8c | 22 | { |
fadi_lad | 0:9bd930408c8c | 23 | // varible Boussole HMC5883L |
fadi_lad | 0:9bd930408c8c | 24 | double heading; |
fadi_lad | 0:9bd930408c8c | 25 | float x, y, z; |
fadi_lad | 0:9bd930408c8c | 26 | HMC5883L hmc5883l(SDA, SCL); |
fadi_lad | 0:9bd930408c8c | 27 | // variable DHT11 /////////////////////////// |
fadi_lad | 0:9bd930408c8c | 28 | float temp,Humidity; |
fadi_lad | 0:9bd930408c8c | 29 | int err; |
fadi_lad | 0:9bd930408c8c | 30 | // configuration GPS ////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 31 | SerialGPS::gps_gga_t *p; |
fadi_lad | 0:9bd930408c8c | 32 | int Hour, Min, Sec, Pos, Sat; |
fadi_lad | 0:9bd930408c8c | 33 | double Latitude, Longitude; |
fadi_lad | 0:9bd930408c8c | 34 | |
fadi_lad | 0:9bd930408c8c | 35 | while(1) |
fadi_lad | 0:9bd930408c8c | 36 | { |
fadi_lad | 0:9bd930408c8c | 37 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 38 | ////////////////////////// aquisation de la boussole /////////////////////////// |
fadi_lad | 0:9bd930408c8c | 39 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 40 | x = hmc5883l.getMx(); |
fadi_lad | 0:9bd930408c8c | 41 | y = hmc5883l.getMy(); |
fadi_lad | 0:9bd930408c8c | 42 | z = hmc5883l.getMz(); |
fadi_lad | 0:9bd930408c8c | 43 | pc.printf("x, y, z: %f, %f,%f \r\n",x,y,z); |
fadi_lad | 0:9bd930408c8c | 44 | heading = atan2(static_cast<double>(y), static_cast<double>(x)); // heading = arctan(Y/X) |
fadi_lad | 0:9bd930408c8c | 45 | heading += DECLINATION_ANGLE; |
fadi_lad | 0:9bd930408c8c | 46 | if(heading < 0.0) // fix sign |
fadi_lad | 0:9bd930408c8c | 47 | heading += PI2; |
fadi_lad | 0:9bd930408c8c | 48 | if(heading > PI2) // fix overflow |
fadi_lad | 0:9bd930408c8c | 49 | heading -= PI2; |
fadi_lad | 0:9bd930408c8c | 50 | pc.printf("heading:%f\r\n",heading); |
fadi_lad | 0:9bd930408c8c | 51 | pc.printf("*********************\r\n"); |
fadi_lad | 0:9bd930408c8c | 52 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 53 | ////////////////////////// aquisation du capteur de température///////////////// |
fadi_lad | 0:9bd930408c8c | 54 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 55 | err = sensor.readData(); |
fadi_lad | 0:9bd930408c8c | 56 | if (err==0){ |
fadi_lad | 0:9bd930408c8c | 57 | temp=sensor.ReadTemperature(CELCIUS); |
fadi_lad | 0:9bd930408c8c | 58 | Humidity=sensor.ReadHumidity(); |
fadi_lad | 0:9bd930408c8c | 59 | pc.printf(" temp / hem =%f, %f\r\n",temp,Humidity); |
fadi_lad | 0:9bd930408c8c | 60 | } |
fadi_lad | 0:9bd930408c8c | 61 | pc.printf("*********************\r\n"); |
fadi_lad | 0:9bd930408c8c | 62 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 63 | ////////////////////////// aquisation gps ////////////::::::::::::::://///////// |
fadi_lad | 0:9bd930408c8c | 64 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:9bd930408c8c | 65 | gps.processing(); |
fadi_lad | 0:9bd930408c8c | 66 | Hour= p->hour; |
fadi_lad | 0:9bd930408c8c | 67 | Min = p->min; |
fadi_lad | 0:9bd930408c8c | 68 | Sec = p->sec; |
fadi_lad | 0:9bd930408c8c | 69 | Pos = p->position_fix; |
fadi_lad | 0:9bd930408c8c | 70 | Sat = p->satellites_used; |
fadi_lad | 0:9bd930408c8c | 71 | Latitude = p->latitude; |
fadi_lad | 0:9bd930408c8c | 72 | Longitude= p->longitude; |
fadi_lad | 0:9bd930408c8c | 73 | pc.printf("gps= %d, %d \r\n",Latitude,Longitude); |
fadi_lad | 0:9bd930408c8c | 74 | pc.printf("hour= %i \r\n",Hour); |
fadi_lad | 0:9bd930408c8c | 75 | pc.printf("min= %i \r\n",Sec); |
fadi_lad | 0:9bd930408c8c | 76 | pc.printf("position_fix= %i \r\n",Pos); |
fadi_lad | 0:9bd930408c8c | 77 | pc.printf("*********************\r\n"); |
fadi_lad | 0:9bd930408c8c | 78 | |
fadi_lad | 0:9bd930408c8c | 79 | wait(10); |
fadi_lad | 0:9bd930408c8c | 80 | } |
fadi_lad | 0:9bd930408c8c | 81 | } |