Microcontroller projects

Programmimg ESPs

last updated: 09/05/19


Why this? There are already books and tutorials on the net. You can find e.g. a really useful guide from Pieter P on github.io.

But I work often with both microcontroller from Espressif, the ESP8266 and the ESP32. An I'm a forgetful man, an often search quite a long time to find back pieces of code already written and used in my projects. So here I will document pieces of code working for both ESPs.

Boards used

I often use the LOLIN (WEMOS) D1 mini pro. The MHEtLive ESP32MiniKit is small and nearly (RxD and TxD are interchanged) pin compatible with the LOLIN board and comes handy if we need a more powerful controller.

flash memory

In the middle of the picture we see the prior version of the LOLIN board named Wemos D1 mini pro.

Other ESP8266 and ESP32 boards should also work with the following software.


Let's start with the most important chapter :). Most boards have one or more built in LEDs. When no serial or UDP is possible, let's use the LEDs. Here four little helper functions:

    /********* LED helper functions *************************************BEGIN*/

    // build in LED on
    void LED_on() {
      digitalWrite(LED_BUILTIN,LOW); // LED on (negative logic)

    // build in LED off
    void LED_off() {
      digitalWrite(LED_BUILTIN,HIGH); // LED off (negative logic)

    // initialise the build in LED and switch it on
    void start_LED() {

    // blink LED_BUILTIN x times (LED was on)
    void blink_LED_x_times(byte x) {
      for(byte i=0; i<x; i++) { // Blink x times
        digitalWrite(LED_BUILTIN,HIGH);   // Off
        digitalWrite(LED_BUILTIN,LOW);    // On
    /********* LED helper functions ***************************************END*/

The LEDs on both boards are using negative logic! If the logic on your board positive, change the interchange HIGH and LOW.


Connect ESP to a router (Wifi station mode STA)

Using one network (SSID)