Tools

Esptool.py

Think of ‘esptool.py’ as a tool that helps you prepare and manage the microcontroller. It helps you by doing a few important tasks:

  • Installing MicroPython Firmware: Before your weather station can start its job, your microcontroller needs the right foundation to run your code. ‘Esptool.py’ is the tool for this job, as it installs the firmware. Think of firmware like the microcontroller's basic operating system that allows it to understand further instructions.
  • Flashing MicroPython: To make programming your weather station easier and more flexible, you'll use MicroPython, a version of Python designed for microcontrollers. With ‘esptool.py’, you flash MicroPython onto the microcontroller, giving it the ability to run your Python scripts. This is a crucial step to turn your microcontroller into a smart device capable of handling weather data.
  • Troubleshooting: Sometimes things don’t go as planned, and you might need to start over. ‘Esptool.py’ can erase everything on your microcontroller, so you can try again with a clean slate.

To install ‘esptool.py’, open the Terminal and run the pip install esptool command.

Esptool

Check if the ‘esptool.py’ is installed and works correctly by running esptool --port COMX flash_id.
Instead of “X” in the command, write the COM port number found next to your device in Device Manager.

Esptool2

After the command is executed, you will see some details about your microcontroller.

MicroPython Firmware

Before putting MicroPython firmware onto the ESP32 microcontroller, you should first erase the entire flash using esptool --port COMX erase_flash command.

Erase flash

Then download the ESP32 MicroPython firmware and save it to a location on your computer that you are familiar with. Finally install/flash the firmware onto your microcontroller with:

esptool --chip esp32 --port COMX write_flash -z 0x1000 X:\x\micropython.bin, where instead of “X:” and “x”, you should write your location to the micropython.bin file.

Info

In the context of microcontrollers and firmware, "flash" and "install" are terms often used interchangeably, but they refer to slightly different aspects of the process. I will not get into the details, as it doesn’t matter for the purpose of this tutorial.
Micropython firmware

Adafruit-ampy

Remember that your microcontroller doesn’t know what to do with the data collected from the sensors unless you give him a set of instructions. The instructions will be provided in the form of code saved within the files.

‘Adafruit-ampy’ is a simple command line tool that helps you send files to the microcontroller.

Install 'Adafruit-ampy' simply by pip install adafruit-ampy.

Adafruit

Setting up MobaXTerm for serial connection

A serial connection allows you to check if your code is uploaded correctly, debug your project, and interact with your microcontroller through a prompt. It's a key tool for making sure everything works as expected and for troubleshooting when things go wrong.

MobaXTerm is a versatile tool that provides a user-friendly environment to establish a serial connection between your computer and the microcontroller.

Download it from here, and install it by following the instructions.

After the installation is done, open the MobaXTerm app. The first thing to do is to create a session, which will be used to establish a serial connection. To create a session:

  • Click “Session” in the upper left corner of the app window. This opens the “Session settings” window.
  • In the “Session settings” window, click “Serial”.
  • Choose the serial port of your microcontroller and set the speed to 115200 (bit/s).
  • Click OK to connect to your microcontroller. Your session now appears under “User sessions” for future connections to your microcontroller.
MobaXTerm

If you’ve successfully connected to the microcontroller, the command prompt displays in the app window. Type print(”Hello World”) in the prompt and press Enter. In the next line, “Hello World” should be displayed.

MobaXTermTest

End the connection by pressing Exit in the upper right corner.