projetlong
/
Projetlong_test
projet en 1 main.cpp
main.cpp@3:d2c57ab99c8e, 2017-02-06 (annotated)
- Committer:
- wallsow
- Date:
- Mon Feb 06 08:25:12 2017 +0000
- Revision:
- 3:d2c57ab99c8e
- Parent:
- 2:7e718a1be318
- Child:
- 4:06944df56a2d
Instrctabl
Who changed what in which revision?
User | Revision | Line number | New 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 | |
jijou | 0:0e12a7930611 | 6 | #define PRINT_CALCULATED |
jijou | 0:0e12a7930611 | 7 | #define PRINT_SPEED 500 // 500 ms between prints |
jijou | 0:0e12a7930611 | 8 | |
jijou | 0:0e12a7930611 | 9 | |
jijou | 0:0e12a7930611 | 10 | //-------Pin Connection----/// |
jijou | 0:0e12a7930611 | 11 | DHT11 sensor(D4);//D4=jeremy |
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 | 3:d2c57ab99c8e | 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 | 2:7e718a1be318 | 29 | s = sensor.readData(); |
wallsow | 2:7e718a1be318 | 30 | T=sensor.readTemperature();/* |
jijou | 0:0e12a7930611 | 31 | if (s != DHT11::OK) { |
jijou | 0:0e12a7930611 | 32 | serial.printf("Error!\r\n"); |
jijou | 0:0e12a7930611 | 33 | } |
jijou | 0:0e12a7930611 | 34 | else { |
wallsow | 2:7e718a1be318 | 35 | serial.printf("AT$SS=%x%x\r\n", T,H); |
wallsow | 2:7e718a1be318 | 36 | }*/ |
wallsow | 2:7e718a1be318 | 37 | return T; |
wallsow | 2:7e718a1be318 | 38 | } |
wallsow | 2:7e718a1be318 | 39 | |
wallsow | 2:7e718a1be318 | 40 | int DHT_Start_Humid() |
wallsow | 2:7e718a1be318 | 41 | { |
wallsow | 2:7e718a1be318 | 42 | s = sensor.readData(); |
wallsow | 2:7e718a1be318 | 43 | H=sensor.readHumidity(); |
wallsow | 2:7e718a1be318 | 44 | return H; |
jijou | 0:0e12a7930611 | 45 | } |
jijou | 0:0e12a7930611 | 46 | |
jijou | 0:0e12a7930611 | 47 | |
wallsow | 2:7e718a1be318 | 48 | int Boussole_Start() |
jijou | 0:0e12a7930611 | 49 | { |
jijou | 0:0e12a7930611 | 50 | bouss.init(); |
wallsow | 2:7e718a1be318 | 51 | Boussole= bouss.getHeadingXYDeg(); |
wallsow | 2:7e718a1be318 | 52 | Head=((int)Boussole)/2; |
wallsow | 2:7e718a1be318 | 53 | serial.printf("\r\n-----Boussole-----\r\n%2f\r\n-----Boussole-----\r\n",Boussole); |
wallsow | 2:7e718a1be318 | 54 | return Head; |
wallsow | 2:7e718a1be318 | 55 | } |
wallsow | 2:7e718a1be318 | 56 | |
wallsow | 2:7e718a1be318 | 57 | int Accelerometre_Start_x() |
wallsow | 2:7e718a1be318 | 58 | { |
wallsow | 2:7e718a1be318 | 59 | x = inputx; |
wallsow | 2:7e718a1be318 | 60 | serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z); |
wallsow | 2:7e718a1be318 | 61 | return x; |
jijou | 0:0e12a7930611 | 62 | } |
jijou | 0:0e12a7930611 | 63 | |
wallsow | 2:7e718a1be318 | 64 | int Accelerometre_Start_y() |
jijou | 0:0e12a7930611 | 65 | { |
jijou | 0:0e12a7930611 | 66 | y = inputy; |
wallsow | 2:7e718a1be318 | 67 | serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z); |
wallsow | 2:7e718a1be318 | 68 | return y; |
wallsow | 2:7e718a1be318 | 69 | } |
wallsow | 2:7e718a1be318 | 70 | |
wallsow | 2:7e718a1be318 | 71 | int Accelerometre_Start_z() |
wallsow | 2:7e718a1be318 | 72 | { |
jijou | 0:0e12a7930611 | 73 | z = inputz; |
jijou | 1:352fcb35e812 | 74 | serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z); |
wallsow | 2:7e718a1be318 | 75 | return z; |
jijou | 0:0e12a7930611 | 76 | } |
jijou | 0:0e12a7930611 | 77 | |
jijou | 0:0e12a7930611 | 78 | |
wallsow | 2:7e718a1be318 | 79 | |
wallsow | 3:d2c57ab99c8e | 80 | void RFID_Start() |
jijou | 0:0e12a7930611 | 81 | { |
jijou | 0:0e12a7930611 | 82 | int i; |
wallsow | 2:7e718a1be318 | 83 | int tag[15]; |
wallsow | 3:d2c57ab99c8e | 84 | //char buff[55]; |
jijou | 0:0e12a7930611 | 85 | |
jijou | 0:0e12a7930611 | 86 | for(i=0;i<5;i++) |
jijou | 0:0e12a7930611 | 87 | tag[i]=rfid.getc(); |
jijou | 0:0e12a7930611 | 88 | |
jijou | 0:0e12a7930611 | 89 | sprintf(buff,"%d%d%d%d%d",tag[0],tag[1],tag[2],tag[3],tag[4]); |
jijou | 1:352fcb35e812 | 90 | serial.printf("\r\n-----Tag RFID-----\r\n%s \r\n-----Tag RFID-----\r\n",buff); |
wallsow | 3:d2c57ab99c8e | 91 | |
jijou | 0:0e12a7930611 | 92 | } |
jijou | 0:0e12a7930611 | 93 | //--------------- |
jijou | 0:0e12a7930611 | 94 | |
jijou | 0:0e12a7930611 | 95 | int main() |
jijou | 0:0e12a7930611 | 96 | { |
jijou | 0:0e12a7930611 | 97 | //serial config |
jijou | 0:0e12a7930611 | 98 | serial.baud(9600); |
jijou | 0:0e12a7930611 | 99 | serial.format(8,SerialBase::None,1); |
jijou | 0:0e12a7930611 | 100 | |
wallsow | 3:d2c57ab99c8e | 101 | serial.printf("\r\n Bracelet Orientation\r\n****************\r\n"); |
wallsow | 2:7e718a1be318 | 102 | |
wallsow | 2:7e718a1be318 | 103 | char *p1lat, *p2lat, *p3lat; |
wallsow | 2:7e718a1be318 | 104 | int intp1lat, intp2lat, intp3lat; |
wallsow | 2:7e718a1be318 | 105 | char *p1long, *p2long, *p3long; |
wallsow | 2:7e718a1be318 | 106 | int intp1long, intp2long, intp3long; |
jijou | 0:0e12a7930611 | 107 | |
jijou | 0:0e12a7930611 | 108 | |
jijou | 0:0e12a7930611 | 109 | while(1){ |
wallsow | 2:7e718a1be318 | 110 | T=DHT_Start_Temper(); |
wallsow | 2:7e718a1be318 | 111 | H=DHT_Start_Humid(); |
wallsow | 2:7e718a1be318 | 112 | Head=Boussole_Start(); |
wallsow | 2:7e718a1be318 | 113 | /*x=Accelerometre_Start_x(); |
wallsow | 2:7e718a1be318 | 114 | y=Accelerometre_Start_y(); |
wallsow | 2:7e718a1be318 | 115 | z=Accelerometre_Start_z();*/ |
wallsow | 3:d2c57ab99c8e | 116 | //pc.printf("\rgga:%s",gga2); |
wallsow | 3:d2c57ab99c8e | 117 | parseGGA(); |
wallsow | 3:d2c57ab99c8e | 118 | getGPSstring(); |
wallsow | 3:d2c57ab99c8e | 119 | |
wallsow | 3:d2c57ab99c8e | 120 | |
wallsow | 3:d2c57ab99c8e | 121 | RFID_Start(); |
wallsow | 3:d2c57ab99c8e | 122 | RFIDA=atoi(buff); |
wallsow | 3:d2c57ab99c8e | 123 | //serial.printf("\r\n%d\r\n",RFIDA); |
wallsow | 3:d2c57ab99c8e | 124 | RFIDA=RFIDA/10000000; |
wallsow | 3:d2c57ab99c8e | 125 | //serial.printf("\r\n%d\r\n",RFIDA); |
wallsow | 2:7e718a1be318 | 126 | //---printf actoboard |
wallsow | 3:d2c57ab99c8e | 127 | serial.printf("\r\n Actooard \r\n********************************************************************\r\n"); |
wallsow | 3:d2c57ab99c8e | 128 | serial.printf("latitude : %s\r\n",lati); |
wallsow | 3:d2c57ab99c8e | 129 | serial.printf("Longitutde : %s\r\n",longi); |
wallsow | 2:7e718a1be318 | 130 | |
wallsow | 2:7e718a1be318 | 131 | |
wallsow | 2:7e718a1be318 | 132 | //traitement Latitude |
wallsow | 2:7e718a1be318 | 133 | p1lat = strtok(lati,"'"); |
wallsow | 2:7e718a1be318 | 134 | p2lat= strtok(NULL, "'");//the second |
wallsow | 2:7e718a1be318 | 135 | p3lat= strtok(NULL, ".");//the third |
wallsow | 3:d2c57ab99c8e | 136 | // serial.printf("\r%s\r\n",p1lat); |
wallsow | 3:d2c57ab99c8e | 137 | // serial.printf("\r%s\r\n",p2lat); |
wallsow | 3:d2c57ab99c8e | 138 | // serial.printf("\r%s\r\n",p3lat); //serial.printf("%s\r\n",longi); |
wallsow | 3:d2c57ab99c8e | 139 | |
wallsow | 2:7e718a1be318 | 140 | //conversion latitude |
wallsow | 2:7e718a1be318 | 141 | intp1lat=atoi(p1lat); |
wallsow | 2:7e718a1be318 | 142 | intp2lat=atoi(p2lat); |
wallsow | 2:7e718a1be318 | 143 | intp3lat=atoi(p3lat); |
wallsow | 3:d2c57ab99c8e | 144 | //concatcénation lati |
wallsow | 3:d2c57ab99c8e | 145 | int latitude_complet_int; |
wallsow | 3:d2c57ab99c8e | 146 | char latitude_complet[6]; |
wallsow | 3:d2c57ab99c8e | 147 | strcat(latitude_complet,p1lat); |
wallsow | 3:d2c57ab99c8e | 148 | strcat(latitude_complet,p2lat); |
wallsow | 3:d2c57ab99c8e | 149 | strcat(latitude_complet,p3lat); |
wallsow | 3:d2c57ab99c8e | 150 | latitude_complet_int=atoi(latitude_complet); |
wallsow | 3:d2c57ab99c8e | 151 | //serial.printf("\r\n int:%d \r\n",latitude_complet_int); |
wallsow | 3:d2c57ab99c8e | 152 | |
wallsow | 3:d2c57ab99c8e | 153 | |
wallsow | 2:7e718a1be318 | 154 | |
wallsow | 2:7e718a1be318 | 155 | //traitement longitude |
wallsow | 2:7e718a1be318 | 156 | p1long = strtok(longi,"'"); |
wallsow | 2:7e718a1be318 | 157 | p2long= strtok(NULL, "'");//the second |
wallsow | 2:7e718a1be318 | 158 | p3long= strtok(NULL, ".");//the third |
wallsow | 2:7e718a1be318 | 159 | intp1long=atoi(p1long); |
wallsow | 2:7e718a1be318 | 160 | intp2long=atoi(p2long); |
wallsow | 2:7e718a1be318 | 161 | intp3long=atoi(p3long); |
wallsow | 2:7e718a1be318 | 162 | |
wallsow | 3:d2c57ab99c8e | 163 | // serial.printf("\r%s\r\n",p1long); |
wallsow | 3:d2c57ab99c8e | 164 | // serial.printf("\r%s\r\n",p2long); |
wallsow | 3:d2c57ab99c8e | 165 | // serial.printf("\r%s\r\n",p3long); |
wallsow | 3:d2c57ab99c8e | 166 | |
wallsow | 3:d2c57ab99c8e | 167 | //concatcénation longitude |
wallsow | 3:d2c57ab99c8e | 168 | int longitude_complet_int; |
wallsow | 3:d2c57ab99c8e | 169 | char longitude_complet[6]; |
wallsow | 3:d2c57ab99c8e | 170 | strcat(longitude_complet,p1long); |
wallsow | 3:d2c57ab99c8e | 171 | strcat(longitude_complet,p2long); |
wallsow | 3:d2c57ab99c8e | 172 | strcat(longitude_complet,p3long); |
wallsow | 3:d2c57ab99c8e | 173 | longitude_complet_int=atoi(longitude_complet); |
wallsow | 3:d2c57ab99c8e | 174 | // serial.printf("\r\n int:%d \r\n",longitude_complet_int); |
wallsow | 2:7e718a1be318 | 175 | |
wallsow | 3:d2c57ab99c8e | 176 | 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);//Head |
wallsow | 2:7e718a1be318 | 177 | //serial.printf("AT$SS=%x\r\n",Head); |
wallsow | 2:7e718a1be318 | 178 | |
wallsow | 2:7e718a1be318 | 179 | |
jijou | 0:0e12a7930611 | 180 | wait(5); |
jijou | 0:0e12a7930611 | 181 | } |
jijou | 0:0e12a7930611 | 182 | } |