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: mbed OneWire DHT22 TSL2561 SSD1306
main.cpp
00001 /******************************************************* 00002 Nom ......... : main.cpp 00003 Role ........ : Récupération de données, mises en forme, 00004 des capteurs de : 00005 Luminosité, Température de l'air, 00006 Humidité de l'air, Température du sol 00007 et Huminidité du sol. 00008 Affichage dans la console et sur l'écran 00009 OLED, ainsi que envoie sur le site 00010 ACTOBOARD via module Sigfox. 00011 Auteur ...... : GEORGE Pierre, LOUVION Quentin et 00012 FAISANT Pierre-Yves 00013 Version ..... : V0 du 17/10/2017 00014 ********************************************************/ 00015 00016 #include "mbed.h" 00017 #include "OneWire.h" 00018 #include "TSL2561.h" 00019 #include "DHT22.h" 00020 #include "ssd1306.h" 00021 #include "standard_font.h" 00022 #include "bold_font.h" 00023 00024 //Déclaration variables 00025 TSL2561 Lum(PB_7,PB_6); // Luminosité (I2C:SDA,SCL) 00026 //DHT22 Tem_Hum_A(PA_11); // Température & Humidité air 00027 OneWire Tem_S(PA_8); // Température sol 00028 AnalogIn Hum_S(PA_0); // Huminidité sol 00029 Serial pc(PA_2,PA_3); //Serial : Tx,Rx 00030 SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data 00031 Serial sigfox(PA_9,PA_10,9600); // Module Sigfox 00032 LowPowerTicker t1; // Ticker pour la fonction d'interruption 00033 00034 char _id[16]; 00035 DeviceAddresses* devAddresses; 00036 uint8_t foundNum; 00037 00038 volatile uint8_t flag=1; 00039 00040 void run() 00041 { 00042 I2C i2c(PB_7,PB_6); 00043 00044 //OneWire Tem_S 00045 OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT); 00046 for (uint8_t i = 0; i < foundNum; i++) 00047 { 00048 OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]); 00049 00050 if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports 00051 continue; 00052 00053 owDevice->generateId(_id); 00054 00055 //Tem_Hum_A.sample(); 00056 00057 // Calcul sur les données envoyées par les capteurs 00058 float Lumux = Lum.lux(); 00059 //float Temp_Air = Tem_Hum_A.getTemperature()/10.0; 00060 //float Hum_Air = Tem_Hum_A.getHumidity()/10.0; 00061 float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE); 00062 float Hum_Sol = Hum_S.read(); 00063 00064 // Affichage données, mises en forme, sur la console 00065 printf( "Lum: %.2f \tTemp_A: %.2f \tHum_A: %.2f \tTemp_S: %.2f \tHum_S: %.2f\r\n", Lumux, 0, 0, Temp_Sol, Hum_Sol); 00066 00067 // Envoie données, mises en forme, sur ACTOBOARD 00068 sigfox.printf("AT$SF="); 00069 sigfox.printf("%02x%02x%02x%02x%02x",(int)Lumux,(int)0,(int)0,(int)Temp_Sol,(int)Hum_Sol); 00070 sigfox.printf("\n\r"); 00071 00072 delete owDevice; 00073 00074 SPI spi(PA_7,NC, PA_5); 00075 00076 // Affichage données, mises en forme, sur l'écran OLED 00077 wait(2); 00078 oled.set_font(bold_font, 8); 00079 oled.printf("Capteurs\r\n"); 00080 oled.printf("\r\n"); 00081 oled.set_font(standard_font, 6); 00082 oled.printf("Lum: %.2f\r\n", Lumux); 00083 oled.printf("Temp_A: %.2f\r\n", 1); 00084 oled.printf("Hum_A: %.2f\r\n", 1); 00085 oled.printf("Temp_S: %.2f\r\n",Temp_Sol); 00086 oled.printf("Hum_S: %.2f\r\n", Hum_Sol); 00087 oled.printf("\r\n"); 00088 oled.update(); 00089 } 00090 } 00091 void interruption(){ 00092 flag=1; 00093 } 00094 00095 int main() { 00096 //OneWire Tem_S 00097 I2C i2c(PB_7,PB_6); 00098 devAddresses = Tem_S.getFoundDevAddresses(); 00099 foundNum = Tem_S.getFoundDevNum(); 00100 00101 SPI spi(PA_7,NC, PA_5); 00102 00103 //OLED 00104 oled.initialise(); 00105 oled.clear(); 00106 oled.set_contrast(255); // max contrast 00107 00108 oled.set_font(bold_font, 8); 00109 oled.printf("Heading\r\n"); 00110 00111 oled.set_font(standard_font, 6); 00112 oled.printf("Hello World!\r\n"); 00113 oled.printf("Some more text here.."); 00114 00115 oled.update(); 00116 00117 t1.attach(interruption,61); 00118 00119 while(1) 00120 { 00121 if(flag) 00122 { 00123 run(); 00124 flag=0; 00125 } 00126 deepsleep(); 00127 } 00128 }
Generated on Mon Jul 18 2022 20:59:38 by
1.7.2
