Software for microcontrollers

FIRST OPTION: ARDUINO IDE

You will have available different microcontroller boards: classical 8-bit Arduino Uno rev. 3, SAMD21 32-bits Arduino MKR1000 WIFI, classical ESP 8266, classical ESP32 and the new ESP32-S3.

It is best to start to use Arduino IDE with all boards because it is one of the easiest way to work with microcontrollers, e.g. ESP32 with Arduino

There are several options from the simplest to the most complex for the development environment apart from Arduino IDE because as of July 2022 it seems compatible with ESP32-S3.

You can try to install in Arduino IDE boards ESP32 and ESP8266 at the URLs:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

https://dl.espressif.com/dl/package_esp32_index.json

http://arduino.esp8266.com/stable/package_esp8266com_index.json
For this course, we’ll be using the ESP32-S3 and ESP8266 boards. However, any other ESP32 with the ESP-WROOM-32 chip should work just fine according to Random Nerd Tutorial.

Another possibility is to try new Arduino 2.0 RC5 (release candidate) zip file (no admin rights to install) or a later stable software at arduino.cc official website following Rui Santos tutorial

For ESP 8266 you can make use of Arduino IDE

Among different possibilities you will use:

SECOND OPTION: PlatformIO IDE

PlatformIO IDE can be installed it as a plugin for Visual Studio Code (VS Code). It is compatible with more than 1000 boards and as of July 2022 it is compatible with  our brand new ESP32-S3 board from Espressif.

After launching VS Code, go to Extensions (Ctrl + Shift+ X) and search for platformio in the marketplace. This appears at the first place in the match list. Click on the Install button, and that is it. In a few minutes, the installation completes and we have PlatformIO installed in the VS Code IDE.

You are asked to install the latest version of Python and at the beginning of the installation to click ADD TO PATH and finally restart VS Code IDE.

1. Click on the PlatformIO icon in the left bar. It lists PlatformIO (or PIO for short) quick access links.

2. Select PIO Home/Open to navigate to the PlatformIO home page

3. You will need the information below:

platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0

Follow steps in Vedat manual (page 20…), Spanish  tutorial to install platformio

It is possible to combine Arduino IDE and PlatformIO IDE

Another different plugin is VisualMicro ESP32-S3 plugin for Visual Code Studio.

THIRD OPTION: ESP-IDF

Espressif IoT Development Framework (ESP-IDF) tools are the the chip manufacturer tool. They recommend to install it as a VS code plugin named “Espressif IDF” and when it is installed it appears in the left side menu of VS Code as the fingerprint Espressif logo. 

https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md

Please download the software by clicking the image below and you will be asked two times for administrator privileges.

The installation includes different tools and it is compatible with all Espressif board and it occupies near 3 Gb of computer memory.

Follow the official programming guide.

Here you have a “Hello world” example for the ESP32-S3 board.

How to use ESP-IDF

To start using ESP-IDF on ESP32 you’ll need the following software installed:

  • Toolchain to compile code for ESP32
  • Build tools – CMake and Ninja to build a full Application for ESP32
  • ESP-IDF that essentially contains API (software libraries and source code) for ESP32 and scripts to operate the Toolchain

FOURTH OPTION:

Micropython

 

FIFTH OPTION:

Circuitpython is compatible with over 300 microcontrollers including our boards.

Start learning circuitpython.

Connecting to  ESP32-S3 in circuitpython

Circuitpython creates a CIRCUITPY drive (your microcontroller) and it should be detected automatically by Mu Editor if connected using a USB data cable (not USB charging cable).

Remember that from Mu Editor version 1.1.1 (March 2022) you have a button named MODE where you can change in different modes: CircuitPython, ESP8266/ESP32, etc.

1) You could need to enter to bootloader mode by using the BOOT button a number of times or continously and in the computer must appear a new drive boardNameBOOT, e.g. ESP-BOOT.

Depending on the kind of hardware you have, it may also be possible to manually put your ESP32-S3 board into Firmware Download mode (reset). For development boards produced by Espressif, this information can be found in the respective getting started guides or user guides. For example, to manually reset a development board, hold down the Boot button (GPIO0) and press the EN button (EN (CHIP_PU)). For other types of hardware, try pulling GPIO0 down.

2) Lights flash and drive is converted to CIRCUITPY when you drag the UF2 file you downloaded to the boot drive on your computer.

2 bis) If you have any problem with the previous steps it is possible to download Microsoft MakeCode for Adafruit in order to flash UF2 (USB Flashing format) file to your microcontroller. UF2 is a binary data file  to be transferred from yout PC to a microcontroller, such as this UF2 file for ESP32-S3-N8R8  board (check if this is your microcontroller). UF2 files can be opened and edited using a variety of Microsoft MakeCode editors.

3) With a fresh CircuitPython install, on your CIRCUITPY drive, you’ll find a code.py file containing print("Hello World!") and an empty lib folder. If your CIRCUITPY drive does not contain a code.py file, you can easily create one and save it to the drive.

Mu attempts to auto-detect your board on startup, so if you do not have a CircuitPython board plugged in with a CIRCUITPY drive available, Mu will inform you where it will store any code you save until you plug in a board.

To avoid this warning, plug in a board and ensure that the CIRCUITPY drive is mounted before starting Mu.

If you are using Mu, click the Load button in the button bar, navigate to the CIRCUITPY drive, and choose code.py.

4) We can edit the code in order to flash a built-in LED (it works in many boards)


import board
import digitalio
import time

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.1)
    led.value = False
    time.sleep(0.5)

Open your code.py file into your editor. You’ll make a simple change. Change the first 0.5 to 0.1. Leave the rest of the code as-is. Save your file. See what happens to the LED on your board? Something changed! Do you know why?

People at Adafruit Industries are working hard to make their software compatible with ESP32 as you can see in this video

FREE BOOKS AND RESOURCES FROM RANDOMNERDTUTORIALS

SOLVING PROBLEMS:

Once you’ve loaded the code.py from Circuitpython, open the serial connection by clicking the Serial button within Mu. Once you click the button, a small terminal window should pop up beneath the editor. This displays the serial output from the microcontroller. Click the Save button in the editor, and you will pobserve that the print statement executed and is running in the serial output window.

Windows users can also use a program called PuTTY to establish a serial connection with a development board if they have problems using the serial terminal from within Mu. It’s available for download at www.chiark.greenend.org.uk/~sgtatham/putty/. PuTTY allows computers to communicate with each other with protocols such as Telnet and S SH. PuTTY can also communicate with virtual devices connected to the COM port to the computer. Once PuTTY is downloaded and installed, on your Windows computer, go to the Control Panel and open your Device Manager. Look for your  device under “Ports”. Take note of the port number associated with your board.Now you can use PuTTY to open a serial communication with your board. To do this, when you open PuTTY, set the connection type to Serial using the radio button. Enter the port (for example, COM3) in the Serial line box, set the Speed to 115200, then press Open.

PuTTY allows you to interact with your microcontroller in the same way that you interact with it from the serial terminal within Mu. Once a serial connection has been established between PuTTY and the microcontroller, you will see the output in a new window. PuTTY also allows you to access the REPL.

 SOLUTION: Burn the bootloader in Arduino IDE following Subero’s book.

https://github.com/PacktPublishing/Internet-of-Things-Projects-with-ESP32 to start using ESP-IDF with a blinking example.