Hello colleagues and enthusiasts!

For the last couple of years, I have been doing almost all the prototyping of simple IoT devices on the NodeMCU, although it is often large in size, expensive, and redundant in functionality. And all because I had a bad experience with the ESP-01, which did not lend itself to firmware at all. Now it’s time to overcome this barrier and master other pieces of iron, from which I need the following – Wi-Fi and pins for connecting peripherals.

In this article, we will analyze the connection to the IoT platform of the most popular boards with a Wi-Fi interface. They can be used to control your device remotely or to take readings from sensors over the Internet.

Several modules (ESP-01, ESP-07, ESP-12E, ESP-12F) and boards (Goouuu Mini-S1, WeMos D1 mini and NodeMCU V2) presented in the article are based on the ESP8266 controller, the use of which allows you to easily and cheaply add to your device wirelessly via Wi-Fi.

This is how the lineup of modules based on the ESP8266 chip looks like.

The last board of those that I will talk about (ESP32 WROOM DevKit v1) is built on the controller of the ESP32 family – a more advanced version of the ESP8266 in terms of its capabilities.

All models shown can be programmed and uploaded via the Arduino IDE in the same way as with the Arduino.

Setting Up the Arduino IDE Programming Environment

By default, the IDE is configured for AVR boards only. For the platforms below, additional support must be added to the board manager.

1) Open the Arduino IDE programming environment.

2) In the menu item File (File) select Preferences (Settings). In the Additional Boards Manager URLs window, enter addresses separated by commas

3) Click OK.

4) In the menu item Tools (Tools) -\u003e Board (Board) select Boards manager (Manager boards).

We find the platform on the ESP8266 in the list and click on the Install button.

6) The inscription INSTALLED reports that the add-ons have been successfully installed.

7) Install the add-on for ESP32 in the same way.

8) Now we have access to platform programming with the ESP8266 and ESP32 module.

9) To connect the boards to the IoT platform, we use the EspMQTTClient library. To install it, in the menu item Tools (Tools) select Manage Libraries (Manage libraries). Find and install the EspMQTTClient library. You may see a message about installing additional libraries. Select “Install all”.

Note – Also, to work with the boards, you will need to install the CH340 drivers (WeMos and Goouuu) and CP2102 (for the rest). Their absence will affect whether the Arduino IDE finds the COM port that the board is connected to.

Firmware code

To flash all the modules used below, we use the same code.

Main functions:

Setting up a Wi-Fi connection

Connecting to an object on the Rightech IoT Cloud platform via the MQTT protocol

Sending random values ​​for temperature (“base/state/temperature”) and humidity (“base/state/humidity”) every 5 seconds (PUB_DELAY)

Receiving light switching messages (“base/relay/led1”)

#include “Arduino.h”

#include “EspMQTTClient.h” /* https://github.com/plapointe6/EspMQTTClient */

                           /* https://github.com/knolleary/pubsubclient */

#define PUB_DELAY (5 * 1000) /* 5 seconds */

EspMQTTClient client(

  “<wifi-ssid>”,

  “<wifi-password>”,

  “dev.righttech.io”,

  “<ric-mqtt-client-id>”

);

void setup() {

  Serial.begin(9600);

}

void onConnectionEstablished() {

  client.subscribe(“base/relay/led1”, [] (const String &payload) {

    Serial println(payload);

  });

}

long last = 0;

void publishTemperature() {

  long now = millis();

  if (client.isConnected() && (now – last > PUB_DELAY)) {

    client.publish(“base/state/temperature”, String(random(20, 30)));

    client.publish(“base/state/humidity”, String(random(40, 90)));

    last=now;

  }

}

void loop() {

  client loop();

  publishTemperature();

}

ESP8266 based modules

There are two options for working with modules based on ESP8266:

Work with AT commands (in the standard Wi-Fi firmware, the module communicates with the control board through “AT commands” using the UART protocol);

Wi-Fi module as an independent controller (all presented modules are very smart: a whole microcontroller is hidden inside the chip, which can be programmed in C ++ via Arduino IDE).

In the article we will consider the second option – firmware modules in the form of an independent full-fledged device. There are also two firmware options in terms of hardware:

Through the Arduino board;

Via USB to serial adapter.

Consider the second option – to use an adapter based on the CP2102 chip (for example, https://www.chipdip.ru/product/cp2102-usb-uart-board-type-a?frommarket=https%3A%2F%2Fmarket.yandex. ru%2Fsearch%3Frs%3DeJwzSvKS4xKzLI&ymclid=16146772489486451735000001). Be sure to pay attention to the fact that the adapter allows you to produce an output voltage of 3.3 V, no more!

1.ESP-01

ESP-01 is the most popular module on ESP8266. The PCB antenna provides a range of up to 400 m in open space.

Appearance

Energy supply

The module’s native voltage is 3.3V. Its pins are not 5V tolerant. If you apply a voltage higher than 3.3V to a power, communication, or I/O pin, the module will fail.

Connecting peripherals

2 general purpose I/O ports

Pinout

Connecting to IoT

Hardware

1) We collect the scheme

RST, GPIO 2 – not connected

RTS, CTS – not connected

2) We switch to the programming mode (it is necessary to perform each time before flashing the module)

2.1) Turn off the power from the module

2.2) Connect GPIO pin 0 to GND

RTS, CTS – not connected

2.3) Connect the module to power

2.4) The hardware is ready, let’s proceed to the software part.

Software part

1) Select the board: Tools (Tools) -> Board (Board) Generic ESP8266 Module.

2) Paste the prepared code.

3) Set the data for the Wi-Fi connection and the identifier of your object on the platform.

4) Compile and upload the sketch to the board.

Leave a Reply

Your email address will not be published. Required fields are marked *