ESP-01 with Thermometers/Voltage regulators: Fix for “Failed to read from DHT sensor!”

Adafruit’s library is Broken.

Use it, but replace DHT.cpp with this one: https://raw.githubusercontent.com/adams13x13/DHT-sensor-library/761f4f4fb94c01afc283d0ffbfbfdeed5bb18a44/DHT.cpp

With that, I’m able to use this code to read from my devices:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#define DHTTYPE DHT11
#define DHTPIN  2
// Replace with your network details
const char* ssid     = "Mywifi";
const char* password = "mypassword";

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 dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
float humidity, temp;  // Values read from sensor
String webString="";     // String to display
unsigned long previousMillis = 0;        // will store last temp was read
const long interval = 2000;              // interval at which to read sensor
void setup(void)
  Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
  dht.begin();           // initialize temperature sensor

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

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("DHT Weather Reading Server");
  Serial.print("Connected to ");
  Serial.print("IP address: ");

  server.on("/", [](){  
    gettemperature();       // read sensor
    webString="Temperature: "+String((int)temp)+" C Humidity: "+String((int)humidity)+"%" ;   
    server.send(200, "text/plain", webString); 
  Serial.println("HTTP server started");
void loop(void)

void gettemperature() {
  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)
    humidity = dht.readHumidity();          // Read humidity (percent)
    temp = dht.readTemperature(false);     // Read temperature as CELSIUS
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity) || isnan(temp)) {
      Serial.println("Failed to read from DHT sensor!");

After that, I was able to run it in both my ESP-01 with DHT11, as shown here (running from 5v from the breadboard):

Problem is, those thermometers are terribly incorrect! My lab is around 22 degrees. What both sensors show?

So, yeah, that’s it for those things. I will search for something better.


Syncthing, Raspberry Pi and SD cards’ life.

I have been using the great Syncthing for my backups, after I finally gave up on Resilio Sync. Basically because the memory consumption of it was unbearable on the Raspberry Pi which I use as the backup server together with an external hard drive.

It works just as well – if not better, its WAY lighter on resources, and it’s open source.

Those synchronization services have a problem, though. They keep many files for indexing their data. Millions of them.

And those files are stored at your home directory.

Which is on the SD card.

Got it already? If no, I will tell you. This will kill your SD card in no time. So, to solve it, move your .config/syncthing to the external hard disk, and do a symlink from the original location.

Something like

mv ~/.config/syncthing /media/externalDisk/
ln -s /media/externalDisk/syncthing ~/.config/syncthing

The same applies for Swap space. Raspberry PIs don’t usually have a separate partition, so they use by default the software dphys-swapfile which maps swap to a file, instead.

Given you are using a LOT of ram with SyncThing, your machine will swap. So, move it to the external hard drive as well just edit the


and use a file on the external disk as well. It will make your SD card live WAY longer.


ESP-01 without soldering

I’ve had one of those for quite some time, but never bothered to do anything with it, as all guides on the internet mentioned some jumper soldering to even start sending code to it.


Recently, I stumbled over some serial controllers made only for this board: I bought it on AliExpress, for less than one euro: link ESP01-Programmer-Adapter-UART-GPIO0-ESP-01-Adaptaterr-ESP8266-USB-to-ESP8266-Serial-Wireless-Wifi-Developent.jpg

Thing is, you still need some soldering in order to make this run. What are they thinking?

Instead of that, I just forced some cable between the ESP-01 and this usb thing. Link this:


Turns out it works!IMG_0584.JPG

Now, to make those super cheap DHT-11 temperature sensors with voltage regulator work with this, is another story….

But let’s be honest, it’s the cutest IoT/web server ever 🙂



NodeMCU ESP8266 v3 (Lolin) working!

I have been trying to make my cheap ESP8266 work for a while. There are multiple issues with them, including garbage output, wrong clock settings, the thing being oblivious to wifi and so on.

Turns out that removing and reinstalling ESP8266, and full update on Arduino and its libraries, and using those settings below, seem to do the trick:

Screen Shot 2018-02-25 at 23.31.34.png

Here is one of my boards, on a base, happily running a web server:


PS: Those things accept anything from USB up to 24v. Great for car/motorbike projects!


Files on ESP32 Micropython and how to scan networks on power up

Turns out it’s way easier than I expected. The ESP32 has a tiny filesystem which can be used to have files on. And, even better, there’s a “boot.py” file which is always executed after a power on or waking up from deep sleep. You just use the normal python file interface as you do on any code.

And this is valid even for writing the boot.py!

So, if you want to scan the wifi networks around at every boot, just plug your ESP32 onto your arduino IDE, and paste this, line by line, at the serial monitor:

f.write("print('************* Welcome to Strube ESP32 *************')\n")
f.write("import network\n")
f.write("station = network.WLAN(network.STA_IF)\n")
f.write("print('Wifi networks around:')\n")
f.write("for i in n:\n")
f.write(" print(i[0])\n")

This will create (or erase) a boot.py file (think of it as the AUTOEXEC.BAT from MS-DOS, or the AUTORUN.INI from windows), start the network module and scan for available Wi-Fi access points.

It shows something like this (I removed the names of the networks which don’t happen to be my coffee machine):Screen Shot 2018-02-14 at 17.54.00.png

Don’t know why the “ENOENT” error at the end yet.


ESP32 + MicroPython + Mac, Wi-Fi scan example

I have been trying to upload MicroPython to a ESP32 on a Mac. It uses the CP210x serial-to-usb driver, so you need to have this installed before you even bother.

ESP32, an amazing little board.

Flashing MicroPython from a Mac to ESP32

I got MicroPython from the official site, at http://micropython.org/download/#esp32. Current version is v1.9.3-240-ga275cb0f, from January 21st, 2018 (today).

To upload it, I used the NodeMCU flasher tool, which I got from Marcel Stör’s github. It allows you to use a GUI to Flash ESP8266 and ESP32 boards. You might need to install WxWidgets – the python’s PIP doesn’t work, but the brew one works. Easy peasy:

brew install wxpython

And you are good to go:

git clone https://github.com/marcelstoer/nodemcu-pyflasher.git

And follow the instructions on how to build it.

Once you have it, you can try the GUI, but when I try to flash it, I have an error like this:

flash read err, 1000
Falling back to built-in command interpreter.
>ets Jun 8 2016 00:22:57

So, I went to the directory where I cloned it, and ran from the command-line:

python esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x1000 ~/Downloads/micropython-esp32-20180121-v1.9.3-240-ga275cb0f.bin

Which gave me a working MicroPython on the ESP32.

Wi-Fi Scan

Making the wifi scan test is a four-liner:

import network
station = network.WLAN(network.STA_IF)

This is the output I get on Arduino Serial monitor, from the reboot to the moment I type those commands (shown in red):

ets Jun 8 2016 00:22:57

configsip: 0, SPIWP:0xee
mode:DIO, clock div:2
entry 0x4007a6c4
[0;32mI (205) cpu_start: Pro cpu up.[0m
[0;32mI (205) cpu_start: Single core mode[0m
[0;32mI (205) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (208) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (215) heap_init: At 3FFDCD68 len 00003298 (12 KiB): DRAM[0m
[0;32mI (221) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
[0;32mI (227) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (233) heap_init: At 4008FC7C len 00010384 (64 KiB): IRAM[0m
[0;32mI (240) cpu_start: Pro cpu start user code[0m
[0;32mI (33) cpu_start: Starting scheduler on PRO CPU.[0m
OSError: [Errno 2] ENOENT
MicroPython v1.9.3-240-ga275cb0f on 2018-01-21; ESP32 module with ESP32
Type "help()" for more information.
>>> import network
>>> station = network.WLAN(network.STA_IF) 
I (42465) wifi: wifi firmware version: 111e74d
I (42465) wifi: config NVS flash: enabled
I (42465) wifi: config nano formating: disabled
[0;32mI (42465) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
[0;32mI (42475) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
I (42495) wifi: Init dynamic tx buffer num: 32
I (42495) wifi: Init data frame dynamic rx buffer num: 64
I (42495) wifi: Init management frame dynamic rx buffer num: 64
I (42505) wifi: wifi driver task: 3ffe2d38, prio:23, stack:4096
I (42505) wifi: Init static rx buffer num: 10
I (42515) wifi: Init dynamic rx buffer num: 0
I (42515) wifi: Init rx ampdu len mblock:7
I (42525) wifi: Init lldesc rx ampdu entry mblock:4
I (42525) wifi: wifi power manager task: 0x3ffe852c prio: 21 stack: 2560
[0;32mI (42555) phy: phy_version: 362.0, 61e8d92, Sep 8 2017, 18:48:11, 0, 0[0m
I (42555) wifi: mode : null
>>> station.active(True) 
I (68635) wifi: mode : sta (24:0a:c4:03:a8:90)
[0;32mI (68635) wifi: STA_START[0m
>>> station.scan()
[0;32mI (79565) network: event 1[0m
[(b'FRITZ 6360C', b'\x9c\xc7\xa6\x0cc\xbe', 1, -84, 4, False), (b'WLAN-565914', b'\xd4!"\xe9\xb7K', 11, -92, 3, False)]

I still have to figure out how to write python scripts to the filesystem, haven’t checked on it yet. But I am happy to make it work 🙂



Esp8266 NodeMCU V3 Lolin: Don’t bother! (Update: Maybe you can give it a try)

I made a robot a while ago – it’s pretty much documented here – with a Esp8266 board. It worked beautifully from the beginning. You set up the board on Arduino IDE and you are good to go.

IMG_8682.JPGA wonderful little board

Recently, inspired by a tweet from my genius friend Ugo Sangiorgi about using the ESP8266 as a wi-fi repeaters, I decided to buy a couple more of those boards, in order to cover my house with cheap wi-fi.

Being the cheapskate I am, I went to AliExpress, and bought the cheapest NodeMCU I found: Something called “NodeMCU V3” (the officials are V1 and V2). It costs around 2 euros. Check it here: NodeMcu on Aliexpress

It damn looked like my first NodeMCU. And a Wi-Fi router for 2 euros, albeit a slow one, is unbeatable.

Until they arrived.

This is the little monster:

IMG_8681.JPGEsp8266 NodeMCU V3 Lolin – looks similar to the one above, eh?

As everyone does, the first thing I did was to power it on and try the Blink example. (It comes with a blink one, but anyway). Nothing.

Turns out, the LED_BUILTIN is set to some other pin. If you and to make it work, replace “LED_BUILTIN” on this board with “2”. It works.

Fine. The board looked a bit large, though. I took an ESP32 that I had around and checked. This thing is bigger than the ESP32 that I was whining about a while ago here!

Lo and behold…

IMG_8684.JPGThe damn board VS a ESP32. Notice how the wifi antenna is somehow covered.

It uses the CH340 serial, which seems to be a piece of crap, but hey, 2 euros. I couldn’t care less.

Making the board run properly on Arduino IDE

(UPDATE: This is outdated. Check my newer post on this board).

The serial output is wrong: One has to set


on arduino code in order to get 115200 output on the serial monitor. This is because it uses a 40mhz crystal oscillator instead of the standard 26mhz one. You can fix this with changing the crystal settings at


Just force setting it to 40mhz, around line 87:

    // crystal_26m_en
    // 0: 40MHz
    // 1: 26MHz
    // 2: 24MHz
      [48] = 0,

This SHOULD fix the fact that this board basically has no wifi. Some people have reported partial success on github, but I can’t say the same. I can see no wifi here.

Did I say that this board is huge? Well, good luck using it in a breadboard. It doesn’t leave any room for anything:

IMG_8685.JPGLove playing with your boards in a breadboard? Well FUCK YOU

All in all, I spend quite some days to find the solution for the LED pin and the clock I mentioned above, and I still can’t have any wi-fi whatsoever. The vendor asked if I have googled it (!).

To sum it up, my recommendation is: don’t buy this crap. There are other cheap boards around.

Oh, and when I mentioned the other Esp8266? Here it is one next to the other:

IMG_8679.JPGThe good, the bad and the ugly?

IMG_8680.JPGThe underbelly of the original ESP8266 vs this Lolin whatever

So, again, the links:

https://github.com/esp8266/Arduino/issues/4005 – the talk about the serial output and wifi

core_esp8266_phy.c The file you should change to make it work

A wifi repeater using ESP8266

(UPDATE: This is outdated. Check my newer post on this board).