affichage fonctionne, valeurs reçues (255)
Dependencies: mbed
Fork of Main_V3_Old by
main.cpp@9:e79b746421b1, 2018-01-15 (annotated)
- Committer:
- Aureb29
- Date:
- Mon Jan 15 11:22:40 2018 +0000
- Revision:
- 9:e79b746421b1
- Parent:
- 8:97c8bf056a17
Main V3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ramialjed | 3:534235b99bc6 | 1 | #include "mbed.h" |
ChrisnieM | 4:784c4b53a3d4 | 2 | #include "DS18B20.h" |
ChrisnieM | 4:784c4b53a3d4 | 3 | #include "OneWireDefs.h" |
ramialjed | 3:534235b99bc6 | 4 | #include "TSL2561.h" |
ramialjed | 5:ae57f8977663 | 5 | #include "DHT22.h" |
ramialjed | 6:f552ca0f5165 | 6 | #include "bold_font.h" |
ramialjed | 6:f552ca0f5165 | 7 | #include "standard_font.h" |
ramialjed | 6:f552ca0f5165 | 8 | #include "ssd1306.h" |
ramialjed | 3:534235b99bc6 | 9 | |
ChrisnieM | 4:784c4b53a3d4 | 10 | #define THERMOMETER DS18B20 |
ChrisnieM | 4:784c4b53a3d4 | 11 | |
ChrisnieM | 4:784c4b53a3d4 | 12 | Serial serie(SERIAL_TX, SERIAL_RX); |
Aureb29 | 9:e79b746421b1 | 13 | TSL2561 LUM(PA_10, PA_9); // Luminosity pins (PA_10 -> SDA / PA_9 -> SCL) |
Aureb29 | 9:e79b746421b1 | 14 | DHT22 Tem_Hum_A(PA_11); // Temperature & Humidity of air pin |
Aureb29 | 9:e79b746421b1 | 15 | AnalogIn Humidite(PA_0); // Moisture pin |
Aureb29 | 9:e79b746421b1 | 16 | SSD1306 ecran(D3 /* cs */, D6/* reset */, A5 /* dc */, A4 /* clock */, D2 /* data */); // Display pins |
ramialjed | 6:f552ca0f5165 | 17 | //Serial PC(PA_2, PA_3); |
Aureb29 | 9:e79b746421b1 | 18 | Serial sigfox(PA_2, PA_3); // Sigfox pins (PA_2 for sigfox RX / PA_3 for sigfox TX) |
Aureb29 | 9:e79b746421b1 | 19 | DigitalOut myled(LED1); // Blink led to check program |
ramialjed | 3:534235b99bc6 | 20 | |
Aureb29 | 9:e79b746421b1 | 21 | int i, Hum_sol, Temp_sol, Lum, Temp_air, Hum_air; // variables for sensors data |
ramialjed | 5:ae57f8977663 | 22 | |
ChrisnieM | 4:784c4b53a3d4 | 23 | int main() |
ChrisnieM | 4:784c4b53a3d4 | 24 | { |
Aureb29 | 9:e79b746421b1 | 25 | /********** Display initialisation *************/ |
ramialjed | 6:f552ca0f5165 | 26 | ecran.initialise(); |
ramialjed | 6:f552ca0f5165 | 27 | ecran.clear(); |
ramialjed | 6:f552ca0f5165 | 28 | ecran.set_contrast(255); |
ramialjed | 6:f552ca0f5165 | 29 | ecran.set_font(bold_font, 8); |
ramialjed | 6:f552ca0f5165 | 30 | |
blazter94 | 8:97c8bf056a17 | 31 | serie.printf("New Program \r\n"); |
Aureb29 | 9:e79b746421b1 | 32 | /********** OneWire initialisation *************/ |
Aureb29 | 9:e79b746421b1 | 33 | THERMOMETER device(true, true, false, PA_8); // device( crcOn, useAddress, parasitic, mbed pin ) |
ChrisnieM | 4:784c4b53a3d4 | 34 | |
blazter94 | 8:97c8bf056a17 | 35 | while (!device.initialize()); // keep calling until it works |
ChrisnieM | 4:784c4b53a3d4 | 36 | |
ChrisnieM | 4:784c4b53a3d4 | 37 | while (true) |
ChrisnieM | 4:784c4b53a3d4 | 38 | { |
Aureb29 | 9:e79b746421b1 | 39 | myled = !myled; // Blink Led |
Aureb29 | 9:e79b746421b1 | 40 | Tem_Hum_A.sample(); // Launch DHT22 |
Aureb29 | 9:e79b746421b1 | 41 | device.readTemperature(); // Launch OneWire |
Aureb29 | 9:e79b746421b1 | 42 | Temp_air = (int)(Tem_Hum_A.getTemperature()/10); // Read DHT22 temperature |
Aureb29 | 9:e79b746421b1 | 43 | Hum_air = (int) (Tem_Hum_A.getHumidity()/10); // Read DHT22 humidity |
Aureb29 | 9:e79b746421b1 | 44 | Hum_sol = (int)(Humidite.read()* 100) ; // Read moisture |
Aureb29 | 9:e79b746421b1 | 45 | Temp_sol = (int)device.readTemperature(); // Read OneWire temperature |
Aureb29 | 9:e79b746421b1 | 46 | Lum = (int) LUM.lux(); // Read Luminosity |
Aureb29 | 9:e79b746421b1 | 47 | |
Aureb29 | 9:e79b746421b1 | 48 | /***************** Serial displayed data *********************/ |
Aureb29 | 9:e79b746421b1 | 49 | |
ramialjed | 6:f552ca0f5165 | 50 | printf("Temperature air: %d\n\r", Tem_Hum_A.getTemperature()/10); |
ramialjed | 6:f552ca0f5165 | 51 | printf("Hum air: %d\n\r", Tem_Hum_A.getHumidity()/10); |
ramialjed | 5:ae57f8977663 | 52 | serie.printf("\rLum: %f \r\n", LUM.lux()); |
ramialjed | 6:f552ca0f5165 | 53 | serie.printf("Temperature sol: %d \n\r",Temp_sol); |
ramialjed | 6:f552ca0f5165 | 54 | serie.printf("Hum sol: %f \n\r",Humidite.read()*100); |
ramialjed | 6:f552ca0f5165 | 55 | printf("------------------------------------------------------------\n\r"); |
Aureb29 | 9:e79b746421b1 | 56 | |
Aureb29 | 9:e79b746421b1 | 57 | /************************ Sending data on Sigfox device *********************/ |
Aureb29 | 9:e79b746421b1 | 58 | |
blazter94 | 8:97c8bf056a17 | 59 | sigfox.printf("AT$SS=%02x %02x %02x %02x %02x \r\n", Temp_sol, Temp_air, Lum, Hum_sol, Hum_air); |
blazter94 | 8:97c8bf056a17 | 60 | |
Aureb29 | 9:e79b746421b1 | 61 | /********************** OLED displayed data ********************/ |
Aureb29 | 9:e79b746421b1 | 62 | |
ramialjed | 6:f552ca0f5165 | 63 | ecran.set_font(bold_font, 8); |
ramialjed | 6:f552ca0f5165 | 64 | ecran.printf("Valeurs"); |
ramialjed | 6:f552ca0f5165 | 65 | ecran.printf("\r\n"); |
ramialjed | 6:f552ca0f5165 | 66 | ecran.update(); |
ramialjed | 6:f552ca0f5165 | 67 | ecran.set_font(standard_font, 6); |
ramialjed | 6:f552ca0f5165 | 68 | ecran.printf("Temp air = %d",Temp_air ); |
ramialjed | 6:f552ca0f5165 | 69 | ecran.printf("\r\n"); |
ramialjed | 6:f552ca0f5165 | 70 | ecran.printf("Hum air = %d", Tem_Hum_A.getHumidity()/10); |
ramialjed | 6:f552ca0f5165 | 71 | ecran.printf("\r\n"); |
ramialjed | 6:f552ca0f5165 | 72 | ecran.printf("Lum = %f", LUM.lux()); |
ramialjed | 6:f552ca0f5165 | 73 | ecran.printf("\r\n"); |
ramialjed | 6:f552ca0f5165 | 74 | ecran.printf("Temp sol = %d",Temp_sol ); |
ramialjed | 6:f552ca0f5165 | 75 | ecran.printf("\r\n"); |
blazter94 | 8:97c8bf056a17 | 76 | ecran.printf("Hum sol = %f", Humidite.read()*100); |
ramialjed | 6:f552ca0f5165 | 77 | ecran.printf("\r\n"); |
ramialjed | 6:f552ca0f5165 | 78 | ecran.update(); |
ramialjed | 6:f552ca0f5165 | 79 | ecran.clear(); |
ramialjed | 6:f552ca0f5165 | 80 | |
blazter94 | 8:97c8bf056a17 | 81 | |
blazter94 | 8:97c8bf056a17 | 82 | |
Aureb29 | 9:e79b746421b1 | 83 | wait(10); // waiting because sigfox only allows 140 sends per day |
ramialjed | 3:534235b99bc6 | 84 | } |
blazter94 | 8:97c8bf056a17 | 85 | return EXIT_SUCCESS; |
blazter94 | 8:97c8bf056a17 | 86 | } |