Basic D-duino code (OLED, WifiManager)

In a previous blog post I introduced to you the D-duino ESP8266 boards. In this blog post, I’ll show you a small Arduino code which is providing the basic functionality for my next projects.

What’s in the box

I am using the awesome WifiManager library. I will handle the configuration and connection to a WiFi network. If  the ESP is unconfigured or the AP is not reachable, it will start an access point by its own. You can connect to this AP and a caption portal will open. Scan for networks, select one and enter the password. The configuration will be saved in the EEPROM. No need to set the credentials inside of your code.

Over-the-Air update is also implemented. This makes it very easy to update the code without connecting the MCU via USB to the host. It’s also faster than serial uploads.

Last part is of course the OLED display. I am using the ESP8266_SSD1306 library. It has some very nice features like progress bars, several graph commands (lines, shapes etc.), pictures and of text.

The Code

I am using platform.io for all my MCU projects. It has a full IDE based on the Atom editor and comes with things like code completion, a library/dependency manager and many other features like an integrated serial terminal.

Start by creating a new project. Select “Generic ESP8266 Module” as board.

After the project is created, copy the following contents to your platformio.ini. It’ll make sure that you can easily upload code via USB without using the flash button on the back (autoflash & reset). It will also configure the appropriate flash layout for the ESP-12F chip.

 

Now the main course. Create a new file “main.ino” and copy the following code.

Now connect your D-duino and build/upload the code. After the restart, the OLED display should come to life.

The WifiManager will now start an access point. The AP name is displayed. Connect to the AP and wait for the portal to come up. If the portal is not shown, open a web browser and go to 192.168.4.1. Select “Configure WiFi”, select your network and set the password. The D-duino will now try to connect.

You can now set the “upload_port” parameter in the platformio.ini to the shown IP to use OTA 🙂