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
Diff: main.cpp
- Revision:
- 9:6ef06c9e2bab
- Parent:
- 8:2ba90555552e
- Child:
- 10:fd7b1648642d
diff -r 2ba90555552e -r 6ef06c9e2bab main.cpp
--- a/main.cpp Tue Oct 17 08:28:14 2017 +0000
+++ b/main.cpp Tue Oct 17 10:17:55 2017 +0000
@@ -1,3 +1,18 @@
+/*******************************************************
+Nom ......... : main.cpp
+Role ........ : Récupération de données, mises en forme,
+ des capteurs de :
+ Luminosité, Température de l'air,
+ Humidité de l'air, Température du sol
+ et Huminidité du sol.
+ Affichage dans la console et sur l'écran
+ OLED, ainsi que envoie sur le site
+ ACTOBOARD via module Sigfox.
+Auteur ...... : GEORGE Pierre, LOUVION Quentin et
+ FAISANT Pierre-Yves
+Version ..... : V0 du 17/10/2017
+********************************************************/
+
#include "mbed.h"
#include "OneWire.h"
#include "TSL2561.h"
@@ -13,15 +28,73 @@
AnalogIn Hum_S(PA_0); // Huminidité sol
Serial pc(PA_2,PA_3); //Serial : Tx,Rx
SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data
+Serial sigfox(PA_9,PA_10,9600); // Module Sigfox
+LowPowerTicker t1; // Ticker pour la fonction d'interruption
+
+char _id[16];
+DeviceAddresses* devAddresses;
+uint8_t foundNum;
+
+void interruption()
+{
+ I2C i2c(PB_7,PB_6);
+
+ //OneWire Tem_S
+ OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT);
+ for (uint8_t i = 0; i < foundNum; i++)
+ {
+ OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]);
+
+ if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports
+ continue;
+
+ owDevice->generateId(_id);
+
+ Tem_Hum_A.sample();
+
+ // Calcul sur les données envoyées par les capteurs
+ float Lumux = Lum.lux();
+ float Temp_Air = Tem_Hum_A.getTemperature()/10.0;
+ float Hum_Air = Tem_Hum_A.getHumidity()/10.0;
+ float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE);
+ float Hum_Sol = Hum_S.read();
+
+ // Affichage données, mises en forme, sur la console
+ printf( "Lum: %f \tTemp_A: %f \tHum_A: %f \tTemp_S: %f \tHum_S: %f\r\n", Lumux, Temp_Air, Hum_Air, Temp_Sol, Hum_Sol);
+
+ // Envoie données, mises en forme, sur ACTOBOARD
+ sigfox.printf("AT$SF=");
+ sigfox.printf("%04x%04x",Temp_Air,Hum_Air);
+ sigfox.printf("\n\r");
+
+ delete owDevice;
+
+ SPI spi(PA_7,NC, PA_5);
+
+ // Affichage données, mises en forme, sur l'écran OLED
+ wait(2);
+ oled.set_font(bold_font, 8);
+ oled.printf("Capteurs\r\n");
+ oled.printf("\r\n");
+ oled.set_font(standard_font, 6);
+ oled.printf("Lum: %f\r\n", Lumux);
+ oled.printf("Temp_A: %f\r\n", Temp_Air);
+ oled.printf("Hum_A: %f\r\n", Hum_Air);
+ oled.printf("Temp_S: %f\r\n",Temp_Sol);
+ oled.printf("Hum_S: %f\r\n", Hum_Sol);
+ oled.printf("\r\n");
+ oled.update();
+ }
+}
int main() {
//OneWire Tem_S
I2C i2c(PB_7,PB_6);
- char _id[16];
- DeviceAddresses* devAddresses = Tem_S.getFoundDevAddresses();
- uint8_t foundNum = Tem_S.getFoundDevNum();
+ devAddresses = Tem_S.getFoundDevAddresses();
+ foundNum = Tem_S.getFoundDevNum();
SPI spi(PA_7,NC, PA_5);
+
//OLED
oled.initialise();
oled.clear();
@@ -35,45 +108,11 @@
oled.printf("Some more text here..");
oled.update();
-
- while(1) {
- I2C i2c(PB_7,PB_6);
- OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT);
- for (uint8_t i = 0; i < foundNum; i++) {
- OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]);
-
- if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports
- continue;
-
- owDevice->generateId(_id);
-
-
- Tem_Hum_A.sample();
-
- float Lumux = Lum.lux();
- float Temp_Air = Tem_Hum_A.getTemperature()/10.0;
- float Hum_Air = Tem_Hum_A.getHumidity()/10.0;
- float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE);
- float Hum_Sol = Hum_S.read();
-
- printf( "Lum: %f \tTemp_A: %f \tHum_A: %f \tTemp_S: %f \tHum_S: %f\r\n", Lumux, Temp_Air, Hum_Air, Temp_Sol, Hum_Sol);
- delete owDevice;
- SPI spi(PA_7,NC, PA_5);
- wait(2);
- oled.set_font(bold_font, 8);
- oled.printf("Capteurs\r\n");
- oled.printf("\r\n");
- oled.set_font(standard_font, 6);
- oled.printf("Lum: %f\r\n", Lumux);
- oled.printf("Temp_A: %f\r\n", Temp_Air);
- oled.printf("Hum_A: %f\r\n", Hum_Air);
- oled.printf("Temp_S: %f\r\n",Temp_Sol);
- oled.printf("Hum_S: %f\r\n", Hum_Sol);
- oled.printf("\r\n");
- oled.update();
- }
- //wait(5); // Frenquence : 200Hz
+
+ t1.attach(interruption,60);
+
+ while(1)
+ {
+ deepsleep();
}
-
-
}
