Easy expansion of a DHT11 ESP8266-01 module

Various webstores sell (very cheap) a module with an DHT11, that takes a plug-in ESp8266-01, thus creating an easy way to ‘IoT’ the temperature and humidity in your house, or any place you want.

The module only uses 1 pin out of 4, but is a quick way to setup an ESP8266-01 application as it has a 3v3 regulator. As such it is also an easy base to use for projects that require a couple of more I/O pins.

Ofcourse one could solder wires directly to the head of the ESP8266-01, but a better solution is to create a little PCB in between  the module and the ESP8266.

For that, we need a couple of long headers and some scrap veroboard or strip board. This creates enough space to mount a small PCB as a ‘floor’ between the module and the ESP8266-01.

Veroboard and stripboard both have their pros  and cons: Veroboard needs you to connect the individual copper islets, but you don’t have to cut between the pins of the header, whereas stripboard doesn’t require you to connect individual islets, but you need to carefully cut the tracks between the 0.1″ spaced header columns.

Eventually you should be able to come up with something like this:

In this picture I expanded the module with a DS18B20, which explains the resistor at the top (is already replaced by an 0805 SMD resistor).

The DHT11 connects to GPIO2 and I have used GPIO0 for the DS18B20. If we look at the circuit of the module, we see that it has no pull up resistors on GPIO0 and GPIO2.

The reason for that is that the module is presumably for the ESP8266-01S that already has pull ups on GPIO0 and GPIO2, bt as I was using the regular ESP8266-01, there were no pull-ups.
The DHT11 module will boot without pullups and the DHT11 will render readings, but there are some false (‘nan’)  readings.
That can be solved by adding the appropriate 10k pull-ups to the board.
Here e.g. I have added an SMD resistor between the signal pin of the DHT11 and Vcc, which is a pull up on GPIO2 just as well.

Anyway, the extra PCB in between makes a further 3 pins available: GPIO0, GPIO1 and GPIO3. The latter 2 are ofcourse the Tx and Rx pin.
In order to use those as regular I/O pins, one needs to add the following two statements in the program:

pinMode(1, FUNCTION_3);
pinMode(3, FUNCTION_3);

A final remark on this module: realise that the DHT11 is placed close to the microprocessor, that generates heat and radiowaves. Those do affect the temperature reading. This can be up to 8-9 degrees difference. Bending out the DHT11 sensor -as shown in one of the pictures- gives much more reasonable readings.

The  method described here can also be used for some other ESP8266-01 modules that are available, such as the relay module , the DS18B20 module and the Neopixel controller (same link)

Advertisements

Solved: Starting programs at boot didn’t work on raspberry

Today I made a new fresh install of Raspbian-Stretch on my old RaspberryPi 1B. That board mainly has some python programs on it that MQTT info onto my network to OpenHab. The previous install had become a bit broken I think, it would crash every two days and rather than sorting that out, I decided a fresh install would be the quickest.

After installing a fresh Stretch image, I put all the programs and required libraries back on, a quick test and that all worked.
OK, now it is time to have the programs start automatically at boot.
That is also simple, I usually add the programs I want to start at boot in my /etc/rc.local file.

Always worked for me.
However, this time it didn’t and for the life of me I couldn’t figure it out. Why is a setup that used to work suddenly not working anymore, starting the programs at boot, while the programs itself work when started manually.
Trying trying trying. Writing the output from each command to a log file didn’t help me, logfiles stayed empty.
Then I decided to write the output of the entire rc.local file to a logfile with:

exec > /tmp/rc-local.out 2>&1;set -x

put that in the rc.local file right before the line that says “# Print the IP address”:

I rebooted and checked the file: /tmp/rc-local.out.

Now it became clear…. the paho (mqtt) module that these python programs were using was not found.
Odd.. I am sure I installed it……and when I manually start the programs they work 100%

I was thinking….. in my previous setup, I had installed the paho.mqtt library manually. It resided in a folder in my /home/pi directory. This time I had installed it with pip. Now it wouldn’t be that…… no, it couldn’t, could it?
The commands in the rc.local file, as far as I know are given by root and my /home/pi directory was owned by ‘pi’…….but that hadn’t changed between two installs and root has privilege anywhere right?

After some more searching I learned that the library “paho” had been installed by pip in the folder “/home/pi/.local/lib/python2.7/site-packages” but “sudo python” searches this library in the folder “/usr/local/lib/python2.7/dist-packages”.

I was not using sudo… but that is in fact what the rc.local does, so I was guessing that that was where my problem lied.

So, I needed to link the one directory to the other somehow.

This is what did that:

cd /usr/lib/python2.7/dist-packages
sudo ln -s /home/pi/.local/lib/python2.7/site-packages/paho

Then it all worked again.

Interesting info on how to start your programs at boot can be found here.

Using limitswitches with diodes

DC motors are often used in electronic projects and a special case is when a DC motor needs to be brought to a certain begin or end position without going further. Typically limit switches are then used. Such a switch is pressed by the motor when that motor reaches its end position. Similarly such a switch can be used when a motor reaches its begin position again.

Obviously, when a limit switch is pressed an action needs to be taken to stop the motor. The solution for that is in fact simple and old news, but surprisingly many hobbyists don’t know about that solution or struggle with it, and that’s why I will explain it here (with apologies to all people who do know it)

Motor in middle position

In the picture above there is a typical circuit for a motor with limit switches. Let’s presume the left switch is opened when the motor comes to its desired left position and the right one opens when the motor comes to its desired right position. Let’s also presume that the motor in that picture is in between left and right position.

It is easy to see that the electrical circuit is closed and that it doesn matter what polarity is used.

We then apply a positive voltage to the top wire and a negative voltage to the bottom wire. The motor starts turning left, until it reaches, presses and opens SW1.


Motor in leftmost position

At that moment, the electric circuit is open: Switch S1 is open and the left diode blocks a positive voltage. The motor stops.

To make the motor go back to its original position, we need to reverse polarity, so now the left most diode sees a negative voltage on its cathode and wil conduct curent: the motor turns reverse. After it travelled a fraction, SW1 will close again (as in the firts picture)…but that only becomes relevant later. We let the motor travel reverse till it comes to its desired right position, where it opens SW2.



Motor in desired right position

As soon as SW2 is open, the circuit gets broken again, no current will flow and the motor stops. As SW1 has closed again after the motor started travelling, the circuit will now conduct for a positive voltage on the top connector. Though SW2 is open, the right-side diode will conduct.

Arduino Atmega 2560 with ethernet W5500 module

If you want to connect the Arduino Atmega2560 with ethernet, there are various options. The easiest might be to get a shield. The regular Arduino shield should fit on the Arduino Mega as well. there are 3 versions of the shield: with an ENC28J60, with a W5100 and with a W5500.
The shields are fairly expensive, it is cheaper to get an ethernet module. These are also available as ENC28J60, W5100 and W5500.

With prices all in the same range (currently around 2.60 Euro), it is best to get a W5500, the most modern chip of the range, that definitely needs less memory than the ENC28J60.

To connect it to an Arduino Mega2560, one only needs 7 connections as shown in the image below.

The SPI connections can be best taken from the ICSP connector  and the chipselect from Pin 10.
Connections on the W5500 module are equally simple as they are usually printed on the module:
SCS is the chipselect that goes to pin 10
SCLK is the clock signal that goes to SCK on the 6 pin header.

When using the W5500, the ‘old’ Ethernet library is not usable anymore. You need to use the Adafruit Ethernet2 library or the WIZ_Ethernet_Library that supports the W5100, W5200 and W5500

Is the Si1145 reliable or is it a piece of crap

Currently working on a project that includes the Si1145 lightsensor.
The Si1145 measures visible light and infrared light and then calculates the UVI from that, without measuring actual UVA or UVB levels.
According to Adafruit it is very reliable.
When i used it however, it seemed the visible and infrared readings always hung around 625 or were 0, while the UVI was always 0.
Now ofcourse I could have a faulty sensor, but some browsing on the internet showed that this was a common occurrence.
When I put the (adafruit) library next to the datasheet, at first glance I couldn’t help but get the impression the library had some shortcomingins that might well explain the erratic behavior.

After some searching I found a latched library that worked better……but even then, in total darkness the ambient light and IR light hung around 600, but at least in daylight I would get different values and even a UVI reading.

The latter though proved totally inaccurate, easily going up to 7 in overcast weather.

I will do some further digging in the code but for now I would not recommend this sensor

Adding ADC channels to an ESP8266

One of the drawbacks of the ESP8266 is that it only has one ADC port.
In case you need more ADC ports, you could add an I2C ADC converter like the PCF8591 or the ADS1115, but there is a cheaper way that is easier to program as well.
You could use an analog multiplexer like the HCT4051, that can switch 8 ADC channels individually to the ADC input of your ESP8266.
Does this method have drawbacks? yes, you need 3 I/O pins to control the HCT4051 and the ESP8266 does not have an abundance of pins to begin with.
The circuit looks like this:

I have chosen GPIO12-14 to control the multiplex chip. If all control lines are LOW, the A0 line is patched through to the ADC of the ESP8266. If all control lines are HIGH, then the A7 line is patched through to the ADC channel of the ESP8266, the table below, shows the state of the I/O pins need to be in to read every individual analog channel

      S0      S1      S2
      GPIO14  GPIO13  GPIO12
A0     0       0       0
A1 0 0 1
A2 0 1 0
A3 0 1 1
A4 1 0 0
A5 1 0 1
A6 1 1 0
A7 1 1 1

ESP8266-01 Neopixel module


In Chinese webstores a “ESP-01S RGB LED Controller Module for Arduino IDE WS2812 Light Ring Smart Electronic DIY” module is sold for less than a dollar  (if you buy it without the ESP8266-01). The module contains everything that is needed to have an ESP8266-01S control a Neopixel strip

The module uses GPIO2 as output for the Neopixel(s). Suitable Software can be found here. Make sure you use the new ESP8266-01S with this module. The ESP8266-01S has the necessary pull up resistors already available. If you use the standard ESP8266-01 you need to attach the required pullups yourself.