Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL345 DHT HMC5883L SerialGPS mbed
main.cpp
00001 #include "mbed.h" 00002 #include "HMC5883L.h" 00003 #include "DHT.h" 00004 #include "ADXL345.h" 00005 #include "SerialGPS.h" 00006 00007 SerialGPS gps(D1, D0); 00008 DHT sensor(D7, DHT22); 00009 Serial pc(D8, PA_10); // tx, rx 00010 // Utility Boussole HMC5883L 00011 #ifndef M_PI 00012 #define M_PI 3.1415926535897932384626433832795 00013 #endif 00014 #define PI2 (2*M_PI) 00015 #define RAD_TO_DEG (180.0/M_PI) 00016 #define DEG_TO_RAD (M_PI/180.0) 00017 #define DECLINATION_ANGLE -0.02123 00018 #define SDA A4 00019 #define SCL A5 00020 00021 int main() 00022 { 00023 // varible Boussole HMC5883L 00024 double heading; 00025 float x, y, z; 00026 HMC5883L hmc5883l(SDA, SCL); 00027 // variable DHT11 /////////////////////////// 00028 float temp,Humidity; 00029 int err; 00030 // configuration GPS ////////////////////////////////////////// 00031 SerialGPS::gps_gga_t *p; 00032 int Hour, Min, Sec, Pos, Sat; 00033 double Latitude, Longitude; 00034 00035 while(1) 00036 { 00037 //////////////////////////////////////////////////////////////////////////////// 00038 ////////////////////////// aquisation de la boussole /////////////////////////// 00039 //////////////////////////////////////////////////////////////////////////////// 00040 x = hmc5883l.getMx(); 00041 y = hmc5883l.getMy(); 00042 z = hmc5883l.getMz(); 00043 pc.printf("x, y, z: %f, %f,%f \r\n",x,y,z); 00044 heading = atan2(static_cast<double>(y), static_cast<double>(x)); // heading = arctan(Y/X) 00045 heading += DECLINATION_ANGLE; 00046 if(heading < 0.0) // fix sign 00047 heading += PI2; 00048 if(heading > PI2) // fix overflow 00049 heading -= PI2; 00050 pc.printf("heading:%f\r\n",heading); 00051 pc.printf("*********************\r\n"); 00052 //////////////////////////////////////////////////////////////////////////////// 00053 ////////////////////////// aquisation du capteur de température///////////////// 00054 //////////////////////////////////////////////////////////////////////////////// 00055 err = sensor.readData(); 00056 if (err==0){ 00057 temp=sensor.ReadTemperature(CELCIUS); 00058 Humidity=sensor.ReadHumidity(); 00059 pc.printf(" temp / hem =%f, %f\r\n",temp,Humidity); 00060 } 00061 pc.printf("*********************\r\n"); 00062 //////////////////////////////////////////////////////////////////////////////// 00063 ////////////////////////// aquisation gps ////////////::::::::::::::://///////// 00064 //////////////////////////////////////////////////////////////////////////////// 00065 gps.processing(); 00066 Hour= p->hour; 00067 Min = p->min; 00068 Sec = p->sec; 00069 Pos = p->position_fix; 00070 Sat = p->satellites_used; 00071 Latitude = p->latitude; 00072 Longitude= p->longitude; 00073 pc.printf("gps= %d, %d \r\n",Latitude,Longitude); 00074 pc.printf("hour= %i \r\n",Hour); 00075 pc.printf("min= %i \r\n",Sec); 00076 pc.printf("position_fix= %i \r\n",Pos); 00077 pc.printf("*********************\r\n"); 00078 00079 wait(10); 00080 } 00081 }
Generated on Sat Jul 16 2022 01:56:57 by
1.7.2