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;

  1. 32-bit RISC CPU
  2. 80mhz clock speed
  3. 64kb Instruction RAM
  4. 96kb Data RAM
  5. 4-8MB flash memory
  6. 16 GPIO pins including I2C and SPI
  7. I2S
  8. 1 ADC
  9. 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.

Setting Preferences

2. click on tools then select board manager, wait for it to update then scroll down and install the esp8266 boards.

Install 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