0. Chapter Ready (Important)

Before starting building the projects, you need to make some preparation first, which is so crucial that you must not skip.

0.1 Installing Thonny (Important)

Thonny is a free, open-source software platform with compact size, simple interface, simple operation and rich functions, making it a Python IDE for beginners. In this tutorial, we use this IDE to develop ESP32 during the whole process.

Thonny supports various operating system, including Windows、Mac OS、Linux.

Downloading Thonny

Official website of Thonny: https://thonny.org

Open-source code repositories of Thonny: https://github.com/thonny/thonny

Follow the instruction of official website to install Thonny or click the links below to download and install. (Select the appropriate one based on your operating system.)

Operating System

Download links/methods

Windows

https://github.com/thonny/thonny/releases/download/v3.2.7/thonny-3.2.7.exe

Mac OS

https://github.com/thonny/thonny/releases/download/v3.2.7/thonny-3.2.7.pkg

Linux

The latest version:

Binary bundle for PC (Thonny+Python):

bash <(wget -O - https://thonny.org/installer-for-linux)


With pip:

pip3 install thonny


Distro packages (may not be the latest version):

Debian, Rasbian, Ubuntu, Mint and others:

sudo apt install thonny


Fedora:

sudo dnf install thonny

You can also open “Freenove_Ultimate_Starter_Kit_for_ESP32/Python/Python_Software”, we have prepared it in advance.

../../../_images/Chapter00_09.png

Installing on Windows

The icon of Thonny after downloading is as below. Double click “thonny-3.2.7.exe”.

../../../_images/Chapter00_10.png

If you’re not familiar with computer software installation, you can simply keep clicking “Next” until the installation completes.

../../../_images/Chapter00_11.png

If you want to change Thonny’s installation path, you can click “Browse” to modify it. After selecting installation path, click “OK”.

If you do not want to change it, just click “Next”.

../../../_images/Chapter00_12.png

Check “Create desktop icon” and then it will generate a shortcut on your desktop to facilitate you to open Thonny later.

../../../_images/Chapter00_13.png

Click “install” to install the software.

../../../_images/Chapter00_14.png

During the installation process, you only need to wait for the installation to complete, and you msut not click “Cancel”, otherwise Thonny will fail to be installed.

../../../_images/Chapter00_15.png

Once you see the interface as below, Thonny has been installed successfully.

../../../_images/Chapter00_16.png

If you’ve check “Create desktop icon” during the installation process, you can see the below icon on your desktop.

../../../_images/Chapter00_17.png

0.2 Basic Configuration of Thonny

Click the desktop icon of Thonny and you can see the interface of it as follows:

../../../_images/Chapter00_18.png

Select “View” -> “Files” and “Shell”.

../../../_images/Chapter00_19.png ../../../_images/Chapter00_20.png

0.3 Installing CH340 (Important)

ESP32 uses CH340 to download codes. So before using it, we need to install CH340 driver in our computers.

Windows

Check whether CH340 has been installed

  1. Connect your computer and ESP32 with a USB cable.

../../../_images/Chapter00_21.png
  1. Turn to the main interface of your computer, select “This PC” and right-click to select “Manage”.

../../../_images/Chapter00_22.png
  1. Click “Device Manager”. If your computer has installed CH340, you can see”USB-SERIAL CH340 (COMx)”. And you can click here to move to the next step.

../../../_images/Chapter00_23.png

Installing CH340

  1. First, download CH340 driver, click http://www.wch-ic.com/search?q=CH340&t=downloads to download the appropriate one based on your operating system.

../../../_images/Chapter00_24.png

You can also open “Freenove_Ultimate_Starter_Kit_for_ESP32/CH340”, we have prepared the installation package.

../../../_images/Chapter00_25.png
  1. Open the folder “Freenove_Ultimate_Starter_Kit_for_ESP32/CH340/Windows/ch341ser”

../../../_images/Chapter00_26.png
  1. Double click “CH341SER.EXE”.

../../../_images/Chapter00_27.png
  1. Click “INSTALL” and wait for the installation to complete.

../../../_images/Chapter00_28.png
  1. Install successfully. Close all interfaces.

../../../_images/Chapter00_29.png
  1. When ESP32 is connected to computer, select “This PC”, right-click to select “Manage” and click “Device Manager” in the newly pop-up dialog box, and you can see the following interface.

../../../_images/Chapter00_30.png
  1. So far, CH340 has been installed successfully. Close all dialog boxes.

MAC

First, download CH340 driver, click http://www.wch-ic.com/search?q=CH340&t=downloads to download the appropriate one based on your operating system.

../../../_images/Chapter00_31.png

If you would not like to download the installation package, you can open “Freenove_Ultimate_Starter_Kit_for_ESP32/CH340”, we have prepared the installation package.

Second, open the folder “Freenove_Ultimate_Starter_Kit_for_ESP32/CH340/MAC/”

../../../_images/Chapter00_32.png

Third, click Continue.

../../../_images/Chapter00_33.png

Fourth, click Install.

../../../_images/Chapter00_34.png

Then, waiting Finsh.

../../../_images/Chapter00_35.png

Finally, restart your PC.

../../../_images/Chapter00_36.png

If you still haven’t installed the CH340 by following the steps above, you can view readme.pdf to install it.

../../../_images/Chapter00_37.png

0.4 Burning Micropython Firmware (Important)

To run Python programs on ESP32, we need to burn a firmware to ESP32 first.

Downloading Micropython Firmware

Official website of microPython: http://micropython.org/

Webpage listing firmware of microPython for ESP32: https://micropython.org/download/esp32spiram/

../../../_images/Chapter00_38.png

Firmware used in this tutorial is esp32spiram-20220117-v1.18.bin

This file is also provided in our data folder “Freenove_Ultimate_Starter_Kit_for_ESP32/Python/Python_Firmware”.

Burning a Micropython Firmware

Connect your computer and ESP32 with a USB cable.

../../../_images/Chapter00_39.png

Make sure that the driver has been installed successfully and that it can recognize COM port correctly. Open device manager and expand “Ports”.

../../../_images/Chapter00_40.png

Note

The port of different people may be different, which is a normal situation.

  1. Open Thonny, click “run” and select “Select interpreter…”

../../../_images/Chapter00_41.png
  1. Select “Micropython (ESP32)”,select “USB-SERIAL CH340 (COM4)”,and then click the long button under “Firmware”.

../../../_images/Chapter00_42.png
  1. The following dialog box pops up. Select “USB-SERIAL CH340 (COM3)” for “Port” and then click “Browse…”. Select the previous prepared microPython firmware “ esp32spiram-20220117-v1.18.bin “. Check “Erase flash before installing” and click “install” to wait for the prompt of finishing installation.

../../../_images/Chapter00_43.png
  1. Wait for the installation to be done.

../../../_images/Chapter00_44.png
  1. Close all dialog boxes, turn to main interface and click “STOP”. As shown in the illustration below

../../../_images/Chapter00_45.png
  1. So far, all the preparations have been made.

0.5 Testing codes (Important)

Testing Shell Command

Enter “print(‘hello world’)” in “Shell” and press Enter.

../../../_images/Chapter00_46.png

Running Online

ESP32 needs to be connected to a computer when it is run online. Users can use Thonny to writer and debug programs.

  1. Open Thonny and click “Open…”.

../../../_images/Chapter00_47.png
  1. On the newly pop-up window, click “This computer”.

../../../_images/Chapter00_48.png

In the new dialog box, select “ HelloWorld.py “ in “ Freenove_Ultimate_Starter_Kit_for_ESP32/Python/Python_Codes/00.0_HelloWorld “ folder.

../../../_images/Chapter00_49.png

Click “Run current script” to execute the program and “Hello World” will be printed in “Shell”.

../../../_images/Chapter00_50.png

Note

When running online, if you press the reset key of ESP32, user’s code will not be executed again. If you wish to run the code automatically after resetting the code, please refer to the following Running Offline.

Running Offline(Importance)

After ESP32 is reset, it runs the file boot.py in root directory first and then runs file main.py, and finally, it enters “Shell”. Therefore, to make ESP32 execute user’s programs after resetting, we need to add a guiding program in boot.py to execute user’s code.

  1. Move the program folder “ Freenove_Ultimate_Starter_Kit_for_ESP32/Python/Python_Codes “ to disk(D) in advance with the path of “ D:/Micropython_Codes “. Open “Thonny”。

../../../_images/Chapter00_51.png
  1. Expand “00.1_Boot” in the “Micropython_Codes” in the directory of disk(D), and double-click boot.py, which is provided by us to enable programs in “MicroPython device” to run offline.

../../../_images/Chapter00_52.png

If you want your written programs to run offline, you need to upload boot.py we provided and all your codes to “MicroPython device” and press ESP32’s reset key. Here we use programs 00.0 and 00.1 as examples. Select “boot.py”, right-click to select “Upload to /”.

../../../_images/Chapter00_53.png

Similarly, upload “HelloWorld.py” to “MicroPython device”.

../../../_images/Chapter00_54.png
  1. Press the reset key and in the box of the illustration below, you can see the code is executed.

../../../_images/Chapter00_55.png

0.6 Thonny Common Operation

Uploading Code to ESP32

Each time when ESP32 restarts, if there is a “boot.py” in the root directory, it will execute this code first.

../../../_images/Chapter00_56.png

Select “Blink.py” in “01.1_Blink”, right-click your mouse and select “Upload to /” to upload code to ESP32’s root directory.

../../../_images/Chapter00_57.png

Downloading Code to Computer

Select “boot.py” in “MicroPython device”, right-click to select “Download to …” to download the code to your computer.

../../../_images/Chapter00_58.png

Deleting Files from ESP32’s Root Directory

Select “boot.py” in “MicroPython device”, right-click it and select “Delete” to delete “boot.py” from ESP32’s root directory.

../../../_images/Chapter00_59.png

Deleting Files from your Computer Directory

Select “boot.py” in “00.1_Boot”, right-click it and select “Move to Recycle Bin” to delete it from “00.1_Boot”.

../../../_images/Chapter00_60.png

Creating and Saving the code

Click “File” -> “New” to create and write codes.

../../../_images/Chapter00_61.png

Enter codes in the newly opened file. Here we use codes of “01.1_Blink.py” as an example.

../../../_images/Chapter00_62.png

Click “Save” on the menu bar. You can save the codes either to your computer or to ESP32-WROVER.

../../../_images/Chapter00_63.png

Select “MicroPython device”, enter “main.py” in the newly pop-up window and click “OK”.

../../../_images/Chapter00_64.png

You can see that codes have been uploaded to ESP32-WROVER.

../../../_images/Chapter00_65.png

Disconnect and reconnect USB cable, and you can see that LED is ON for one second and then OFF for one second, which repeats in an endless loop.

../../../_images/Chapter00_66.png

0.7 Note

Though there are many pins available on ESP32, some of them have been connected to peripheral equipment, so we should avoid using such pins to prevent pin conflicts. For example, when downloading programs, make sure that the pin state of Strapping Pin, when resetting, is consistent with the default level; do NOT use Flash Pin; Do NOT use Cam Pin when using Camera function.

Strapping Pin

The state of Strapping Pin can affect the functions of ESP32 after it is reset, as shown in the table below.

../../../_images/Chapter00_67.png

If you have any difficulties or questions with this tutorial or toolkit, feel free to ask for our quick and free technical support through support@freenove.com at any time.

or check: https://www.espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf

Flash Pin

GPIO6-11 has been used to connect the integrated SPI flash on the module, and is used when GPIO 0 is power on and at high level. Flash is related to the operation of the whole chip, so the external pin GPIO6-11 cannot be used as an experimental pin for external circuits, otherwise it may cause errors in the operation of the program.

GPIO16-17 has been used to connect the integrated PSRAM on the module.

Because of external pull-up, MTDI pin is not suggested to be used as a touch sensor. For details, please refer to Peripheral Interface and Sensor chapter in “ESP32_Data_Sheet”.

For more relevant information, please click: https://www.espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf.

Cam Pin

When using the cam camera of our ESP32-WROVER, please check the pins of it. Pins with underlined numbers are used by the cam camera function, if you want to use other functions besides it, please avoid using them.

../../../_images/Chapter00_68.png

CAM_Pin

GPIO_pin

I2C_SDA

GPIO26

I2C_SCL

GPIO27

CSI_VYSNC

GPIO25

CSI_HREF

GPIO23

CSI_Y9

GPIO35

XCLK

GPIO21

CSI_Y8

GPIO34

CSI_Y7

GPIO39

CSI_PCLK

GPIO22

CSI_Y6

GPIO36

CSI_Y2

GPIO4

CSI_Y5

GPIO19

CSI_Y3

GPIO5

CSI_Y4

GPIO18

If you have any questions about the information of GPIO, you can click here to go back to ESP32-WROVER to view specific information about GPIO.

Or check: https://www.espressif.com/sites/default/files/documentation/esp32-wrover_datasheet_en.pdf.