
Projet Long pour AGRAL
Dependencies: mbed OneWire DHT22 TSL2561 SSD1306
main.cpp@11:7c872ac9da9a, 2017-11-20 (annotated)
- Committer:
- Pipou
- Date:
- Mon Nov 20 15:33:30 2017 +0000
- Revision:
- 11:7c872ac9da9a
- Parent:
- 10:fd7b1648642d
- Child:
- 12:df4ff058ab06
- Child:
- 13:9a8b32c34787
Sigfox 5 valeurs, fix affichage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pipou | 9:6ef06c9e2bab | 1 | /******************************************************* |
Pipou | 9:6ef06c9e2bab | 2 | Nom ......... : main.cpp |
Pipou | 9:6ef06c9e2bab | 3 | Role ........ : Récupération de données, mises en forme, |
Pipou | 9:6ef06c9e2bab | 4 | des capteurs de : |
Pipou | 9:6ef06c9e2bab | 5 | Luminosité, Température de l'air, |
Pipou | 9:6ef06c9e2bab | 6 | Humidité de l'air, Température du sol |
Pipou | 9:6ef06c9e2bab | 7 | et Huminidité du sol. |
Pipou | 9:6ef06c9e2bab | 8 | Affichage dans la console et sur l'écran |
Pipou | 9:6ef06c9e2bab | 9 | OLED, ainsi que envoie sur le site |
Pipou | 9:6ef06c9e2bab | 10 | ACTOBOARD via module Sigfox. |
Pipou | 9:6ef06c9e2bab | 11 | Auteur ...... : GEORGE Pierre, LOUVION Quentin et |
Pipou | 9:6ef06c9e2bab | 12 | FAISANT Pierre-Yves |
Pipou | 9:6ef06c9e2bab | 13 | Version ..... : V0 du 17/10/2017 |
Pipou | 9:6ef06c9e2bab | 14 | ********************************************************/ |
Pipou | 9:6ef06c9e2bab | 15 | |
Pipou | 0:75cfe7e78e4b | 16 | #include "mbed.h" |
pgeorge | 2:1e52e7fab454 | 17 | #include "OneWire.h" |
pgeorge | 3:e369ee47403e | 18 | #include "TSL2561.h" |
pgeorge | 3:e369ee47403e | 19 | #include "DHT22.h" |
Pipou | 6:998a618b5385 | 20 | #include "ssd1306.h" |
Pipou | 6:998a618b5385 | 21 | #include "standard_font.h" |
Pipou | 6:998a618b5385 | 22 | #include "bold_font.h" |
pgeorge | 3:e369ee47403e | 23 | |
Pipou | 4:2767fb09ac47 | 24 | //Déclaration variables |
Pipou | 4:2767fb09ac47 | 25 | TSL2561 Lum(PB_7,PB_6); // Luminosité (I2C:SDA,SCL) |
Pipou | 4:2767fb09ac47 | 26 | DHT22 Tem_Hum_A(PA_11); // Température & Humidité air |
Pipou | 4:2767fb09ac47 | 27 | OneWire Tem_S(PA_8); // Température sol |
Pipou | 4:2767fb09ac47 | 28 | AnalogIn Hum_S(PA_0); // Huminidité sol |
Pipou | 4:2767fb09ac47 | 29 | Serial pc(PA_2,PA_3); //Serial : Tx,Rx |
Pipou | 6:998a618b5385 | 30 | SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data |
Pipou | 9:6ef06c9e2bab | 31 | Serial sigfox(PA_9,PA_10,9600); // Module Sigfox |
Pipou | 9:6ef06c9e2bab | 32 | LowPowerTicker t1; // Ticker pour la fonction d'interruption |
Pipou | 9:6ef06c9e2bab | 33 | |
Pipou | 9:6ef06c9e2bab | 34 | char _id[16]; |
Pipou | 9:6ef06c9e2bab | 35 | DeviceAddresses* devAddresses; |
Pipou | 9:6ef06c9e2bab | 36 | uint8_t foundNum; |
Pipou | 9:6ef06c9e2bab | 37 | |
Pipou | 10:fd7b1648642d | 38 | volatile uint8_t flag=1; |
Pipou | 10:fd7b1648642d | 39 | |
Pipou | 10:fd7b1648642d | 40 | void run() |
Pipou | 9:6ef06c9e2bab | 41 | { |
Pipou | 9:6ef06c9e2bab | 42 | I2C i2c(PB_7,PB_6); |
Pipou | 9:6ef06c9e2bab | 43 | |
Pipou | 9:6ef06c9e2bab | 44 | //OneWire Tem_S |
Pipou | 9:6ef06c9e2bab | 45 | OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT); |
Pipou | 9:6ef06c9e2bab | 46 | for (uint8_t i = 0; i < foundNum; i++) |
Pipou | 9:6ef06c9e2bab | 47 | { |
Pipou | 9:6ef06c9e2bab | 48 | OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]); |
Pipou | 9:6ef06c9e2bab | 49 | |
Pipou | 9:6ef06c9e2bab | 50 | if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports |
Pipou | 9:6ef06c9e2bab | 51 | continue; |
Pipou | 9:6ef06c9e2bab | 52 | |
Pipou | 9:6ef06c9e2bab | 53 | owDevice->generateId(_id); |
Pipou | 9:6ef06c9e2bab | 54 | |
Pipou | 9:6ef06c9e2bab | 55 | Tem_Hum_A.sample(); |
Pipou | 10:fd7b1648642d | 56 | |
Pipou | 9:6ef06c9e2bab | 57 | // Calcul sur les données envoyées par les capteurs |
Pipou | 9:6ef06c9e2bab | 58 | float Lumux = Lum.lux(); |
Pipou | 9:6ef06c9e2bab | 59 | float Temp_Air = Tem_Hum_A.getTemperature()/10.0; |
Pipou | 9:6ef06c9e2bab | 60 | float Hum_Air = Tem_Hum_A.getHumidity()/10.0; |
Pipou | 9:6ef06c9e2bab | 61 | float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE); |
Pipou | 9:6ef06c9e2bab | 62 | float Hum_Sol = Hum_S.read(); |
Pipou | 9:6ef06c9e2bab | 63 | |
Pipou | 9:6ef06c9e2bab | 64 | // Affichage données, mises en forme, sur la console |
Pipou | 11:7c872ac9da9a | 65 | printf( "Lum: %.2f \tTemp_A: %.2f \tHum_A: %.2f \tTemp_S: %.2f \tHum_S: %.2f\r\n", Lumux, Temp_Air, Hum_Air, Temp_Sol, Hum_Sol); |
Pipou | 9:6ef06c9e2bab | 66 | |
Pipou | 9:6ef06c9e2bab | 67 | // Envoie données, mises en forme, sur ACTOBOARD |
Pipou | 9:6ef06c9e2bab | 68 | sigfox.printf("AT$SF="); |
Pipou | 11:7c872ac9da9a | 69 | sigfox.printf("%02x%02x%02x%02x%02x",(int)Lumux,(int)Temp_Air,(int)Hum_Air,(int)Temp_Sol,(int)Hum_Sol); |
Pipou | 9:6ef06c9e2bab | 70 | sigfox.printf("\n\r"); |
Pipou | 9:6ef06c9e2bab | 71 | |
Pipou | 9:6ef06c9e2bab | 72 | delete owDevice; |
Pipou | 9:6ef06c9e2bab | 73 | |
Pipou | 9:6ef06c9e2bab | 74 | SPI spi(PA_7,NC, PA_5); |
Pipou | 9:6ef06c9e2bab | 75 | |
Pipou | 9:6ef06c9e2bab | 76 | // Affichage données, mises en forme, sur l'écran OLED |
Pipou | 9:6ef06c9e2bab | 77 | wait(2); |
Pipou | 9:6ef06c9e2bab | 78 | oled.set_font(bold_font, 8); |
Pipou | 9:6ef06c9e2bab | 79 | oled.printf("Capteurs\r\n"); |
Pipou | 9:6ef06c9e2bab | 80 | oled.printf("\r\n"); |
Pipou | 9:6ef06c9e2bab | 81 | oled.set_font(standard_font, 6); |
Pipou | 11:7c872ac9da9a | 82 | oled.printf("Lum: %.2f\r\n", Lumux); |
Pipou | 11:7c872ac9da9a | 83 | oled.printf("Temp_A: %.2f\r\n", Temp_Air); |
Pipou | 11:7c872ac9da9a | 84 | oled.printf("Hum_A: %.2f\r\n", Hum_Air); |
Pipou | 11:7c872ac9da9a | 85 | oled.printf("Temp_S: %.2f\r\n",Temp_Sol); |
Pipou | 11:7c872ac9da9a | 86 | oled.printf("Hum_S: %.2f\r\n", Hum_Sol); |
Pipou | 9:6ef06c9e2bab | 87 | oled.printf("\r\n"); |
Pipou | 9:6ef06c9e2bab | 88 | oled.update(); |
Pipou | 9:6ef06c9e2bab | 89 | } |
Pipou | 9:6ef06c9e2bab | 90 | } |
Pipou | 10:fd7b1648642d | 91 | void interruption(){ |
Pipou | 10:fd7b1648642d | 92 | flag=1; |
Pipou | 10:fd7b1648642d | 93 | } |
Pipou | 10:fd7b1648642d | 94 | |
Pipou | 0:75cfe7e78e4b | 95 | int main() { |
Pipou | 4:2767fb09ac47 | 96 | //OneWire Tem_S |
pgeorge | 8:2ba90555552e | 97 | I2C i2c(PB_7,PB_6); |
Pipou | 9:6ef06c9e2bab | 98 | devAddresses = Tem_S.getFoundDevAddresses(); |
Pipou | 9:6ef06c9e2bab | 99 | foundNum = Tem_S.getFoundDevNum(); |
Pipou | 6:998a618b5385 | 100 | |
pgeorge | 8:2ba90555552e | 101 | SPI spi(PA_7,NC, PA_5); |
Pipou | 9:6ef06c9e2bab | 102 | |
Pipou | 6:998a618b5385 | 103 | //OLED |
Pipou | 6:998a618b5385 | 104 | oled.initialise(); |
Pipou | 6:998a618b5385 | 105 | oled.clear(); |
Pipou | 6:998a618b5385 | 106 | oled.set_contrast(255); // max contrast |
Pipou | 6:998a618b5385 | 107 | |
Pipou | 6:998a618b5385 | 108 | oled.set_font(bold_font, 8); |
Pipou | 6:998a618b5385 | 109 | oled.printf("Heading\r\n"); |
Pipou | 6:998a618b5385 | 110 | |
Pipou | 6:998a618b5385 | 111 | oled.set_font(standard_font, 6); |
Pipou | 6:998a618b5385 | 112 | oled.printf("Hello World!\r\n"); |
Pipou | 6:998a618b5385 | 113 | oled.printf("Some more text here.."); |
Pipou | 6:998a618b5385 | 114 | |
Pipou | 6:998a618b5385 | 115 | oled.update(); |
Pipou | 9:6ef06c9e2bab | 116 | |
Pipou | 10:fd7b1648642d | 117 | t1.attach(interruption,61); |
Pipou | 9:6ef06c9e2bab | 118 | |
Pipou | 9:6ef06c9e2bab | 119 | while(1) |
Pipou | 9:6ef06c9e2bab | 120 | { |
Pipou | 10:fd7b1648642d | 121 | if(flag) |
Pipou | 10:fd7b1648642d | 122 | { |
Pipou | 10:fd7b1648642d | 123 | run(); |
Pipou | 10:fd7b1648642d | 124 | flag=0; |
Pipou | 10:fd7b1648642d | 125 | } |
Pipou | 9:6ef06c9e2bab | 126 | deepsleep(); |
Pipou | 0:75cfe7e78e4b | 127 | } |
Pipou | 0:75cfe7e78e4b | 128 | } |