ESP8622 z wyświetlaczem SSD1306 (OLED) DHT22, BH1750 pod ESPEasy

Domoticz part 3.1: ESP Easy on ESP8266 – remote and local OLED display with temperature, humidity, light – weather station

Previously we played around the SSD1306 OLED display as side display for Raspberry Pi. The author of ESP Easy – Richard ten Klooster (https://github.com/ESP8266nu/ESPEasy) – recently updated his project to include new sensors, so today we will update our DHT22 enabled remote sensor for Domoticz with display and light metering. Our weather station will get a remote display.

I’ve created such bundle of sensors to allow both temperature and humidity measurement small shack for chopped wood but also to light the way to it after dark via LED lamp. Also I was interested in stability of ESPEasy with DHT22, BH 1750 and OLED I2C display.

What will you need?

Software & Hardware

Let’s do it!

Connecting the display is very easy – event if you didn’t the previous example for Raspberry Pi. After logging in to ESP – ESPEasy – we choose the PINs that will work as I2C bus. This example uses the default: GPIO 4 & 5. Let’s connect our display to +3,3V, GND, and SDL & SCL to GPIO 4 & 5. The configuration is as follows:

ESP Easy - SSD1306
ESP Easy – SSD1306

Pay attention – this is how the sensor was called and the values that we defined – we need to enter them again just the same for the display for ESPEasy to get data and to display them correctly:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

The first value is the address on the I2C bus – to find out if we have correct one go to Tools->I2C Scan, which gives you the address – and notice that example shows another – connected to the I2C bus sensor – Lux – BH1750.:

ESP Easy - Scan i2c
ESP Easy – Scan i2c

Out address is (hexadecimal): 0x3c!
If all is correct – we should see “ESPEasy” on the screen (upside down is still fine).

Next – we move to display configuration – direction, which line are used for displaying – but first let’s try to display some data from external source:

Remote and local display

ESPEasy allows you to display both local sensor dana or any other data via unprotected method – using just http URL.
What is possible – first we can turn on/off the display. In this example the IP address of ESP8266 running ESPEasy is 10.20.30.40. We can turn off the display (i.e. it’s too bright in the night)

Then to turn in on:

Clearing the display:

Now, to us it in our project – we should use the curl to send data from Raspberry Pi:

An example:

Finally, we will use this function to display data from other sensor that our Raspberry Pi has data of – the opposite of what we usually use the ESP for!

But first – we should get the data from our already connected DHT22 and lux sensor. Let’s type the name of our sensor in Line 1. The Line 2 could hold the info about uptime – and time – we know that device is working and has proper communications with NTP.

Where to set NTP ? Go to NTP in Tools and choose your favourite NTP server – i.e. pool.ntp.org.
We got time & uptime – that’s easy. Displaying variable takes more effort – we need to use the percentage as brackets (%). Take a peek at Wiki page for examples.
We’re ready to display the data from DHT22. It’s time to check what was it’s name in the configuration:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

– and here it’s name is: AmicaTempHum. It’s a bit different we need “[ ]”, and the variables (we have two of them when talking to DHT 22) are separated by (#): [AmicaTempHum#Humidity]. This time the “%” is used to tell you that humidity is in % – so it’s supposed to be displayed.

The same approach should be used for temperature. Since by default we set 300 seconds of update time – we should get on the screen, after a while:

ESP8622 with SSD1306 (OLED) display working on ESPEasy
ESP8622 with SSD1306 (OLED) display working on ESPEasy

OPTIONAL: Since we can have quite a lot devices on I2C bus – let’s connect in paralel lux meter – BH1750. Meaning: VCC 3,3V to VCC, SDA & SCL to SDA & SCL finnaly GND to GND. Just like DHT22 it needs tiny amounts of power so the Amica NodeMCU can handle it safely. If we connected it properly we should get this info:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy
ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

So, next photo show how much light I’m using here:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

Beware – if you’re getting values like 54612 lux – the sensor is NOT working properly (check connections).

This is it – domoticz needs to be updated with new virtual Lux sensor (the virtuals for DHT22 have been added last time). So what to do with light intensity sensor ? Using the same approach as with the script for opening garage – we can turn on some LED lamps if it gets dark enough. Or use ‘Events’ in domoticzu if you like GUI approach.

But wait! People commenting this brought up interesting idea:

Displaying other values FROM domoticz on remote sensor

Looking at our example we see that Line 7 is empty. Originally I wanted to add the baraometer, but the shop canceled the order. I have other one on RPi – so why not use this data – atmospheric pressure cannot be that different, right? The BMP180 gives me temperature and pressure in hPa. I don’t care about the temperature, but the pressure is interesting. Since we already brought up the garage exampe  you might remember that a LUA script w domoticz can give you data and allows you to use it:

  • we need to get the pressure data
  • cut it (remove extra info)
  • display it on SSD1306 attached to ESP8266

The LUA script will use the round function – single digit, and will be launched every minute (or smarter – at any change then if with devicechanged) – so let’s use the time option.
In my system this sensor is named ‘TemperaturaCisnienie’ so remember the name of the script has to match it:

IP address needs to mathc you network and script goes to /home/pi/domoticz/scripts/lua:

So after a while you will get pressure on the screen.

Another example from comments discussion:
I you have the termometer from previous example about attaching termometers to domoticz – corresponding script is here (remember about the name!)

This time we only update on temperature CHANGE.