Introduction: Programming the ESP8266 WeMos-D1R2 Using Arduino Software/IDE
In this Instructable I will guide you through the steps needed to install, configure and program the WeMos-D1R2 board using the Arduino IDE.
WeMos-D1R2 is an ESP8266-12 based WiFi enabled microprocessor unit on a Arduino-UNO footprint. That means the board looks and works (in most cases) like an UNO. Apparently several shields, sensors and output devices that are manufactured for the Arduino platform will work on the WeMos-D1R2 with the added advantage of builtin WiFi.
There are two WeMos boards in the market.If you are not careful you will end up with a D1 Board which is an older version. You have to make sure you have the current version of the board WeMos-D1R2. I bought my WeMos-D1R2 from Banggood, I believe it is a Hong Kong based online retailer. The quality of the product is good and has a short delivery time, about two weeks to the US. They carry the genuine WeMos-D1R2. There are several older model WeMos-D1 being sold as WeMos-D1R2 to unsuspecting customers by several other vendors.
You will find several similarities between this Instructable and my previous one - Programming the ESP8266-12E using Arduino software/IDEbecause of the fact that the ESP8266-12 is the foundation of the WeMos-D1R2 board. In some cases I have copied and pasted the complete steps.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Differences Between the I/O Pins.
Though the Arduino UNO and the WeMos-D1R2 are similar, there are a few differences in their pin assignment. The above illustration provides the mapping of the pins. In some situations programs written for the UNO will need to be modified a little to the proper pin assignments of the WeMos-D1R2. More on this when we write our first sketch.
Step 2: Getting Started - Connect the WeMos-D1R2 to Your Computer
The WeMos-D1R2 board comes without an USB cable. Make sure you have a data cable and not a ordinary charging cable. A data cable causes your Windows OS to react. It announces the attachment of a new hardware and tries to install the USB drivers. It either finds the driver on your system or it does not. If it does not then you will need to download the USB drivers. The USB interface chip is the CH340G. You will need to install the drivers for this chip.
A Google search for the "CH340G drivers" finds several sites. You can download the Windows 7 drivers from here or the Windows 8 from here. Though I have not tried them, other operating systems can be downloaded from here. Some flavors of Windows operating system come with the drivers.
Step 3: Is the WeMos-D1R2 Happily Communicating With Your Computer?
Lets find out if the WeMos-D1R2 and your computer are communicating with each other. Getting this step right is important for any further action. Open the Device Manager via Control Panel| Hardware and Sound.
Step 4: Installing Arduino Software/IDE
I downloaded the most current Arduino software (Version 1.6.8) from here. It is a Windows installer exe file so double clicking on it will start the installation including the installation of several peripheral drivers. You can find detailed instructions to install the Arduino software here.
Once the Arduono software is installed, I tested the install by connecting an existing Arduino Uno that I had and uploaded the Blink sketch. All systems worked as they were supposed to.
Step 5: Where to Find the Arduino IDE Preferences Dialog
You will need to familiarize yourself with the File| Preferencesdialog box. We will need this info later.
Step 6: Where to Find the Arduino IDE Boards Manager Dialog
You will also need to know about the Tools | Board:… | Boards Manager dialog box. You have an older version of Arduino software if you cannot see Board Manager in the menu. Go update your software.
Step 7: Telling Arduino Where to Find the Wemos-D1R2 Library
The WeMos-D1R2 board can be added to the Arduino software/IDE by installing the necessary libraries. This community supported Github page: Unofficial list of 3rd party boards support has the information needed to get your Arduino software to support the WeMos-D1R2. Search/look for “ESP8266” on this webpage. Look for the URL shown in the image above. Copy and paste that URL into your Preferences dialog and select OK. Else you can copy the following and paste into your Preferences dialog and select OK: http://arduino.esp8266.com/stable/package_esp8266com_index.json Either case do not click on the URL.
Step 8: Installing the WeMos-D1R2 Board Via the Board Manager
Open Tools | Board:|Boards Manager dialog box. Somewhere in there you will see the entry “esp8266 of ESP8266 Community version 2.1.0” select that. The Install button will appear, click the Install button. Wait for a while… This process will take some time to download and complete. After the install it is a good idea to shut the Arduino program and restarted it.
Step 9: Determining the COM Port WeMos-D1R2 Shows Up On
If not connected connect the Wemos-D1R2 board to your computer. Give it a couple of minutes to get to know the computer. Go to Control Panel| Hardware and Sound| Device Manager and click on Ports (COM & LPT). There you will find the port number that your Wemos-D1R2 is connected on. In my case it is COM12. Make a note of that, we need this info later.
Step 10: Selecting the WeMos-D1R2 Board
Go to Tools | Board:… scroll way down and select WeMos D1 R2 & mini. The Tools menu changes to the second image shown above.
Step 11: Configuring COM Port
In a Step 9 we had determined the COM port WeMos-D1R2 appears on. To select the COM port, go to Tools | Port: and select the COM port, in my case it was COM12.
Step 12: Configuring COM Port Speed
To select the speed of communication between the WeMos-D1R2 and the computer. Go to Tools | Upload Speed: and select 115200. We are ready to upload our first sketch.
Step 13: Test Drive the Setup
Test drive the complete setup using the boiler plate sketch.
To upload the boiler plate sketch go to Sketch | Upload or use the shortcut key Crtl+U or click on the right arrow button next to the check mark. A successful compile and upload means all systems are working and we are ready to get to the real stuff.
Step 14: Trying the Blink Example
Load the packaged example Blink. To find it go to File | Examples | 01.Basics | Blink. Compile and upload as instructed in the previous step. Nothing happens. :(
The reason nothing happens is because the on board LED on the UNO is connected to pin 13. Refer to the table in Step 2. On the WeMos-D1R2 the on board LED is connected to pin 14.
Replace all instances of pin 13 with pin 14 and save the sketch as WeMosBlink. Compile and upload as instructed in the previous step. Viola the blue LED starts blinking.
Replace all instances of pin 13 with pin 2 and save sketch. Compile and upload as instructed in the previous step. The blue LED on the ESP8266-12 module starts blinking.
Disconnect the WeMos-D1R2 from your computer and connect an external 5V power source. I connected it to the power bank that I use to charge my phone. The LEDs will start blinking.
We aren't WiFing yet. That will be in the next Instructable. Time permitting I will write one soon. If you feel motivated enough try adopting my previous Instructable Programming a HTTP Server on ESP-8266-12E to the WeMos-D1R2 and update me in the comments.