Arduino ESP8266 Tutorial: First look at the WeMos D1 Arduino compatible ESP8266 Wifi Board
Hi guys, welcome to today’s tutorial. Today we will be taking a look at the Wemos D1 Arduino compatible esp8266 wifi board. The Wemos D1 is a Wi-Fi enabled board which is compatible with the Arduino and is based on the popular ESP8266 chip. It is one of the cheapest Arduino boards around, less than 9$. I ordered one a few days ago, which just came in and I thought it will be cool to do a first look at the board in today’s tutorial.
The Wemos D1 looks like the normal Arduino board with the same pin layout as the Uno, which means all of the shields which can be used with the Arduino Uno, will plug in seamlessly with the Wemos D1. While the connection is one thing, the shields must have matching libraries that work with the esp8266 platform so as to be able to establish easy communication between the Wemos and the shield.
Instead of using any of the Atmel/AVR series of microcontroller, the board uses the ESP8266EX chip. some of the features of the ESP8266EX chip include;
- 32-bit RISC CPU
- 80mhz clock speed
- 64kb Instruction RAM
- 96kb Data RAM
- 4-8MB flash memory
- 16 GPIO pins including I2C and SPI
- I2S
- 1 ADC
- Embedded WiFi
to mention a few. The flash memory is a 100 times bigger than the Arduino with an equally greater RAM compared to the Arduino.
For this tutorial, we will be looking at how to setup the Wemos D1 so you can program it using the Arduino IDE. We will also be looking at connecting to the internet using the board and lastly, we will be trying out the display of information from the board on an OLED Display.
Required Components and Where to Buy
To follow this tutorial and build along, the following components/parts are required;
1. ESP8266 BOARD ▶ https://educ8s.tv/part/WemosD1
2. OLED Display ▶ https://educ8s.tv/part/OLED096
3. Small Breadboard ▶ https://educ8s.tv/part/SmallBreadboard
4. Wires ▶ https://educ8s.tv/part/Wires
[adsense]Preparing the Arduino IDE
To be able to program the Wemos D1 with the Arduino IDE, we will need to install the board support for the esp8266 board on the Arduino IDE. Follow the steps below;
1. Include the link to the ESP8266 board in your Arduino preferences by going to file and selecting Preferences then enter this URL ( http://arduino.esp8266.com/stable/package_esp8266com_index.json ) in the text box in front of addition board manager URL.
2. click on tools then select board manager, wait for it to update then scroll down and install the esp8266 boards.
Once this is done, you will be able to select the Wemos D1 board to upload codes to it. Installing the board automatically leads to the installation of the esp8266 example codes. It is important to note that due to the different hardware architecture of the ESP8266 most programs will not work without modifications. Also, most of the libraries need to be rewritten in order to work as well. so to test the board installation, we will use the blink sketch example which is meant for the ESP8266. it is similar to the one for Arduino but it’s not the same. To load the blink sketch, go to, examples, scroll down to esp8266 and select blink, then proceed to select the Wemos board under tools and upload the code to it. You should see the LED on the Wemos board begin to blink after code upload.
Connecting to the Internet with the Wemos D1
After getting the blink sketch to work, the next thing we will try is to connect the board to the internet. For this, it will be nice to visualize the whole process, so we will be connecting an OLED display to the Wemos D1 board.
Schematics
Connect the Wemos D1 to the OLED Display as described below.
OLED ▶ Wemos D1 VCC ▶ 5v GND ▶ GND SDA ▶- SD0 SCL ▶ SCLK/SDCLK/CLK
Code
To test the ability of the board to connect to the internet, I developed a simple program that connects to my home Wi-Fi network and then visits my website educ8s.tv to download some text that it is stored in a .txt file at this URL educ8s.tv/test.txt. As shown in the image below, after a while the text “It works fine” which is the text stored in the .txt file on the server appears on the little OLED display. The board works flawlessly!
To do a brief explanation of the code, the first thing we do in the code is to include the libraries to be used. A special library for the OLED display was used and it is attached alongside the code in the download section.
#include <ESP8266WiFi.h> #include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility #include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file) #include <SPI.h> // For SPI comm (needed for not getting compile error) #include <Wire.h> // For I2C comm, but needed for not getting compile error
Next, we input the credentials of the WiFi to which the ESP will connect to.
const char* ssid = "ZyXEL"; const char* password = "password"; char servername[]="educ8s.com"; // remote server we will connect to WiFiClient client;
With that done, we then write the HTTP get function that visits the website and pulls the information stored in the text file.
void sendGET() //client function to send/receive GET request data. { if (client.connect(servername, 80)) { //starts client connection, checks for connection Serial.println("connected"); client.println("GET /test.txt HTTP/1.1"); //download text client.println("Host: educ8s.tv"); client.println("Connection: close"); //close 1.1 persistent connection client.println(); //end of get request } else { Serial.println("connection failed"); //error message if no client connect Serial.println(); } while(client.connected() && !client.available()) delay(1); //waits for data while (client.connected() || client.available()) { //connected or data available char c = client.read(); //gets byte from ethernet buffer result = result+c; deleteHttpHeader(); Serial.println(c); } Serial.println(result); display.setTextSize(1); display.setTextColor(WHITE); display.print(result); display.display(); client.stop(); //stop client }
The void setup function is next. here the display is set to provide feedback by displaying the outcome of the actions of the esp8266.
void setup() { Serial.begin(115200); delay(10); display.begin(SSD1306_SWITCHCAPVCC); // Switch OLED display.display(); display.clearDisplay(); delay(2000); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.print("Connecting to "); display.print(ssid); display.display(); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); display.println("\nWiFi connected"); display.println("IP address: "); display.println(WiFi.localIP()); display.display(); }
The void loop() function calls the result function which displays the information stored in the text file that was accessed by the board.
void loop() { result=""; delay(5000); sendGET(); }
With this board, Our Arduino projects can now access the Internet with ease. The OLED display I use with the Arduino in previous tutorials works fine with the use of the appropriate library developed for the ESP8266.
The Full code for the project can be downloaded below.
——————–
CODE OF THE PROJECT
——————–
That’s it for this tutorial guys, thanks for watching and(or) reading. Did you make any cool and interesting with the wemos D1 or you have any questions, feel free to leave me a comment. Do subscribe to our youtube channel by following the link below if you’ve not done so already, its one of the few ways you could show support for what we are doing. see you next time.
SUBSCRIBE ON YOUTUBE
——————–
Never miss a video: Subscribe to educ8s.tv
that is amazing …. thank you for this great effort
If your application requires maximum battery life, you ll likely need to make liberal use of the ESP8266 s deep sleep functionality. That ll be covered later in this tutorial.
I am getting this error while trying to compile the wifitest file on arduino:
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp: In member function ‘virtual void ESP_SSD1306::drawPixel(int16_t, int16_t, uint16_t)’:
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp:130:14: error: ‘swap’ was not declared in this scope
swap(x, y);
^
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp: In member function ‘virtual void ESP_SSD1306::drawFastHLine(int16_t, int16_t, int16_t, uint16_t)’:
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp:594:16: error: ‘swap’ was not declared in this scope
swap(x, y);
^
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp: In member function ‘virtual void ESP_SSD1306::drawFastVLine(int16_t, int16_t, int16_t, uint16_t)’:
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp:662:16: error: ‘swap’ was not declared in this scope
swap(x, y);
^
exit status 1
Error compiling for board WeMos D1 R2 & mini.
Would you help how to fix this please ? I use Arduino 1.6.9 version too, thank you.
Had a similar problem.
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp: In member function ‘virtual void ESP_SSD1306::drawFastHLine(int16_t, int16_t, int16_t, uint16_t)’:
C:\Arduino\libraries\OLEDESP\ESP_SSD1306.cpp:594:16: error: ‘swap’ was not declared in this scope
swap(x, y);
If you have an older version of the ESP_SSD1306.h in your project import the below library and be sure to pick ESP8266 SSD1306 from the library dropdown.
https://github.com/somhi/ESP_SSD1306
Have you measured current draw in deep sleep? The RT9013 they use seems to have a low Iq – unlike the 1117-3.3 often used in other ESP8266 boards. It looks like one could feed in a LiPo directly to the “+5V” Arduino pin.
The only other low Iq I’ve found is the SPX6819 that Adafruit used on their Huzzah. I’ve rolled my own boards using 1825S that seem to be running off 1W solar panels driving the cheap TP4056 chargers into 1800 mA-Hr LiPos. They wake up every 30 minutes, reconnect to wifi and upload to Thingspeak.
Working well in summertime. When winter comes I may need a slightly larger solar panel.
I’m hopeful these Wemos boards can work as well. Nice to have the schematic available!
The other loads would seem to be the USB chip on the power LED, but the schematic shows a 10K on the LED.
This seems like a nice platform with mounting holes, 4-pin connectors for UART and I2C.
My comments were based on the R2 version. It will be interesting to so the differences between that one and the original.
Can you give us a schematic on how this is wired? Especially the OLED. Thanks
where i found rtc library for wemos D1 R2 mini can u plese tell me who may known
Excellent, please do more. I’ve purchased a couple of these and learn a lot from what you do, please do more on the D1
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Library is here.
How do you interface an arduino mega board to the esp8266 development board
how do i operate my esp8266 d1 mini by android phone by sending data to firebase
(firebase as a inerface between phone and esp).
please give me code.i am new learner .
I am getting this error while trying to compile the wifitest file on arduino:
Build options changed, rebuilding all
In file included from C:\Users\nurulfais\Desktop\ESP8622 part 1\universal-arduino-telegram-demo-master\implementation\implementation.ino:1:0:
C:\Program Files (x86)\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src/UniversalTelegramBot.h:27:25: fatal error: ArduinoJson.h: No such file or directory
#include
^
compilation terminated.
exit status 1
Error compiling for board WeMos D1 R2 & mini.
Would you help how to fix this please ? I use Arduino 1.8.3 version too, thank you.
It seems that only a few shields will fit, the prototyping-style shields would be the best bet, not LCD displays or similar. Most I/O on the 8266 is already in use, so it’s pretty much I2C throughout, unless you want to just turn on a relay/buzzer/LED.
Also watch out, it’s unprotected 3.3V logic, so you can easily blow an input with 5V.
And why is this comment box text grey on white, I can hardly see it! It’s all very well getting trendy, but….!
Connecting to Router
WiFi connected
IP address:
192.168.100.144
Content-Length: 14
Connection: close
thank you man! it’s very help me, unfortantly if do search wemos d1r1+ssd1306 google never give your link, after few days i do wemos d1r1 i2c search request, and find your project.
thanks. Got errors when compiling related to ‘SWAP’ in the adafruit GFX library, ESP_SSD1306.cpp wbich i could only resolve by editing the cpp to comment out all rferences to SWAP. Probably going to cause future problems with other sketches, but doing this got it to work. Any comment on a better way would be appreciated.
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: “Olimex MOD-WIFI-ESP8266(-DEV), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 2MB (FS:64KB OTA:~992KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600”
WARNING: library Arduino_Uno_WiFi_Dev_Ed_Library claims to run on avr architecture(s) and may be incompatible with your current board which runs on esp8266 architecture(s).
In file included from C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:8:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.h:18:3: error: ‘ESP’ does not name a type
18 | ESP *esp;
| ^~~
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.h:27:11: error: expected ‘)’ before ‘*’ token
27 | MQTT(ESP *esp);
| ~ ^~
| )
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:11:11: error: expected constructor, destructor, or type conversion before ‘(‘ token
11 | MQTT::MQTT(ESP *esp8266)
| ^
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘boolean MQTT::begin(const char*, const char*, const char*, uint16_t, boolean)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:20:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
20 | crc = esp->request(CMD_MQTT_SETUP, 0, 1, 9);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘boolean MQTT::lwt(const char*, const char*, uint8_t, uint8_t)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:51:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
51 | crc = esp->request(CMD_MQTT_LWT, 0, 1, 5);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘void MQTT::connect(const char*, uint32_t, boolean)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:69:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
69 | crc = esp->request(CMD_MQTT_CONNECT, 0, 0, 4);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘void MQTT::disconnect()’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:84:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
84 | crc = esp->request(CMD_MQTT_DISCONNECT, 0, 0, 1);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘void MQTT::subscribe(const char*, uint8_t)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:91:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
91 | crc = esp->request(CMD_MQTT_SUBSCRIBE, 0, 0, 3);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp: In member function ‘void MQTT::publish(const char*, uint8_t*, uint16_t, uint8_t, uint8_t)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\mqtt.cpp:105:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
105 | crc = esp->request(CMD_MQTT_PUBLISH, 0, 0, 6);
| ^~~
| exp
In file included from C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:7:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.h:30:3: error: ‘ESP’ does not name a type
30 | ESP *esp;
| ^~~
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.h:38:11: error: expected ‘)’ before ‘*’ token
38 | REST(ESP *e);
| ~ ^~
| )
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:8:11: error: expected constructor, destructor, or type conversion before ‘(‘ token
8 | REST::REST(ESP *e)
| ^
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp: In member function ‘boolean REST::begin(const char*, uint16_t, boolean)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:27:18: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
27 | uint16_t crc = esp->request(CMD_REST_SETUP, (uint32_t)&restCb, 1, 3);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp: In member function ‘void REST::request(const char*, const char*, const char*, int)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:50:11: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
50 | crc = esp->request(CMD_REST_REQUEST, 0, 0, 5);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:52:11: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
52 | crc = esp->request(CMD_REST_REQUEST, 0, 0, 3);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:53:9: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
53 | crc = esp->request(crc,(uint8_t*)&remote_instance, 4);
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp: In member function ‘uint16_t REST::getResponse(char*, uint16_t)’:
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:127:5: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
127 | esp->process();
| ^~~
| exp
C:\Users\Manoj Santani\Documents\Arduino\libraries\Arduino_Uno_WiFi_Dev_Ed_Library\src\lib\rest.cpp:133:12: error: ‘esp’ was not declared in this scope; did you mean ‘exp’?
133 | return esp->return_value;
| ^~~
| exp
Multiple libraries were found for “Servo.h”
Used: C:\Users\Manoj Santani\Documents\ArduinoData\packages\esp8266\hardware\esp8266\3.0.2\libraries\Servo
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\Servo
exit status 1
Error compiling for board Olimex MOD-WIFI-ESP8266(-DEV).
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
I am getting this error