Encounter with ESP 32 — Micro-controller

Murali Krishnan Mani
3 min readFeb 20, 2020

--

I recently had an opportunity to read about an article on Micropython. I was amazed with the fact that embedded systems can be coded in Python (interpreter language), when it used to be in C language. I was inspired by that fact and wanted to try out some bit and get my hands dirty to understand the capabilities. I ventured out with some simple experiments during the Christmas break and eventually ended up doing a real-time use case for home automation in less than a month!!!

  1. Device Cost: Approximately £7 from Amazon + Relay Board to control 220 v device is £5
  2. Low on power utilization — 5 Volts and goes on intelligent power saving mode (can be controlled programmatically)
  3. Communication: Wifi & Blue Tooth enabled devices, Supports MQTT protocol for communication with other IoT enabled devices/ gateway
  4. Communication: ESP-NOW communication protocol with other ESP devices (220 meters remote)

I used Raspberry PI 2 for installation / setup on the ESP 32 device, however Windows / Mac can also be used as the host computer for the setup.

Step 1: Install required s/w on the host device (Raspberry PI 2 in my case) so that you can interact with ESP 32 board.

pip3 install esptool #Install esptool
pip3 install rshell #Install rshell to interact with ESP 32 board

Step 2: Download the Micropython Firmware specific specific to the device

wget http://micropython.org/resources/firmware/esp32-idf3-20200125-v1.12-87-g96716b46e.bin

Step 3: Flash ESP 32 device with latest firmware (before this step connect ESP 32 device to the PI’s USB port)

esptool.py — chip esp32 — port /dev/ttyUSB0 — baud 460800 write_flash -z 0x1000 esp32-idf3–20200125-v1.12–87-g96716b46e.bin

Step 4: Once the flashing is completed, which takes couple of minutes to load the firmware, you can logon to the board using the rshell installed earlier

rshell — buffer-size=30 -d -p /dev/ttyUSB0

pyboards (lists down the boards connected)

Step 5: Execute simple commands through REPL — Read Evaluate Print Loop (an interactive MicroPython prompt for ESP32 or ESP8266 family of devices).

repl (command in the rshell opens up a prompt where in MicroPython commands can be issued)

Simple set of statements to blink an in-built LED light is as mentioned below.

from machine import Pin
p1 = Pin(2, Pin.OUT)
p1.value(0)
p1.value(1)

The most obvious first time experiment for anyone using the ESP32 device would be Garage Door. It happened to me to be as well!! The cost to enable remote control access for door opening and closing was quoted to be £160 by the vendor (Liftboy). I was able to automate with an investment of £12, a saving of £148!!!

I had downloaded the WebServer code from the following link and customized for my specific needs. It was pretty straightforward to change the boot.py (manage your Wifi connection) main.py (Websocket + GPIO controls).

The schematic for the implementation as mentioned below.

Conclusion: It was quiet simple to start ESP 32 devices and the potential of such low cost device in the space of IoT & Industrial IoT is phenomenal. The solution development cost & effort would also be low. Would explore more devices like ESP32-CAM or similar devices in this space.

--

--

Murali Krishnan Mani

A technology enthusiast, interested to learning new evolving technologies and apply them to resolve business critical problems.