![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dependencies: ADXL345 DHT HMC5883L SerialGPS mbed
main.cpp@1:082c5ed435fa, 2016-11-08 (annotated)
- Committer:
- fadi_lad
- Date:
- Tue Nov 08 08:36:54 2016 +0000
- Revision:
- 1:082c5ed435fa
- Parent:
- 0:f39c73c23563
V 0.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fadi_lad | 0:f39c73c23563 | 1 | #include "mbed.h" |
fadi_lad | 0:f39c73c23563 | 2 | #include "DHT.h" |
fadi_lad | 0:f39c73c23563 | 3 | #include "HMC5883L.h" |
fadi_lad | 0:f39c73c23563 | 4 | #include "ADXL345.h" |
fadi_lad | 0:f39c73c23563 | 5 | #include "SerialGPS.h" |
fadi_lad | 0:f39c73c23563 | 6 | #define SDA A4 |
fadi_lad | 0:f39c73c23563 | 7 | #define SCL A5 |
fadi_lad | 0:f39c73c23563 | 8 | |
fadi_lad | 0:f39c73c23563 | 9 | Serial pc(D8, PA_10); |
fadi_lad | 0:f39c73c23563 | 10 | DHT sensor(D7, DHT11); |
fadi_lad | 0:f39c73c23563 | 11 | HMC5883L compass(SDA, SCL); |
fadi_lad | 0:f39c73c23563 | 12 | ADXL345 accelerometer(D4, D5, D3, D2); |
fadi_lad | 0:f39c73c23563 | 13 | SerialGPS gps(D1, D0); |
fadi_lad | 0:f39c73c23563 | 14 | |
fadi_lad | 0:f39c73c23563 | 15 | |
fadi_lad | 0:f39c73c23563 | 16 | int main() { |
fadi_lad | 0:f39c73c23563 | 17 | /////////////// Declaration des différentes variables utilisées //////////////// |
fadi_lad | 0:f39c73c23563 | 18 | float temp,Humidity; |
fadi_lad | 0:f39c73c23563 | 19 | float xBoussole, yBoussole, zBoussole; |
fadi_lad | 0:f39c73c23563 | 20 | int Hour, Min, Sec, Pos, Sat; |
fadi_lad | 0:f39c73c23563 | 21 | double Latitude, Longitude; |
fadi_lad | 0:f39c73c23563 | 22 | /////////////////// configuration de la liaison serie ////////////////////////// |
fadi_lad | 0:f39c73c23563 | 23 | pc.baud(9600); //speed(baud) |
fadi_lad | 0:f39c73c23563 | 24 | pc.format(8,Serial::None,1); //format(bits,SerialBase,stop_bits) |
fadi_lad | 0:f39c73c23563 | 25 | /////////////////// configuration du cap température /////////////////////////// |
fadi_lad | 0:f39c73c23563 | 26 | int err; |
fadi_lad | 0:f39c73c23563 | 27 | /////////////////// configuration de la Boussole /////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 28 | HMC5883L hmc5883l(SDA, SCL); |
fadi_lad | 0:f39c73c23563 | 29 | /////////////////// configuration de l'accélérométre /////////////////////////// |
fadi_lad | 0:f39c73c23563 | 30 | int readings[3] = {0, 0, 0}; |
fadi_lad | 0:f39c73c23563 | 31 | //Go into standby mode to configure the device. |
fadi_lad | 0:f39c73c23563 | 32 | accelerometer.setPowerControl(0x00); |
fadi_lad | 0:f39c73c23563 | 33 | //Full resolution, +/-16g, 4mg/LSB. |
fadi_lad | 0:f39c73c23563 | 34 | accelerometer.setDataFormatControl(0x0B); |
fadi_lad | 0:f39c73c23563 | 35 | //3.2kHz data rate. |
fadi_lad | 0:f39c73c23563 | 36 | accelerometer.setDataRate(ADXL345_3200HZ); |
fadi_lad | 0:f39c73c23563 | 37 | //Measurement mode. |
fadi_lad | 0:f39c73c23563 | 38 | accelerometer.setPowerControl(0x08); |
fadi_lad | 0:f39c73c23563 | 39 | /////////////////// configuration GPS ////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 40 | SerialGPS::gps_gga_t *p; |
fadi_lad | 0:f39c73c23563 | 41 | |
fadi_lad | 0:f39c73c23563 | 42 | while(1) { |
fadi_lad | 0:f39c73c23563 | 43 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 44 | ////////////////////////// aquisation du capteur de température///////////////// |
fadi_lad | 0:f39c73c23563 | 45 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 46 | err = sensor.readData(); |
fadi_lad | 0:f39c73c23563 | 47 | //if (err==0){ |
fadi_lad | 0:f39c73c23563 | 48 | temp=sensor.ReadTemperature(CELCIUS); |
fadi_lad | 0:f39c73c23563 | 49 | Humidity=sensor.ReadHumidity(); |
fadi_lad | 1:082c5ed435fa | 50 | |
fadi_lad | 0:f39c73c23563 | 51 | // }else |
fadi_lad | 0:f39c73c23563 | 52 | // pc.printf("\r\Error DHT %i \n",err); |
fadi_lad | 0:f39c73c23563 | 53 | wait(5); |
fadi_lad | 0:f39c73c23563 | 54 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 55 | ////////////////////////// aquisation de la boussole /////////////////////////// |
fadi_lad | 0:f39c73c23563 | 56 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 57 | xBoussole = hmc5883l.getMx(); |
fadi_lad | 0:f39c73c23563 | 58 | yBoussole = hmc5883l.getMy(); |
fadi_lad | 0:f39c73c23563 | 59 | zBoussole = hmc5883l.getMz(); |
fadi_lad | 0:f39c73c23563 | 60 | |
fadi_lad | 0:f39c73c23563 | 61 | wait(5); |
fadi_lad | 0:f39c73c23563 | 62 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 63 | ////////////////////////// aquisation de l'accélérométre /////////////////////// |
fadi_lad | 0:f39c73c23563 | 64 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 65 | accelerometer.getOutput(readings); |
fadi_lad | 0:f39c73c23563 | 66 | // pc.printf("accelerometre %i, %i, %i\r\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); |
fadi_lad | 0:f39c73c23563 | 67 | // pc.printf("AT$SS= %x \r\n",(int)readings[0]); |
fadi_lad | 0:f39c73c23563 | 68 | // pc.printf("AT$SS= %x \r\n",(int)readings[1]); |
fadi_lad | 0:f39c73c23563 | 69 | // pc.printf("AT$SS= %x \r\n",(int)readings[2]); |
fadi_lad | 0:f39c73c23563 | 70 | |
fadi_lad | 0:f39c73c23563 | 71 | |
fadi_lad | 0:f39c73c23563 | 72 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 73 | ////////////////////////// aquisation gps ////////////::::::::::::::://///////// |
fadi_lad | 0:f39c73c23563 | 74 | //////////////////////////////////////////////////////////////////////////////// |
fadi_lad | 0:f39c73c23563 | 75 | gps.processing(); |
fadi_lad | 0:f39c73c23563 | 76 | Hour= p->hour; |
fadi_lad | 0:f39c73c23563 | 77 | Min = p->min; |
fadi_lad | 0:f39c73c23563 | 78 | Sec = p->sec; |
fadi_lad | 0:f39c73c23563 | 79 | Pos = p->position_fix; |
fadi_lad | 0:f39c73c23563 | 80 | Sat = p->satellites_used; |
fadi_lad | 0:f39c73c23563 | 81 | Latitude = p->latitude; |
fadi_lad | 0:f39c73c23563 | 82 | Longitude= p->longitude; |
fadi_lad | 1:082c5ed435fa | 83 | // pc.printf("AT$SS= %f \r\n",temp); |
fadi_lad | 1:082c5ed435fa | 84 | // pc.printf("AT$SS= %f \r\n",Humidity); |
fadi_lad | 1:082c5ed435fa | 85 | // pc.printf("AT$SS= %8x \r\n",*((int *)&xBoussole)); |
fadi_lad | 1:082c5ed435fa | 86 | // pc.printf("AT$SS= %8x \r\n",(int)yBoussole); |
fadi_lad | 1:082c5ed435fa | 87 | // pc.printf("AT$SS= %8x \r\n",(int)zBoussole); |
fadi_lad | 1:082c5ed435fa | 88 | // pc.printf("AT$SS= %x \r\n", (int)Latitude); |
fadi_lad | 1:082c5ed435fa | 89 | // pc.printf("AT$SS=00 12 FF 42 \r\n"); |
fadi_lad | 1:082c5ed435fa | 90 | // pc.printf("humidity= %4.2f C\r\n",); |
fadi_lad | 1:082c5ed435fa | 91 | // pc.printf("AT$SS= %x \r\n", (int)Longitude); |
fadi_lad | 1:082c5ed435fa | 92 | ////////////////////////////////////////////// |
fadi_lad | 1:082c5ed435fa | 93 | pc.printf("AT$SS= %x%x \r\n", (unsigned char*)&Longitude,(unsigned char*)&Latitude); |
fadi_lad | 1:082c5ed435fa | 94 | |
fadi_lad | 1:082c5ed435fa | 95 | // pc.printf("AT$SS= %x \r\n", (int)Longitude); |
fadi_lad | 1:082c5ed435fa | 96 | |
fadi_lad | 1:082c5ed435fa | 97 | wait(0); |
fadi_lad | 0:f39c73c23563 | 98 | |
fadi_lad | 0:f39c73c23563 | 99 | } |
fadi_lad | 0:f39c73c23563 | 100 | } |
fadi_lad | 0:f39c73c23563 | 101 |