pinout of a Wemos D1 mini

I'm getting frustrated here :frowning:

I'm trying to read out a DHT22 sensor.

It's a breakout board with 3 pins : GND, VCC and DAT

I connected the 5V of the Wemos D1 mini with the VCC, the GND with the GND and the DAT with D0.

It took me a while to found out that D0 is not pin 0 in arduino! :frowning:

On this page I found out that D0 = 16, right?

Still doesn't work :frowning: I'm still getting a "failed to read from DHT sensor"

This is my code :

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 16     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}

My only guess is that I'm still not using the right pin in my code, can someone help me out pls?

stevennoppe:
It took me a while to found out that D0 is not pin 0 in arduino!

Yes, that one got me too when I started with the WeMos boards. The confusing thing is sometimes you will see the digital pins on standard Arduino boards (e.g. Uno) referred to with the Dn notation but you need to use just the number in the code. So I tried doing the same with my WeMos D1 when I first used it. The best thing to do with those boards is to just call the pin D0 in your code. Don't worry about what the value of D0 is, just go by what's written on the silkscreen on the board.

stevennoppe:
My only guess is that I'm still not using the right pin in my code, can someone help me out pls?

You can verify what pin is what by connecting a multimeter or LED to the pin and then uploading the File > Examples > 01.Basics > Blink sketch modified to blink that pin.

1 Like

I did the test like you told me and it seems that D0 is indeed 16 :

LED_BUILTIN = blue LED
0 = D3
1 = TX
2 = blue LED
3 = RX
4 = D2
5 = D1
12 = D6
13 = D7
14 = D5
15 = D8
16 = D0

So now I'm 100 % sure that my connections are ok :slight_smile:
I will make a new post now, since the question has to be remade...

In case you're wondering, it's in the documentation here: Arduino/boards.rst at master · esp8266/Arduino · GitHub.

Pieter

The problem was that the last hour I was using "16" for D0 but it still didn't work and I was doubting the pinout because of that.

Now I'm 100% sure about the pinout, so there has to be another problem...

Just a wild guess: GPIO16 / D0 is the RTC GPIO, it hasn't got the same features as a normal IO pin. For example, it doesn't have interrupt capabilities. I'm not sure if the DHT library uses interrupts, but it could explain why it doesn't work.

Pieter

Edit:

// 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

Hello PieterP,

that was probably indeed the problem!

I connected the DAT to D3 and now it works!

thanx a lot !