Wemos D1 Mini Documentation
Wemos D1 Mini Documentation
power, its shields, and a documentation that looks fairly good. The board can be programmed with
Arduino or Lua, and supports both serial and OTA programming. I’ve decided to give it a try and bought
the board together with two temperature shields, a relay shield, and micro SD shield.
Click to Enlarge
I got all for $ 14.00 from Wemos Aliexpress shop, and it took about one month for delivery. I can also see
they’ve recently released a new OLED shield selling for about $5. All shields were shipped inside their
own anti-static bags.
The pins are clearly marked on both side of the board and the shields. One side of the board features
ESP8266 module.
and the other side has CH340 serial to USB chip, and the reset button.
The provided headers make it easy to stack the board with several shields if you wish too. For example I
connect Wemos D1 mini to both the relay shield, and DHT Pro shield after soldering some of the headers.
The only potential pitfall would be to solder the header on the wrong side, so you just need to make sure
the pins (5V, RST,…) are properly aligned.
I’ve mostly followed the Getting Started in Arduino guide in Wemos.cc in this tutorial, and people who
prefer Lua/NodeMCU will want to check NodeMCU guide instead. There are various ways to configure the
Arduino IDE for WeMos D1 mini in the guide, but I’ve only used the recommended way: git.
The first step was to install and run Arduino 1.6.8. Since I’m using a computer running Ubuntu 14.04 64-
bit, I downloaded and installed Arduino 1.6.8 64-bit for Linux:
Note this folder as this is where we’ll install the board support, tools and examples, and exit Arduino
before starting the installation:
cd
1
2mkdir -p hardware
3cd hardware
4mkdir esp8266com
5
cd esp8266com
6
git clone https://github.com/esp8266/Arduino.git esp8266
download the binary tools:
1 cd esp8266/tools
2 python get.py
and finally install the examples:
1 cd
2 git clone https://github.com/wemos/D1_mini_Examples.git
Later on, you can update the board support files and the samples by running git pull in the two
directories where you ran git clone.
Now connect Wemos D1 mini to a USB port of your computer with a micro USB to USB cable. In Linux,
you should see a new device in the kernel log:
[ 8643.196931] usb 7-3: new full-speed USB device number 4 using ohci-pci
[ 8643.361709] usb 7-3: New USB device found, idVendor=1a86,
1
2 idProduct=7523
3 [ 8643.361717] usb 7-3: New USB device strings: Mfr=0, Product=2,
4 SerialNumber=0
5
[ 8643.361722] usb 7-3: Product: USB2.0-Serial
6
[ 8643.363826] ch341 7-3:1.0: ch341-uart converter detected
[ 8643.387870] usb 7-3: ch341-uart converter now attached to ttyUSB0
Let’s start Arduino 1.6.8 and select WeMos D1 R2 & mini in Tools->Board.
We can use the default for the other settings include 80 MHz CPU frequency, 4M flash size, 912600
upload speed, and /dev/ttyUSB0 port.
We can now use the code samples, and to make sure everything works I’ll run the blink project in File-
>Sketchbooks->D1_mini_Examples->01. Basics->Blink:
1
2/*
3* Blink
4
5* Turns on the onboard LED on for one second, then off for one second,
6repeatedly.
7* This uses delay() to pause between LED toggles.
8*/
9
1
0void setup() {
1 pinMode(BUILTIN_LED, OUTPUT); // initialize onboard LED as output
1}
1
2
1void loop() {
3 digitalWrite(BUILTIN_LED, HIGH); // turn on LED with voltage HIGH
1 delay(1000); // wait one second
4
1
digitalWrite(BUILTIN_LED, LOW); // turn off LED with voltage LOW
5 delay(1000); // wait one second
1}
6
Pressing the Upload button will build and upload to code to the board and once this is complete, the
build-in Blue LED (D4 / GPIO2) will blink every second. So my board is working.
As you can see I’ve already connected DHT Pro shield to the board, so let’s try the sample for the shield
to get the temperature and humidity in File->Sketchbooks->D1_mini_Examples->04. Shield-
>DHT_Pro_Shield->Simple:
/* DHT Pro Shield - Simple
*
* Example testing sketch for various DHT humidity/temperature sensors
* Written by ladyada, public domain
*
* Depends on Adafruit DHT Arduino library
* https://github.com/adafruit/DHT-sensor-library
*/
#include "DHT.h"
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// 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;
}
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");
}
But this time I had an error during compilation, as DHT library is missing:
D1_mini_Examples/04.Shields/DHT_Pro_Shield/Simple/Simple.ino:10:17: fatal
1 error: DHT.h: No such file or directory
2 #include "DHT.h"
3
4
^
5 compilation terminated.
6 exit status 1
Error compiling for board WeMos D1 R2 & mini.
To fix that error, go to Sketch->Include Library->Manage Libraries, input dht to filter the library, and
install DHT sensor library by Adafruit.
Now click on the Upload button again, the code will be compiled and uploaded to the board. Now open
the serial monitor with Ctrl+Shift M or Tools->Serial Monitor, and you should see the printed values for
the humidity in percent as well as the temperature & heat index in Celcius and Fahrenheit.
Th
e reported temperature matched the temperature reported by my IR thermometer (32.5 C). Pretty good.
If you’d like to get results displayed on a web page instead, you may want to modify DHT Shield-
>SimpleServer sample.
Now I’ll had the relay shield on top, and run another sample (File->Sketchbooks->D1_mini_Examples-
>04. Shield->Relay_Shield->Blink):
C
/*
* Relay Shield - Blink
1 * Turns on the relay for two seconds, then off for two seconds, repeatedly.
2
3
*
4 * Relay Shield transistor closes relay when D1 is HIGH
5 */
6
7
const int relayPin = D1;
8
9 const long interval = 2000; // pause for two seconds
10
11 void setup() {
12
pinMode(relayPin, OUTPUT);
13
14 }
15
16 void loop() {
17 digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
18
19 delay(interval); // pause
20 digitalWrite(relayPin, LOW); // turn off relay with voltage LOW
delay(interval); // pause
}
The relay blink sample will turn on and off the relay every two seconds. Since the DHT Pro shield uses D4
pin and the Relay shield uses D1 pin both can be used at the same time. I had no problem uploading the
sample to the board, and hearing the relay switch on and off every 2 second.