2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
ESP32CAM IoT Tutorial 10
MicroPython Application Experience
Xiaozhi accidentally discovered that there is an emerging programming mode MicroPython, which can also be used to write applications for ESP32Cam, so he happily tried it out.
Xiaozhi accidentally bought an ESP32Cam from the store below, and got a batch of programming information from the customer service. He downloaded it to the computer and got the following files.
MicoPython, also known as microPython, is a very streamlined and tiny Python runtime environment (only more than 1M, burned into the ESP32Cam development board). We can operate the development board like operating Python on the computer, which is very convenient and effective!
Avoidance records:
After testing, it was found that the ESP32Cam burning base I bought before can burn the micropython firmware, but during use, Thonny cannot connect to ESP32Cam, so I need to buy a CH340 burner.
When using CH340 for burning, I found that the connection method provided on the Internet also had problems. The correct method should be to use the 5V interface for burning. It seems that burning cannot be done using the 3.3V interface.
First, install Thonny on your computer (it is included in the download file provided by the merchant). After the installation is complete, open the program.
Select Run - Configure Interpreter, select "MicroPython (ESP32)", and then select the port number of ESP32Cam (connect ESP32Cam as shown in the previous figure, and plug CH340 into the computer. If your computer successfully installs the CH340 driver, you can see this port number. Of course, you can also view the device port number of this CH340 in My Computer - Properties - Device Manager).
Then click “Install or update MicroPyhon” in the picture to burn the MicroPython firmware image file to the ESP32Cam development board.
In the dialog box that opens, select the device's port number and the image file (the bin file starting with MicroPython provided by the merchant), and select "Install" to burn. Wait until it reaches 100%, and the burning is complete, then you can close the dialog box.
Unplug Ch340 and ESP32Cam. Remove the ground connection wire between GPIO 0 and GND on the ESP32Cam. Reinsert it into the computer. At this time, we click on the device in the lower right corner of the window, and the program will refresh the connection status with the device. If the information shown in the figure appears in the debug window after the refresh, it means that the MicroPython in this ESP32Cam development board has been successfully started and successfully connected to the computer. (As mentioned earlier, due to problems with the design of the burning base of the ESP32Cam, there is no problem in completing the second step of burning the firmware, and it can be burned normally. However, at this time, the information in the debug window cannot be displayed, but a bunch of error messages, indicating that it is impossible to correctly connect and start MicroPython using the burning base, and you must buy another CH340 burner yourself)
We choose "Open" the file in the computer and select the camera test program file cameratest.py provided by the merchant.
Click the Run button at the top of the window, and you can see that the program in ESP32Cam is running in the debug window below. Click the three horizontal buttons of the MicroPython device in the file management on the left, and click "Refresh". You can see that there is an additional "First Picture.png" under this MicroPython device. This means that ESP32Cam has called the camera, captured a picture on the screen, and saved it to the internal storage of the ESP32Cam development board.
Right-click the file and choose to download it to a folder on your computer.
At this time, we lengthen the upper box of the file management on the left, and you can see the "first picture.png" downloaded from the ESP32Cam development board (of course you can also find this picture file in the corresponding folder of My Computer). Right-click the file and select "Open with external default program", and you can see this picture.
This program is just a test program provided by the merchant. When you take the first photo, and click the run button at the top of the window again to continue taking photos, the following error will appear in the debug window. At this time, you only need to right-click "First Picture.png" in the MicroPython device in the left window, then close Thonny and unplug the device. Wait for five or six seconds, then reopen the Thonny program, plug in the device, refresh the device connection, reopen this test file, click run, and you can take a new picture again.
4. Advantages and Disadvantages Analysis
MicroPython is a new programming mode for development boards. It installs a very simple Python runtime environment into the ESP32Cam development board, providing us with a mechanism to communicate with the computer. In this way, we can control the development board in the computer, just like writing Python programs. Of course, you can also write the completed program into the development board, so that the development board can run the program stored in the chip independently as long as it is powered on without the computer (like Python, after the chip is powered on, it will first run a program named "main.py" and execute instructions one by one from the main program "main(){}" in this program file. So the program we write into the development board should be named "main.py").
Since MicroPython has only been around for a short time and relies on image files, some of the available functions are not familiar to me, and there are relatively few application examples available online, so it is difficult to learn.
Of course, the biggest feature of Python is its inclusiveness, which can easily integrate the functions of various languages. With the increasing popularity of artificial intelligence technology, the development of MicroPython applications and development boards is an inevitable trend.
We are confident that in the near future, various MicroPython programming technology application examples will flourish and a hundred schools of thought will contend! This article is written superficially, just to start a discussion.