projet en 1 main.cpp

Dependencies:   DHT11 HMC5883L

Committer:
wallsow
Date:
Fri Jan 27 22:47:35 2017 +0000
Revision:
2:7e718a1be318
Parent:
1:352fcb35e812
Child:
3:d2c57ab99c8e
projet long + acto

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
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;
jijou 0:0e12a7930611 24
wallsow 2:7e718a1be318 25 int DHT_Start_Temper()
jijou 0:0e12a7930611 26 {
wallsow 2:7e718a1be318 27 s = sensor.readData();
wallsow 2:7e718a1be318 28 T=sensor.readTemperature();/*
jijou 0:0e12a7930611 29 if (s != DHT11::OK) {
jijou 0:0e12a7930611 30 serial.printf("Error!\r\n");
jijou 0:0e12a7930611 31 }
jijou 0:0e12a7930611 32 else {
wallsow 2:7e718a1be318 33 serial.printf("AT$SS=%x%x\r\n", T,H);
wallsow 2:7e718a1be318 34 }*/
wallsow 2:7e718a1be318 35 return T;
wallsow 2:7e718a1be318 36 }
wallsow 2:7e718a1be318 37
wallsow 2:7e718a1be318 38 int DHT_Start_Humid()
wallsow 2:7e718a1be318 39 {
wallsow 2:7e718a1be318 40 s = sensor.readData();
wallsow 2:7e718a1be318 41 H=sensor.readHumidity();
wallsow 2:7e718a1be318 42 return H;
jijou 0:0e12a7930611 43 }
jijou 0:0e12a7930611 44
jijou 0:0e12a7930611 45
wallsow 2:7e718a1be318 46 int Boussole_Start()
jijou 0:0e12a7930611 47 {
jijou 0:0e12a7930611 48 bouss.init();
wallsow 2:7e718a1be318 49 Boussole= bouss.getHeadingXYDeg();
wallsow 2:7e718a1be318 50 Head=((int)Boussole)/2;
wallsow 2:7e718a1be318 51 serial.printf("\r\n-----Boussole-----\r\n%2f\r\n-----Boussole-----\r\n",Boussole);
wallsow 2:7e718a1be318 52 return Head;
wallsow 2:7e718a1be318 53 }
wallsow 2:7e718a1be318 54
wallsow 2:7e718a1be318 55 int Accelerometre_Start_x()
wallsow 2:7e718a1be318 56 {
wallsow 2:7e718a1be318 57 x = inputx;
wallsow 2:7e718a1be318 58 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 59 return x;
jijou 0:0e12a7930611 60 }
jijou 0:0e12a7930611 61
wallsow 2:7e718a1be318 62 int Accelerometre_Start_y()
jijou 0:0e12a7930611 63 {
jijou 0:0e12a7930611 64 y = inputy;
wallsow 2:7e718a1be318 65 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 66 return y;
wallsow 2:7e718a1be318 67 }
wallsow 2:7e718a1be318 68
wallsow 2:7e718a1be318 69 int Accelerometre_Start_z()
wallsow 2:7e718a1be318 70 {
jijou 0:0e12a7930611 71 z = inputz;
jijou 1:352fcb35e812 72 serial.printf("\r\n-----Accelerometre-----\r\nX:%f,Y: %f,Z: %f \r\n-----Accelerometre-----\r\n",x,y,z);
wallsow 2:7e718a1be318 73 return z;
jijou 0:0e12a7930611 74 }
jijou 0:0e12a7930611 75
jijou 0:0e12a7930611 76
wallsow 2:7e718a1be318 77
wallsow 2:7e718a1be318 78
wallsow 2:7e718a1be318 79 int RFID_Start(int t0,int t1,int t2,int t3,int t4)
jijou 0:0e12a7930611 80 {
jijou 0:0e12a7930611 81 int i;
wallsow 2:7e718a1be318 82 int tag[15];
jijou 0:0e12a7930611 83 char buff[55];
jijou 0:0e12a7930611 84
jijou 0:0e12a7930611 85 for(i=0;i<5;i++)
jijou 0:0e12a7930611 86 tag[i]=rfid.getc();
jijou 0:0e12a7930611 87
jijou 0:0e12a7930611 88 sprintf(buff,"%d%d%d%d%d",tag[0],tag[1],tag[2],tag[3],tag[4]);
jijou 1:352fcb35e812 89 serial.printf("\r\n-----Tag RFID-----\r\n%s \r\n-----Tag RFID-----\r\n",buff);
wallsow 2:7e718a1be318 90 t0=tag[0];
wallsow 2:7e718a1be318 91 t1=tag[1];
wallsow 2:7e718a1be318 92 t2=tag[2];
wallsow 2:7e718a1be318 93 t3=tag[3];
wallsow 2:7e718a1be318 94 t4=tag[4];
jijou 0:0e12a7930611 95 }
jijou 0:0e12a7930611 96 //---------------
jijou 0:0e12a7930611 97
jijou 0:0e12a7930611 98 int main()
jijou 0:0e12a7930611 99 {
jijou 0:0e12a7930611 100 //serial config
wallsow 2:7e718a1be318 101 int t0,t1,t2,t3,t4;
jijou 0:0e12a7930611 102 serial.baud(9600);
jijou 0:0e12a7930611 103 serial.format(8,SerialBase::None,1);
jijou 0:0e12a7930611 104
jijou 0:0e12a7930611 105 serial.printf("\r\n Test program\r\n****************\r\n");
wallsow 2:7e718a1be318 106
wallsow 2:7e718a1be318 107 char *p1lat, *p2lat, *p3lat;
wallsow 2:7e718a1be318 108 int intp1lat, intp2lat, intp3lat;
wallsow 2:7e718a1be318 109 char *p1long, *p2long, *p3long;
wallsow 2:7e718a1be318 110 int intp1long, intp2long, intp3long;
jijou 0:0e12a7930611 111
jijou 0:0e12a7930611 112
jijou 0:0e12a7930611 113 while(1){
wallsow 2:7e718a1be318 114 T=DHT_Start_Temper();
wallsow 2:7e718a1be318 115 H=DHT_Start_Humid();
wallsow 2:7e718a1be318 116 Head=Boussole_Start();
wallsow 2:7e718a1be318 117 /*x=Accelerometre_Start_x();
wallsow 2:7e718a1be318 118 y=Accelerometre_Start_y();
wallsow 2:7e718a1be318 119 z=Accelerometre_Start_z();*/
jijou 0:0e12a7930611 120 getGPSstring(1);
wallsow 2:7e718a1be318 121 RFID_Start(t0,t1,t2,t3,t4);
wallsow 2:7e718a1be318 122 //---printf actoboard
wallsow 2:7e718a1be318 123 serial.printf("\r\n Test Actooard\r\n****************\r\n");
wallsow 2:7e718a1be318 124 serial.printf("%s\r\n",lati);
wallsow 2:7e718a1be318 125 serial.printf("%s\r\n",longi);
wallsow 2:7e718a1be318 126
wallsow 2:7e718a1be318 127
wallsow 2:7e718a1be318 128 //traitement Latitude
wallsow 2:7e718a1be318 129 p1lat = strtok(lati,"'");
wallsow 2:7e718a1be318 130 p2lat= strtok(NULL, "'");//the second
wallsow 2:7e718a1be318 131 p3lat= strtok(NULL, ".");//the third
wallsow 2:7e718a1be318 132 serial.printf("\r%s\r\n",p1lat);
wallsow 2:7e718a1be318 133 serial.printf("\r%s\r\n",p2lat);
wallsow 2:7e718a1be318 134 serial.printf("\r%s\r\n",p3lat); //serial.printf("%s\r\n",longi);
wallsow 2:7e718a1be318 135 //conversion latitude
wallsow 2:7e718a1be318 136 intp1lat=atoi(p1lat);
wallsow 2:7e718a1be318 137 intp2lat=atoi(p2lat);
wallsow 2:7e718a1be318 138 intp3lat=atoi(p3lat);
wallsow 2:7e718a1be318 139
wallsow 2:7e718a1be318 140 //traitement longitude
wallsow 2:7e718a1be318 141 p1long = strtok(longi,"'");
wallsow 2:7e718a1be318 142 p2long= strtok(NULL, "'");//the second
wallsow 2:7e718a1be318 143 p3long= strtok(NULL, ".");//the third
wallsow 2:7e718a1be318 144 intp1long=atoi(p1long);
wallsow 2:7e718a1be318 145 intp2long=atoi(p2long);
wallsow 2:7e718a1be318 146 intp3long=atoi(p3long);
wallsow 2:7e718a1be318 147
wallsow 2:7e718a1be318 148 serial.printf("\r%s\r\n",p1long);
wallsow 2:7e718a1be318 149 serial.printf("\r%s\r\n",p2long);
wallsow 2:7e718a1be318 150 serial.printf("\r%s\r\n",p3long);
wallsow 2:7e718a1be318 151
wallsow 2:7e718a1be318 152 serial.printf("AT$SS=%x%x%x%x%x0%x%x%x\r\n",T,H,intp1lat,intp2lat,intp3lat,intp1long,intp2long,intp3long);//Head
wallsow 2:7e718a1be318 153 //serial.printf("AT$SS=%x\r\n",Head);
wallsow 2:7e718a1be318 154
wallsow 2:7e718a1be318 155
jijou 0:0e12a7930611 156 wait(5);
jijou 0:0e12a7930611 157 }
jijou 0:0e12a7930611 158 }