laitimes

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

author:APPLE频道

Video loading...

01 Radio rail

1. Problem/Goal

  This ESP32 control board is the core of the wireless rail trolley, after it is connected to the computer, you can practice MicroPython programming through several small experiments, which can lay the foundation for the debugging of the back trolley, through this process, you can gradually familiarize yourself with the ports on the control board, and look at the development and testing of several basic applets below.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

Second, the basic principle

  Using ESP32 to control the LED, buttons and OLED screen on the board, you need to know the corresponding ports of these peripherals. This is the definition of the ESP32 external port, LED1 to IO2. The two keys step into levels IO25, IO26. Here are the ports corresponding to the five control signals of the OLED screen. Also, find their respective positions on the board. From the front of the circuit board, LED1 corresponds to the screen surface of D1, two buttons are on the right side of the circuit board, and this 7-pin socket is used to fix the OLED screen.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  According to the schematic, if the LED1 port is low, the corresponding LED is on, and when it is high, the LED is off. The two button ports are set high by two pull-up resistors, and when pressed, the corresponding IO port level is low. The OLED port on the right is used to connect an external 128 ×64 LCD screen.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

3. Application examples

1. LED flashing

  In the given data, a Python program containing a Test LED,

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  This is the code of the program. The modules that need to be used after the first two lines of the program import are a Pin module for pin control and a time module for timing. Use the Pin class to declare an LED0 object with two parameters. The first parameter indicates the serial number of the IO pin, and it is just now known from the schematic that LED1 is connected to IO2. The second pin defines the input-output properties of that pin. This is defined as the output pin, which drives the LED. The following uses the object function value to set the state of this pin. 1 for high and 0 for low. The second half of the program is a while loop structure, and since the condition is always TRUE, this loop is executed until the break instruction is encountered, or the program has an error. Use the if else statement below to change the state of the LED. The value function is applied earlier to read the status of the LED, and when it is 0, set it to 1. Otherwise, set to 0. Therefore, this operation is to change the state of the LED. Each cycle pauses for 0.5 seconds, so the LED changes to light up every second.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  Copy the program to the program editing window above Thonny and start the program run through the menu Run command.

  Once the program is running, the LED starts blinking. If you change this delay time, for example to 0.25 seconds, and reload the program runs, you can observe that the LED blinking frequency doubles.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

2. Button test

  Keys on the board can be used to enter temporary commands, such as opening or stopping program execution. These two buttons are located on the right side of the board.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  Procedural and very simple. The first two sentences are still input PIN and time software modules. Next, use the Pin declaration to measure the pins, the previous numbers represent the IO port serial numbers of the two keys connected to ESP32, and the following parameters indicate the attributes of the pin, input ports. Followed by a while loop body that reads the state of the two keys via value, using print to display in the Shell window in the Thonny development environment. The key level is high, returns 1, otherwise returns 0. According to the schematic, we know that when the button is pressed, the corresponding pin is low. Through the sleep function of time, the control cycle is 1 second, so after the program runs, the key status is displayed every second.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  Copy the program to run in the Thonny environment, you can see that the shell window outputs a line of numbers every second, the key is not pressed, the number is 1, when the key is pressed, the corresponding number is 0. Therefore, by judging the level of the pin, you can know whether the corresponding button is pressed, so that the execution process of the program can be controlled.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

3. Test OLED

  If more information needs to be displayed, it is more convenient to use OLED. The OLED in the development kit is a 128 by 64 dot matrix OLED display that can display characters, graphics, etc. The OLED screen has seven pins that can be inserted into sockets on the circuit board. Once connected, it can be tested by the program.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  Since the OLED program is more complicated, the following is a brief introduction to the steps of the test. The program involves two files, one is the previous OLED096 and the other is the test oled file. The OLED096 file contains the screen driver function, which is called by the test oled program. You will need to load both files into the ESP32 device. First create a new file in Thonny Letter, copy the contents of the OLED096 file to the program editing interface. Then store. Select a MicroPython device when storing, and the file name of the stored file is LQ_OLED096. Note that this name cannot be changed. If the stored procedure shows that the device is busy, you can press "STOP" to stop the ESP32 program from running. Next, create a new file, copy the content of the TEST OLED program into the edit box, and then execute the software. If there are no errors in the Shell window, the program is running normally.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

  After the program is running, you can observe the test information displayed on the OLED screen, and there is an incrementing number below The OLED screen can see the corresponding yellow and blue characters if it is bicolored. At this point, the OLED program has been tested. If you are interested in the corresponding program, you can study the code in the two files yourself.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

IV. Summary

  This article gives three basic test experiments of ESP32-based control board, through these experiments, everyone is familiar with the development of MicroPython programs on the development board, laying the foundation for later development and modification of intelligent car programs, and it is recommended that you complete more tests on the basis of being familiar with the schematic diagram of the development board.

Wireless Rail Smart Car School Race| How to do preliminary programming tests on ESP32?

02Lecture materials

1. Lecture video

2. Lecture materials

  • Tsinghua Cloud Disk Data Download[1] : https://cloud.tsinghua.edu.cn/d/7471180bdb0f4d1ebbc7/
  • Wireless Rail Smart Car School Race| How to learn radio rail model? [2]
  • Learn Python[3] : https://www.learnpython.org/

Resources

[1]

Tsinghua Cloud Disk Data Download: https://cloud.tsinghua.edu.cn/d/7471180bdb0f4d1ebbc7/

[2]

Wireless Rail Smart Car School Race| How to learn radio rail model? : https://zhuoqing.blog.csdn.net/article/details/131876635

[3]

Learn Python: https://www.learnpython.org/