Our third and fourth data are temperature and humidity. We will use a DHT11 sensor with the NodeMCU.
Get module and NodeMCU boilerplate from GitHub
We have a nice node that detects light, it works in toilet @ my work 🙂 It does it jobs almost perfectly. There is still a hack for it – leave a light on when leaving the toilet. I have an idea to fix this but first, let’s reforge a lousy code into a module and a handler. After refactor we may safely add it to the NodeMCU boilerplate.
This is going to be our second data node for display. It will show area lightness and with conjunction with a time, we can tell if an artificial light is on or off.
NodeMCU boilerplate @ GitHub
We have LCDs and we should have a data that can be displayed on them, we need data sources. So in parallel with displaying, let’s work on some sensor nodes.
First will be a motion detector, we gonna use a module with easy to remember name: PIR HC-SR501 🙂.
There are a few variants of it. But the main difference is an ability to use jumpers to change mode. My version can’t do that 😦
As a brain for sensor we will use the NodeMCUv3 board and as a language the LUA.
Module added to NodeMCU boilerplate @ GitHub
Before we do a restart and focus on creating GfxLCD module we need to know something more about other graphical displays. I have two more, one is monochrome 122×32 on NJU6450 chipset and second is OLED 0.96″ on SSD1306.
This time we gonna run NJU6450.
Why we need to know more? Because we will create a main gfx class and it’s drivers for different LCDs. And we should know biggest differences so we can be prepared for them. Like TFT is a color display but NJU is monochrome, so what to do with colors? How to do a conversion?
But before we answer those question let’s wire it and do a simple drawing.
Our little devices require a power. Mostly 5V DC. How to deliver it? The power grid is 230V so it is too much 🙂 and additionally, it is AC.
What can we do?
We can use a phone charger. It is easily affordable and does its job. But it looks bad and often we have power so close that it is a waste to use something with a long cord. We want to have a nice, small and compact device. What can we do?
We can draw pixels so let move further and write an algorithm for drawing a line. We could use loop and draw_pixel for it but this would be very inefficient. Remember that we operate in selected area so using pixel would first select a 1×1 area and then set a color. Two operations for each point in the line.
A long time ago we created a NodeMCU Node with two channel relay. It was working but it’s code bases on old boilerplate. I recently bought an SSR (solid state relay) so let’s take this opportunity and upgrade our node to the newest boilerplate and write a handler for relays.
To control 230V/110V devices we mostly use a relay module. What is a relay? We may describe it as a button but instead of a mechanical switch, we have an electric switch. Bluntly speaking it has 230V switchable by 5V. This describe any relay but what about a module?
The module gives us better protection, a control circuit and a device circuit has galvanic separation, often a led to show status and nice mount points. And such module can have more that one channel, it is a group of relays nicely mounted on a single board.
So this is it. A start of a long road to the main control node. It needs output (display) and input(touch). I was thinking about using a ready-solution, hook shield to a RPi and do some web based GUI. But the web it is my daily work – so no! It must be something different. And I want to use Python!
So lets get to work and do some first drawing. My screen is 2.4″ TFT 240×320 v2.1 – this display has an ILI9325 controller for an LCD and AD7843 for touch. And it is GPIO only version without SPI (ok it has SPI for touch) but it may work in 8-bit mode (it has 16 data pins – we will use only 8).
We will start with dirty code and one goal in mind. Display something 🙂 Later we will do the same thing as with CharLCD – separate driver logic and wiring from the main class.