blog.ijacek007.cz

Blog o všem trochu jinak.

V minulém článku jsem psal o projektu počítadla, ve kterém jsem použil ESP32 desku s LCD displejem. V dnešním příkladu Vám ukáži, jak pomocí méně výkonné destičky s čipem ESP8266 vytvořit Wi-Fi teploměr s vlhkostí a indikátorem signálu.

Ve svém domě používám několik čipů ESP8266 pro měření teplot. O zapojení jsem psal v článku Teploměr s ESP8266 s indikací připojení k Wi-Fi síti. Toto je vhodné všude tam, kde chcete zjišťovat teplotu ale nepotřebujete o ní mít v místě měření přehled. Co ale když chcete teplotu zaznamenávat a zároveň mít aktuální hodnoty na očích? Zde pomůže destička s ESP8266 a integrovaným 0,9 palcovým LCD displejem. Celé zapojení pak doplňuje teplotní a vlhkostní čídlo DHT22.


zapojení desky

Protože hodnoty stále sbírám na straně serveru, je webová stránka stejná jako v případě samotných starších teploměrů. Zároveň se ale údaje o teplotě zobrazují také na integrovaném LCD displeji. Displej má rozlišení 128×64 bodů a lze jej využít na zobrazení téměř libovolných údajů. V našem případě bude prvních 10 vteřin po připojení k Wi-Fi zobrazovat logo s rokem instalace, poté na 5 vteřin bude na displeji zobrazeno název SSID Wi-Fi, ke které je přihlášen a obdrženou IP adresu. To je funkce intro(). A poté už na displeji uvidíte pouze tři hodnoty aktuální teplotu, vlhkost a sílu příjmu Wi-Fi signálu. Ve starém zapojení k indikaci připojení k Wi-Fi sloužila jen dvoubarevná dioda, která svítila modře v případě úspěšného připojení k sítí a červené pokud se k síti připojit nedalo.


Pohled na zapojení LCD a DHT22

Na následujícím schématu je LCD umístěn zvláštně. pokud by jste neměli desku s LCD jde ji jednoduše takto připojit. S integrovaným lcd ji pochopitelně připojovat nemusíte. Po chvíli hledání na internetu jsem našel tabulku, ze které jsem vycházel. Síla Wi-Fi signálu je tedy následující. V následující tabulce. Samozřejmě si můžete dle vlastních představ upravit, jak grafickou podobu, která je v příkladu umístěna v pravém spodním roku, tak také rozsah, ze kterými signál jednotlivým indikátorům přiřadíte.

Signál Popis
> –70 Výborný
> –85 Dobrý
> –100 Špatný
> –110 Hodně špatný


náhled na funkční program s teplou vlhkostí a sílou signálu


pohled na návrh instalace

Celý zdrojový kód.

#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`

// Initialize the OLED display using Wire library
SSD1306  display(0x3c, 5,4);
// https://github.com/ThingPulse/esp8266-oled-ssd1306
// (adresa , sda,scl)
int start = 1;
/* DHTServer - ESP8266 Webserver with a DHT sensor as an input

   Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)

   Version 1.0  5/3/2014  Version 1.0   Mike Barela for Adafruit Industries
*/

#include <Wire.h>

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN1  14




int poc = 0;
const char* ssid     = "TajnaWifi";
const char* password = "SuperTajneHeslo";


ESP8266WebServer server(80);

// Initialize DHT sensor
// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
// you need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// This is for the ESP8266 processor on ESP-01
DHT dht1(DHTPIN1, DHTTYPE, 11); // 11 works fine for ESP8266
// DHT dht2(DHTPIN2, DHTTYPE, 11); // 11 works fine for ESP8266
// DHT dht3(DHTPIN3, DHTTYPE, 11); // 11 works fine for ESP8266

float humidity1, temp_f1;  // Values read from sensor1
// float humidity2, temp_f2;  // Values read from sensor2
// float humidity3, temp_f3;  // Values read from sensor3

String webString = "";   // String to display
// Generally, you should use "unsigned long" for variables that hold time
unsigned long previousMillis = 0;        // will store last temp was read
const long interval = 2000;              // interval at which to read sensor

void handle_root() {
  // server.send(200, "text/plain", "Hello from the weather esp8266, read from /temp or /humidity");
  gettemperature();       // read sensor
  webString = "" + String(temp_f1) + "|"+ String((int)humidity1) +"*|*"; // Arduino has a hard time with float to string
  server.send(200, "text/plain", webString);            // send to someones browser when asked

  delay(100);
}

void setup(void)
{
  display.init();

  //display.flipScreenVertically();   // rotace displeje
  display.setFont(ArialMT_Plain_16);

   // modul nastartoval zobraz intro
   display.clear();  // clear the display
   display.setTextAlignment(TEXT_ALIGN_RIGHT);
   intro();
   display.display();
   delay(10000);



  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
  dht1.begin();           // initialize temperature sensor1
  //      dht2.begin();           // initialize temperature sensor2
  //      dht3.begin();           // initialize temperature sensor3


  // nasstaveni wifi modu jen na clienta
  // WiFi.mode(m): set mode to WIFI_AP, WIFI_STA, or WIFI_AP_STA.
  // WiFi.mode(WIFI_STA);
  WiFi.softAPdisconnect(true);

  // Connect to WiFi network

  WiFi.begin(ssid, password);
  Serial.print("\n\r \n\rWorking to connect");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {

    if (poc<33){

   display.clear();  // clear the display
   display.setTextAlignment(TEXT_ALIGN_RIGHT);
   connecting(poc);
   display.display();

      poc++ ;

    }else{

   display.clear();  // clear the display
   display.setTextAlignment(TEXT_ALIGN_RIGHT);
   teplota();
   display.display();
   delay(500);

    }

   delay(1000);

    Serial.print(".");
  }
  Serial.println("");
  Serial.println("DHT Weather Reading Server");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handle_root);



  server.on("/temp", []() { // if you add this subdirectory to your webserver call, you get text below :)
    gettemperature();       // read sensor
    webString = "Temperature: " + String((int)temp_f1) + " F"; // Arduino has a hard time with float to string
    server.send(200, "text/plain", webString);            // send to someones browser when asked
  });




  server.on("/humidity", []() { // if you add this subdirectory to your webserver call, you get text below :)
    gettemperature();           // read sensor
    webString = "Humidity: " + String((int)humidity1) + "%";
    server.send(200, "text/plain", webString);               // send to someones browser when asked
  });

  server.begin();
  Serial.println("HTTP server started");
}


 void intro( ) {
  display.setFont(ArialMT_Plain_24);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64,0,"ijacek.007");
  display.drawString(64,30,"© 2018");

 }

  void connecting( int poc) {
  char tecka = ' ';
   if(poc % 2 == 0){  tecka = '.'; }
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64,5,"Connecting ."+String(tecka));
  display.drawString(64,30,String(WiFi.SSID()));
  display.drawHorizontalLine(0, 0, (poc*4));
 }

  void ip( ) {
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64,0,String(WiFi.SSID()));
  display.drawString(64,30,WiFi.localIP().toString());

 }

  void teplota( ) {


   // sila signálu nejlepsi = 128  >-70dBm
   // dobrý = 96  -70 to -85
   // střední 64  -86 to -100
   // špatný 32   < -100
   // žadny 0    -110


  long rssi = WiFi.RSSI();

  // long rssi = -50;

   if ((WiFi.status() == WL_CONNECTED)){

   if (rssi>-70){display.drawVerticalLine(127, 38, 20);display.drawVerticalLine(126, 38, 20);}
   if (rssi>=-85 ){display.drawVerticalLine(124, 43, 15);display.drawVerticalLine(123, 43, 15);}
   if (rssi>=-100 ){display.drawVerticalLine(121, 48, 10);display.drawVerticalLine(120, 48, 10);}
   if (rssi>=-110){display.drawVerticalLine(118, 53, 5);display.drawVerticalLine(117, 53, 5);}

  }else {
   display.drawString(124,31,String("X"));

   }



    gettemperature();
  display.setFont(ArialMT_Plain_24);
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.drawString(64,2,String(temp_f1)+" °C");
  display.drawString(64,31,String(humidity1) +"%");
 //  display.drawString(64,31,String(WiFi.RSSI()));
  // display.drawString( a ,40,"-");
 // display.drawHorizontalLine(0, 0, a);
  }

void loop(void)
{


  server.handleClient();


 if (start == 1) {

    // modul zobraz ip
   display.clear();  // clear the display
   display.setTextAlignment(TEXT_ALIGN_RIGHT);
   ip();
   display.display();
   delay(5000);

   start = 0;

  }else{


   display.clear();  // clear the display
   display.setTextAlignment(TEXT_ALIGN_RIGHT);
   teplota();
   display.display();
   delay(500);
    }


}

void gettemperature() {
  // Wait at least 2 seconds seconds between measurements.
  // if the difference between the current time and last time you read
  // the sensor is bigger than the interval you set, read the sensor
  // Works better than delay for things happening elsewhere also
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you read the sensor
    previousMillis = currentMillis;

    // Reading temperature for humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
    humidity1 = dht1.readHumidity();          // Read humidity (percent)
    temp_f1 = dht1.readTemperature();     // Read temperature as Fahrenheit

    //   humidity2 = dht2.readHumidity();          // Read humidity (percent)
    //   temp_f2 = dht2.readTemperature();     // Read temperature as Fahrenheit

    //   humidity3 = dht3.readHumidity();          // Read humidity (percent)
    //   temp_f3 = dht3.readTemperature();     // Read temperature as Fahrenheit


    //float t = dht.readTemperature();
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity1) || isnan(temp_f1)) {
      Serial.println("Failed to read from DHT sensor 1!");
      return;
    }
  }
}



nastaveni desky a komunikace s arduino prostředím

Mohlo by Vás zajímat

Měření teploty a vlhkosti ve Fóliovníku

Měření teploty a vlhkosti pomocí ESP8266 a indikací připojení do Wi-Fi sítě


Štítky článku elektronika | programovani | stavebnice | zajimavosti |
Autor Ijacek.007 16.07.2018 Opravil(a) sokorka zobrazeno 5 259x
Předchozí článek Měření teploty a vlhkosti ve fóliovníku pomocí desky NODEMCU s čipem ESP8266
Sběrnice i2c a proč ji využívat Další článek


gravatar

Vložit komentář

Nick *:
WWW:
Email * (nezobrazuje se ):
Gravatar:
Pamatuj si mě:
Komentář článku *:
Opiš následující text: *

* - vyžadované údaje. RSS kanál s komentáři

Přihlášení



Audioknihy

Jsme milovníci audio knížek, kterých aktuálně máme zakoupených 390. Poslech všech dohromady zabral přes 5340 hodin.

Z tohoto množství jsme si již stihli poslechnout téměř 48% tedy 188 audioknih.

Aktuálně poslouchaná audioknihakniha je Everest 1922

Poslední hodnocenou audioknihou je Nápad za miliardu Hodnocení audioknihy 4/5.

Nejlépe hodnocenou audioknihou je Astronautův průvodce životem na Zemi Hodnocení audioknihy 4/5.

Reklama