Programme d'une sonde de température DHT 11 associée à de la sauvegarde de données sur clé USB et à l'affichage de ces données sur afficheur LCD
Dependencies: FatFileSystemCpp mbed
main.cpp@0:ed0b4e66d2ad, 2015-06-02 (annotated)
- Committer:
- Fanta025
- Date:
- Tue Jun 02 14:19:54 2015 +0000
- Revision:
- 0:ed0b4e66d2ad
Programme d'une sonde de temp?rature DHT 11 associ?e ? de la sauvegarde de donn?es sur USB et un affichage sur ?cran LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Fanta025 | 0:ed0b4e66d2ad | 1 | #include "mbed.h" |
Fanta025 | 0:ed0b4e66d2ad | 2 | #include "MSCFileSystem.h" |
Fanta025 | 0:ed0b4e66d2ad | 3 | #include "DHT.h" |
Fanta025 | 0:ed0b4e66d2ad | 4 | #include "TextLCD.h" |
Fanta025 | 0:ed0b4e66d2ad | 5 | Ticker timer_5s; |
Fanta025 | 0:ed0b4e66d2ad | 6 | MSCFileSystem msc("usb"); // Mount flash drive under the name "msc" |
Fanta025 | 0:ed0b4e66d2ad | 7 | Serial pc(USBTX,USBRX); |
Fanta025 | 0:ed0b4e66d2ad | 8 | DigitalOut led(LED1); |
Fanta025 | 0:ed0b4e66d2ad | 9 | DigitalOut rw(p13); |
Fanta025 | 0:ed0b4e66d2ad | 10 | DHT sensor(p10, DHT11); |
Fanta025 | 0:ed0b4e66d2ad | 11 | TextLCD lcd(p12, p14, p15, p16, p17, p18, TextLCD::LCD16x2); |
Fanta025 | 0:ed0b4e66d2ad | 12 | |
Fanta025 | 0:ed0b4e66d2ad | 13 | |
Fanta025 | 0:ed0b4e66d2ad | 14 | void attime() |
Fanta025 | 0:ed0b4e66d2ad | 15 | { |
Fanta025 | 0:ed0b4e66d2ad | 16 | led = !led; |
Fanta025 | 0:ed0b4e66d2ad | 17 | } |
Fanta025 | 0:ed0b4e66d2ad | 18 | |
Fanta025 | 0:ed0b4e66d2ad | 19 | int main() |
Fanta025 | 0:ed0b4e66d2ad | 20 | |
Fanta025 | 0:ed0b4e66d2ad | 21 | { |
Fanta025 | 0:ed0b4e66d2ad | 22 | rw=0; |
Fanta025 | 0:ed0b4e66d2ad | 23 | led =0; |
Fanta025 | 0:ed0b4e66d2ad | 24 | unsigned char data[120*160]; // Test array of data |
Fanta025 | 0:ed0b4e66d2ad | 25 | timer_5s.attach(&attime, 10); |
Fanta025 | 0:ed0b4e66d2ad | 26 | int error = 0; |
Fanta025 | 0:ed0b4e66d2ad | 27 | //float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; |
Fanta025 | 0:ed0b4e66d2ad | 28 | float h = 0.0f, c = 0.0f; |
Fanta025 | 0:ed0b4e66d2ad | 29 | |
Fanta025 | 0:ed0b4e66d2ad | 30 | while(1) { |
Fanta025 | 0:ed0b4e66d2ad | 31 | wait(2.0f); |
Fanta025 | 0:ed0b4e66d2ad | 32 | error = sensor.readData(); |
Fanta025 | 0:ed0b4e66d2ad | 33 | if (0 == error) { |
Fanta025 | 0:ed0b4e66d2ad | 34 | c = sensor.ReadTemperature(CELCIUS); |
Fanta025 | 0:ed0b4e66d2ad | 35 | h = sensor.ReadHumidity(); |
Fanta025 | 0:ed0b4e66d2ad | 36 | lcd.locate(0,0); |
Fanta025 | 0:ed0b4e66d2ad | 37 | lcd.printf("Temp : %4.2f\n", c); |
Fanta025 | 0:ed0b4e66d2ad | 38 | lcd.locate(0,1); |
Fanta025 | 0:ed0b4e66d2ad | 39 | lcd.printf("Humid : %4.2f\n", h); |
Fanta025 | 0:ed0b4e66d2ad | 40 | // lcd.printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); |
Fanta025 | 0:ed0b4e66d2ad | 41 | } else { |
Fanta025 | 0:ed0b4e66d2ad | 42 | lcd.printf("Error: %d\n", error); |
Fanta025 | 0:ed0b4e66d2ad | 43 | } |
Fanta025 | 0:ed0b4e66d2ad | 44 | if (led==1) { |
Fanta025 | 0:ed0b4e66d2ad | 45 | wait(0.2); |
Fanta025 | 0:ed0b4e66d2ad | 46 | // Fill the data with values |
Fanta025 | 0:ed0b4e66d2ad | 47 | for (int i=0; i<120*160; i++) { |
Fanta025 | 0:ed0b4e66d2ad | 48 | data[i] = 0xAA; // Fill array with data |
Fanta025 | 0:ed0b4e66d2ad | 49 | } |
Fanta025 | 0:ed0b4e66d2ad | 50 | |
Fanta025 | 0:ed0b4e66d2ad | 51 | // Create timers |
Fanta025 | 0:ed0b4e66d2ad | 52 | // Timer Write_time, Read_time; |
Fanta025 | 0:ed0b4e66d2ad | 53 | // Write_time.start(); |
Fanta025 | 0:ed0b4e66d2ad | 54 | |
Fanta025 | 0:ed0b4e66d2ad | 55 | // Write to local file |
Fanta025 | 0:ed0b4e66d2ad | 56 | FILE *fp = fopen( "/usb/Mesures.txt", "a"); |
Fanta025 | 0:ed0b4e66d2ad | 57 | |
Fanta025 | 0:ed0b4e66d2ad | 58 | for (int i=0; i<1; i++) { |
Fanta025 | 0:ed0b4e66d2ad | 59 | //fprintf(fp, "%c",data[i]); |
Fanta025 | 0:ed0b4e66d2ad | 60 | |
Fanta025 | 0:ed0b4e66d2ad | 61 | fprintf(fp, "Temp : %4.2f\n - ",c,data[0]); |
Fanta025 | 0:ed0b4e66d2ad | 62 | fprintf(fp, "Humid : %4.2f\n\r\n", h,data[0]); |
Fanta025 | 0:ed0b4e66d2ad | 63 | } |
Fanta025 | 0:ed0b4e66d2ad | 64 | |
Fanta025 | 0:ed0b4e66d2ad | 65 | fclose(fp); |
Fanta025 | 0:ed0b4e66d2ad | 66 | led=0; |
Fanta025 | 0:ed0b4e66d2ad | 67 | } |
Fanta025 | 0:ed0b4e66d2ad | 68 | |
Fanta025 | 0:ed0b4e66d2ad | 69 | } |
Fanta025 | 0:ed0b4e66d2ad | 70 | // Write_time.stop(); |
Fanta025 | 0:ed0b4e66d2ad | 71 | // pc.printf("\n\rTime taken so write array = %f seconds",Write_time.read()); |
Fanta025 | 0:ed0b4e66d2ad | 72 | |
Fanta025 | 0:ed0b4e66d2ad | 73 | |
Fanta025 | 0:ed0b4e66d2ad | 74 | } |