GSOE Webserver ESP01 DHT11
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE
Diff: main.cpp
- Revision:
- 1:e6f838f99eeb
- Parent:
- 0:8fe7d36af056
- Child:
- 2:85f2573de3e4
--- a/main.cpp Mon Mar 17 12:35:48 2014 +0000 +++ b/main.cpp Mon Jul 26 12:23:40 2021 +0000 @@ -1,110 +1,17 @@ #include "mbed.h" - -DigitalOut LCD_RS(D8); -DigitalOut LCD_EN(D9); -DigitalOut LCD_D4(D4); -DigitalOut LCD_D5(D5); -DigitalOut LCD_D6(D6); -DigitalOut LCD_D7(D7); +#include "LCD.h" -//######################################## -// LCD Library -//######################################## - -//send data to lcd -void write_lcd(uint8_t d){ - - LCD_D4 = (d & 0x10)?1:0; - LCD_D5 = (d & 0x20)?1:0; - LCD_D6 = (d & 0x40)?1:0; - LCD_D7 = (d & 0x80)?1:0; - - wait_us(2); - LCD_EN = 1; - wait_us(2); - LCD_EN = 0; - -} - -//lcd write byte -void lcd_write_byte(uint8_t byte){ - - write_lcd(byte); - write_lcd(byte << 4); - -} - -//write command -void lcd_putcmd(uint8_t c){ - - wait_ms(5); - lcd_write_byte(c); - -} - -//write one char -void lcd_putc(uint8_t d){ - - wait_ms(1); - LCD_RS = 1; - lcd_write_byte(d); - LCD_RS = 0; - -} - - - -//print string -void lcd_puts(char * p){ - - while(* p)lcd_putc(* p++); - -} - -//lcd initial interface -void lcd_initial(void){ - - uint8_t x = 3; - - LCD_RS = 0; - LCD_EN = 0; - - LCD_D4 = 0; - LCD_D5 = 0; - LCD_D6 = 0; - LCD_D7 = 0; - - wait_ms(50); - - while(x--){ - - write_lcd(0x30); - wait_ms(5); - - } - - write_lcd(0x20); //4bit interface - - lcd_putcmd(0x28); //function set - lcd_putcmd(0x08); //display off - lcd_putcmd(0x01); //display clear - lcd_putcmd(0x06); //entry mode set - lcd_putcmd(0x0c); //display on - -} -//######################################## -// End of LCD Library -//######################################## #define DHTLIB_OK 0 #define DHTLIB_ERROR_CHECKSUM -1 #define DHTLIB_ERROR_TIMEOUT -2 Timer tmr; +lcd mylcd; -DigitalInOut data_pin(A1); +DigitalInOut data_pin(PB_15); int humidity; int temperature; @@ -128,31 +35,31 @@ // REQUEST SAMPLE data_pin.output(); data_pin.write(0); - wait_ms(18); + wait_us(18000); data_pin.write(1); wait_us(40); data_pin.input(); // ACKNOWLEDGE or TIMEOUT - unsigned int loopCnt = 10000; + unsigned int loopCnt = 20000; while(!data_pin.read())if(!loopCnt--)return DHTLIB_ERROR_TIMEOUT; - loopCnt = 10000; + loopCnt = 20000; while(data_pin.read())if(!loopCnt--)return DHTLIB_ERROR_TIMEOUT; // READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT for(int i=0; i<40; i++){ - loopCnt = 10000; + loopCnt = 20000; while(!data_pin.read())if(loopCnt-- == 0)return DHTLIB_ERROR_TIMEOUT; //unsigned long t = micros(); tmr.start(); - loopCnt = 10000; + loopCnt = 20000; while(data_pin.read())if(!loopCnt--)return DHTLIB_ERROR_TIMEOUT; @@ -191,30 +98,21 @@ int main(void){ - lcd_initial(); + mylcd.clear(); + mylcd.cursorpos(0); - lcd_puts("=Nucleo - DHT11="); + mylcd.printf("Nucleo - DHT11"); for(;;){ + int fehler=dht_read(); - if(!dht_read()){ - //sprintf(buffer, "Temp %2d C ", temperature); - //lcd_putcmd(0x80); - //lcd_puts(buffer); - sprintf(buffer, "Hum %2d%% Tmp %2dc", humidity, temperature); - lcd_putcmd(0xc0); - lcd_puts(buffer); - wait(0.5); + + mylcd.cursorpos(0x40); + mylcd.printf("Hum %2d%% Tmp %2dc ", humidity, temperature); + wait_us(500000); - }else{ - - lcd_putcmd(0x80); - lcd_puts("Sensor Error !!!"); - lcd_putcmd(0xc0); - lcd_puts(" "); - - } + }