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@8:2ba90555552e, 2017-10-17 (annotated)
- Committer:
- pgeorge
- Date:
- Tue Oct 17 08:28:14 2017 +0000
- Revision:
- 8:2ba90555552e
- Parent:
- 6:998a618b5385
- Child:
- 9:6ef06c9e2bab
fix SPI/I2C peri
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Pipou | 0:75cfe7e78e4b | 1 | #include "mbed.h" |
| pgeorge | 2:1e52e7fab454 | 2 | #include "OneWire.h" |
| pgeorge | 3:e369ee47403e | 3 | #include "TSL2561.h" |
| pgeorge | 3:e369ee47403e | 4 | #include "DHT22.h" |
| Pipou | 6:998a618b5385 | 5 | #include "ssd1306.h" |
| Pipou | 6:998a618b5385 | 6 | #include "standard_font.h" |
| Pipou | 6:998a618b5385 | 7 | #include "bold_font.h" |
| pgeorge | 3:e369ee47403e | 8 | |
| Pipou | 4:2767fb09ac47 | 9 | //Déclaration variables |
| Pipou | 4:2767fb09ac47 | 10 | TSL2561 Lum(PB_7,PB_6); // Luminosité (I2C:SDA,SCL) |
| Pipou | 4:2767fb09ac47 | 11 | DHT22 Tem_Hum_A(PA_11); // Température & Humidité air |
| Pipou | 4:2767fb09ac47 | 12 | OneWire Tem_S(PA_8); // Température sol |
| Pipou | 4:2767fb09ac47 | 13 | AnalogIn Hum_S(PA_0); // Huminidité sol |
| Pipou | 4:2767fb09ac47 | 14 | Serial pc(PA_2,PA_3); //Serial : Tx,Rx |
| Pipou | 6:998a618b5385 | 15 | SSD1306 oled(PB_0,PB_4,PB_5,PA_5,PA_7); // OLED : CS,Reset,DC,Clock,Data |
| Pipou | 0:75cfe7e78e4b | 16 | |
| Pipou | 0:75cfe7e78e4b | 17 | int main() { |
| Pipou | 4:2767fb09ac47 | 18 | //OneWire Tem_S |
| pgeorge | 8:2ba90555552e | 19 | I2C i2c(PB_7,PB_6); |
| pgeorge | 2:1e52e7fab454 | 20 | char _id[16]; |
| Pipou | 4:2767fb09ac47 | 21 | DeviceAddresses* devAddresses = Tem_S.getFoundDevAddresses(); |
| Pipou | 4:2767fb09ac47 | 22 | uint8_t foundNum = Tem_S.getFoundDevNum(); |
| Pipou | 6:998a618b5385 | 23 | |
| pgeorge | 8:2ba90555552e | 24 | SPI spi(PA_7,NC, PA_5); |
| Pipou | 6:998a618b5385 | 25 | //OLED |
| Pipou | 6:998a618b5385 | 26 | oled.initialise(); |
| Pipou | 6:998a618b5385 | 27 | oled.clear(); |
| Pipou | 6:998a618b5385 | 28 | oled.set_contrast(255); // max contrast |
| Pipou | 6:998a618b5385 | 29 | |
| Pipou | 6:998a618b5385 | 30 | oled.set_font(bold_font, 8); |
| Pipou | 6:998a618b5385 | 31 | oled.printf("Heading\r\n"); |
| Pipou | 6:998a618b5385 | 32 | |
| Pipou | 6:998a618b5385 | 33 | oled.set_font(standard_font, 6); |
| Pipou | 6:998a618b5385 | 34 | oled.printf("Hello World!\r\n"); |
| Pipou | 6:998a618b5385 | 35 | oled.printf("Some more text here.."); |
| Pipou | 6:998a618b5385 | 36 | |
| Pipou | 6:998a618b5385 | 37 | oled.update(); |
| pgeorge | 3:e369ee47403e | 38 | |
| Pipou | 0:75cfe7e78e4b | 39 | while(1) { |
| pgeorge | 8:2ba90555552e | 40 | I2C i2c(PB_7,PB_6); |
| Pipou | 4:2767fb09ac47 | 41 | OneWireDeviceTemperature::startConversationForAll(&Tem_S, OWTEMP_11_BIT); |
| pgeorge | 2:1e52e7fab454 | 42 | for (uint8_t i = 0; i < foundNum; i++) { |
| Pipou | 4:2767fb09ac47 | 43 | OneWireDevice* owDevice = OneWireDeviceFactory::init(&Tem_S, (*devAddresses)[i]); |
| pgeorge | 2:1e52e7fab454 | 44 | |
| pgeorge | 2:1e52e7fab454 | 45 | if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports |
| pgeorge | 2:1e52e7fab454 | 46 | continue; |
| pgeorge | 2:1e52e7fab454 | 47 | |
| pgeorge | 2:1e52e7fab454 | 48 | owDevice->generateId(_id); |
| pgeorge | 3:e369ee47403e | 49 | |
| pgeorge | 3:e369ee47403e | 50 | |
| Pipou | 4:2767fb09ac47 | 51 | Tem_Hum_A.sample(); |
| Pipou | 6:998a618b5385 | 52 | |
| Pipou | 6:998a618b5385 | 53 | float Lumux = Lum.lux(); |
| Pipou | 6:998a618b5385 | 54 | float Temp_Air = Tem_Hum_A.getTemperature()/10.0; |
| Pipou | 6:998a618b5385 | 55 | float Hum_Air = Tem_Hum_A.getHumidity()/10.0; |
| Pipou | 6:998a618b5385 | 56 | float Temp_Sol = owDevice->sendGetCommand(GET_TEMPERATURE); |
| Pipou | 6:998a618b5385 | 57 | float Hum_Sol = Hum_S.read(); |
| Pipou | 6:998a618b5385 | 58 | |
| Pipou | 6:998a618b5385 | 59 | 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); |
| pgeorge | 8:2ba90555552e | 60 | delete owDevice; |
| pgeorge | 8:2ba90555552e | 61 | SPI spi(PA_7,NC, PA_5); |
| Pipou | 6:998a618b5385 | 62 | wait(2); |
| Pipou | 6:998a618b5385 | 63 | oled.set_font(bold_font, 8); |
| Pipou | 6:998a618b5385 | 64 | oled.printf("Capteurs\r\n"); |
| Pipou | 6:998a618b5385 | 65 | oled.printf("\r\n"); |
| Pipou | 6:998a618b5385 | 66 | oled.set_font(standard_font, 6); |
| Pipou | 6:998a618b5385 | 67 | oled.printf("Lum: %f\r\n", Lumux); |
| Pipou | 6:998a618b5385 | 68 | oled.printf("Temp_A: %f\r\n", Temp_Air); |
| Pipou | 6:998a618b5385 | 69 | oled.printf("Hum_A: %f\r\n", Hum_Air); |
| Pipou | 6:998a618b5385 | 70 | oled.printf("Temp_S: %f\r\n",Temp_Sol); |
| Pipou | 6:998a618b5385 | 71 | oled.printf("Hum_S: %f\r\n", Hum_Sol); |
| Pipou | 6:998a618b5385 | 72 | oled.printf("\r\n"); |
| Pipou | 6:998a618b5385 | 73 | oled.update(); |
| Pipou | 4:2767fb09ac47 | 74 | } |
| Pipou | 6:998a618b5385 | 75 | //wait(5); // Frenquence : 200Hz |
| Pipou | 0:75cfe7e78e4b | 76 | } |
| Pipou | 6:998a618b5385 | 77 | |
| Pipou | 6:998a618b5385 | 78 | |
| Pipou | 0:75cfe7e78e4b | 79 | } |
