projet en 1 main.cpp

Dependencies:   DHT11 HMC5883L

Committer:
wallsow
Date:
Mon Feb 06 10:18:50 2017 +0000
Revision:
4:06944df56a2d
Parent:
3:d2c57ab99c8e
instrctable fin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jijou 0:0e12a7930611 1 #include "mbed.h"
jijou 0:0e12a7930611 2 #include "DHT11.h"
jijou 0:0e12a7930611 3 #include "HMC5883L.h"
jijou 0:0e12a7930611 4 #include "gps.h"
jijou 0:0e12a7930611 5
wallsow 4:06944df56a2d 6 #define PRINT_CALCULATED
wallsow 4:06944df56a2d 7 #define PRINT_SPEED 500 // 500 ms between prints
jijou 0:0e12a7930611 8
jijou 0:0e12a7930611 9
jijou 0:0e12a7930611 10 //-------Pin Connection----///
wallsow 4:06944df56a2d 11 DHT11 sensor(D4);//D4= dht11 data
jijou 0:0e12a7930611 12 HMC5883L bouss(PB_9, PB_8); // HMC5883L(PinName sda, PinName scl) PB_8 + PB_9
jijou 0:0e12a7930611 13 Serial rfid(PA_9, PA_10); // pa9=d8 pa10=d2
jijou 0:0e12a7930611 14 Serial serial(PA_0,PA_1); /*PA_0=A0=TX PA_1=A0=RX*/
jijou 0:0e12a7930611 15 AnalogIn inputx(PC_0); // input A5 for X axis
jijou 0:0e12a7930611 16 AnalogIn inputy(PC_1); // input A4 for Y axis
jijou 0:0e12a7930611 17 AnalogIn inputz(PB_1); // input A3 for Z axis
jijou 0:0e12a7930611 18
jijou 0:0e12a7930611 19 float x=0,y=0,z=0; // variables for x,y,z axes
jijou 0:0e12a7930611 20
wallsow 2:7e718a1be318 21 int H, T, s;
wallsow 2:7e718a1be318 22 float Boussole;
wallsow 2:7e718a1be318 23 int Head;
wallsow 4:06944df56a2d 24 char buff[55];
wallsow 3:d2c57ab99c8e 25 int RFIDA;
jijou 0:0e12a7930611 26
wallsow 2:7e718a1be318 27 int DHT_Start_Temper()
jijou 0:0e12a7930611 28 {
wallsow 4:06944df56a2d 29 s = sensor.readData();
wallsow 4:06944df56a2d 30 T=sensor.readTemperature();
wallsow 4:06944df56a2d 31 return T;
wallsow 2:7e718a1be318 32 }
wallsow 2:7e718a1be318 33
wallsow 2:7e718a1be318 34 int DHT_Start_Humid()
wallsow 2:7e718a1be318 35 {
wallsow 4:06944df56a2d 36 s = sensor.readData();
wallsow 2:7e718a1be318 37 H=sensor.readHumidity();
wallsow 2:7e718a1be318 38 return H;
jijou 0:0e12a7930611 39 }
jijou 0:0e12a7930611 40
jijou 0:0e12a7930611 41
wallsow 2:7e718a1be318 42 int Boussole_Start()
jijou 0:0e12a7930611 43 {
wallsow 4:06944df56a2d 44 //Head is divided by 2 because of sending data to actoboard the value is limit to 255
jijou 0:0e12a7930611 45 bouss.init();
wallsow 4:06944df56a2d 46 Boussole= bouss.getHeadingXYDeg();
wallsow 2:7e718a1be318 47 Head=((int)Boussole)/2;
wallsow 2:7e718a1be318 48 serial.printf("\r\n-----Boussole-----\r\n%2f\r\n-----Boussole-----\r\n",Boussole);
wallsow 4:06944df56a2d 49 return Head;
wallsow 2:7e718a1be318 50 }
wallsow 2:7e718a1be318 51
wallsow 2:7e718a1be318 52 int Accelerometre_Start_x()
wallsow 2:7e718a1be318 53 {
wallsow 2:7e718a1be318 54 x = inputx;
wallsow 2:7e718a1be318 55 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 56 return x;
jijou 0:0e12a7930611 57 }
jijou 0:0e12a7930611 58
wallsow 2:7e718a1be318 59 int Accelerometre_Start_y()
jijou 0:0e12a7930611 60 {
jijou 0:0e12a7930611 61 y = inputy;
wallsow 2:7e718a1be318 62 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 63 return y;
wallsow 2:7e718a1be318 64 }
wallsow 2:7e718a1be318 65
wallsow 2:7e718a1be318 66 int Accelerometre_Start_z()
wallsow 2:7e718a1be318 67 {
jijou 0:0e12a7930611 68 z = inputz;
jijou 1:352fcb35e812 69 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 70 return z;
jijou 0:0e12a7930611 71 }
jijou 0:0e12a7930611 72
jijou 0:0e12a7930611 73
wallsow 2:7e718a1be318 74
wallsow 3:d2c57ab99c8e 75 void RFID_Start()
jijou 0:0e12a7930611 76 {
wallsow 4:06944df56a2d 77 int i;
wallsow 4:06944df56a2d 78 int tag[15];
jijou 0:0e12a7930611 79
wallsow 4:06944df56a2d 80 for(i=0; i<5; i++)
wallsow 4:06944df56a2d 81 tag[i]=rfid.getc();
jijou 0:0e12a7930611 82
wallsow 4:06944df56a2d 83 sprintf(buff,"%d%d%d%d%d",tag[0],tag[1],tag[2],tag[3],tag[4]);
wallsow 4:06944df56a2d 84 serial.printf("\r\n-----Tag RFID-----\r\n%s \r\n-----Tag RFID-----\r\n",buff);
wallsow 3:d2c57ab99c8e 85
jijou 0:0e12a7930611 86 }
jijou 0:0e12a7930611 87 //---------------
jijou 0:0e12a7930611 88
jijou 0:0e12a7930611 89 int main()
jijou 0:0e12a7930611 90 {
jijou 0:0e12a7930611 91 //serial config
jijou 0:0e12a7930611 92 serial.baud(9600);
jijou 0:0e12a7930611 93 serial.format(8,SerialBase::None,1);
wallsow 4:06944df56a2d 94
wallsow 3:d2c57ab99c8e 95 serial.printf("\r\n Bracelet Orientation\r\n****************\r\n");
wallsow 4:06944df56a2d 96
wallsow 2:7e718a1be318 97 char *p1lat, *p2lat, *p3lat;
wallsow 2:7e718a1be318 98 int intp1lat, intp2lat, intp3lat;
wallsow 2:7e718a1be318 99 char *p1long, *p2long, *p3long;
wallsow 2:7e718a1be318 100 int intp1long, intp2long, intp3long;
jijou 0:0e12a7930611 101
jijou 0:0e12a7930611 102
wallsow 4:06944df56a2d 103 while(1) {
wallsow 2:7e718a1be318 104 T=DHT_Start_Temper();
wallsow 2:7e718a1be318 105 H=DHT_Start_Humid();
wallsow 2:7e718a1be318 106 Head=Boussole_Start();
wallsow 4:06944df56a2d 107 x=Accelerometre_Start_x();
wallsow 2:7e718a1be318 108 y=Accelerometre_Start_y();
wallsow 4:06944df56a2d 109 z=Accelerometre_Start_z();
wallsow 4:06944df56a2d 110 getGPSstring();
wallsow 3:d2c57ab99c8e 111
wallsow 4:06944df56a2d 112
wallsow 3:d2c57ab99c8e 113 RFID_Start();
wallsow 3:d2c57ab99c8e 114 RFIDA=atoi(buff);
wallsow 3:d2c57ab99c8e 115 RFIDA=RFIDA/10000000;
wallsow 4:06944df56a2d 116
wallsow 4:06944df56a2d 117 //traitement Latitude
wallsow 2:7e718a1be318 118 p1lat = strtok(lati,"'");
wallsow 2:7e718a1be318 119 p2lat= strtok(NULL, "'");//the second
wallsow 4:06944df56a2d 120 p3lat= strtok(NULL, ".");//the third
wallsow 4:06944df56a2d 121
wallsow 4:06944df56a2d 122 //conversion latitude
wallsow 2:7e718a1be318 123 intp1lat=atoi(p1lat);
wallsow 2:7e718a1be318 124 intp2lat=atoi(p2lat);
wallsow 2:7e718a1be318 125 intp3lat=atoi(p3lat);
wallsow 4:06944df56a2d 126 //concatcénation lati
wallsow 3:d2c57ab99c8e 127 int latitude_complet_int;
wallsow 3:d2c57ab99c8e 128 char latitude_complet[6];
wallsow 3:d2c57ab99c8e 129 strcat(latitude_complet,p1lat);
wallsow 3:d2c57ab99c8e 130 strcat(latitude_complet,p2lat);
wallsow 3:d2c57ab99c8e 131 strcat(latitude_complet,p3lat);
wallsow 3:d2c57ab99c8e 132 latitude_complet_int=atoi(latitude_complet);
wallsow 4:06944df56a2d 133
wallsow 4:06944df56a2d 134
wallsow 4:06944df56a2d 135
wallsow 4:06944df56a2d 136 //traitement longitude
wallsow 2:7e718a1be318 137 p1long = strtok(longi,"'");
wallsow 2:7e718a1be318 138 p2long= strtok(NULL, "'");//the second
wallsow 2:7e718a1be318 139 p3long= strtok(NULL, ".");//the third
wallsow 2:7e718a1be318 140 intp1long=atoi(p1long);
wallsow 2:7e718a1be318 141 intp2long=atoi(p2long);
wallsow 2:7e718a1be318 142 intp3long=atoi(p3long);
wallsow 4:06944df56a2d 143
wallsow 4:06944df56a2d 144 //concatcénation longitude
wallsow 3:d2c57ab99c8e 145 int longitude_complet_int;
wallsow 3:d2c57ab99c8e 146 char longitude_complet[6];
wallsow 3:d2c57ab99c8e 147 strcat(longitude_complet,p1long);
wallsow 3:d2c57ab99c8e 148 strcat(longitude_complet,p2long);
wallsow 3:d2c57ab99c8e 149 strcat(longitude_complet,p3long);
wallsow 3:d2c57ab99c8e 150 longitude_complet_int=atoi(longitude_complet);
wallsow 2:7e718a1be318 151
wallsow 4:06944df56a2d 152 serial.printf("AT$SS=%x%x%x%x%x0%x%x%x%x%x\r\n",T,H,intp1lat,intp2lat,intp3lat,intp1long,intp2long,intp3long,RFIDA,Head);
wallsow 4:06944df56a2d 153
wallsow 4:06944df56a2d 154 wait(5);
jijou 0:0e12a7930611 155 }
jijou 0:0e12a7930611 156 }