Esp32 environment construction and entry programming

Some treasure bought an esp32, as well as an esp32 development guide book.

And then there’s the setting up of the environment. It is mainly written on Linux. I have built it on my orange PI PC development board for half a day, but there are still some problems in the back, which are not solved properly. After all, the price of a orange pie is so low, and the price of adding a display screen is not high. Moreover, it can also be used for hardware programming and learning various kinds of programming. Although the speed is a little slow, the entry-level is absolutely enough. Of course, if those A80 and rk3399 can be cheaper, at least they can be cheaper than microcomputers.

So, I changed the environment of window. There was an esp8266, which was used to play with microphoton. Now, if you want to learn esp32 programming, you have to start over in addition to using micropython. And I haven’t used eclipse very much before. It took me a long time to figure out after setting up the environment.

Now I’ll give you a brief introduction.

1: Win environment

I directly downloaded the integrated development environment of Anxin Ke (esp8266 was used by Anxin before, so I found it and it really supports esp32). On the official website of Anxin, find the development environment below: how to install the integrated development environment of Anxin, how to use the integrated development environment of ESP series, and how to burn firmware for ESP series modules

Click in and download the file of the network disk according to the tutorial, and then download the ESP IDF. You can download git with cygwn software in the downloaded software, that is, aithinkeride under the download directory_ In v0.5 / cygwin Cygwin.bat , click open directly as follows:

The usage is the same as the command terminal under Linux. This is recommended for git download, because I found that there are several direct download points on the GitHub of esp32, which cannot be downloaded, but can be downloaded by git clone. For example, there is a NES game simulator written in esp32!

CD to the file directory you want to download and type git clone — recursive https://github.com/espressif/esp-idf Please note that git clone must add — recursive, otherwise all modules in the components directory cannot be pulled. CD in, LS enter, you can see the directory, as follows:

L components: the core component of esp-idf

L doc: esp-idf related documents

Examples: the sample program provided by esp-idf, including many peripheral devices, Wi Fi, Bluetooth, etc

L make: eps-idf project management directory

L tools: tool set provided by esp-idf

Then it’s better to create an app folder and put git into it.

The whole process is as follows:

  Esp32 environment construction and entry programming_ Esp32 pin diagram

App folder is your own to run the main file, you can later write your own things. In this example, you can do it without downloading the ESP IDF template.

The last line is used to make up for the missing module (I see it from the Internet anyway, just follow it.)

Then, click the previous ide file and double-click to open esp_ IDE.exe , the first two are in the current directory, you can open one by one, and the third is the directory of the ESP IDF file you just downloaded. Just go to the folder you downloaded called ESP IDF.

  Esp32 environment construction and entry programming_ Esp32 pin diagram

Okay, here comes the big picture.

Just click on aithinker_ IDE.exe Open eclipse, and then click Import in the blank space on the left to load your ESP IDF project. Detailed steps can refer to the network. (I copied the whole folder to a folder and opened it again, the same thing.)

Then, right-click the general directory of the project on the left side (not a good screenshot) is to right-click the ESP IDF directory, select the property option at the bottom, and modify the following address on the right side of C / C + + build to become the place where you put the Min function (such as the app created before, pay attention to the folder contained in the app folder after downloading).

  Esp32 environment construction and entry programming_ Esp32 pin diagram

Then, right-click on the left side of the general catalog

Select the create option in make targets and add the following

  Esp32 environment construction and entry programming_ Esp32 pin diagram

In the same step, create another build:

  Esp32 environment construction and entry programming_ Esp32 pin diagram

Before compiling, press Shift + F9 to call up an option,

  Esp32 environment construction and entry programming_ Esp32 pin diagram

After selecting build, the compiler will jump out of an interface. Generally, you just need to choose exit directly.

Then you can directly right-click the general project directory on the left and select build project (if you have built before, remember to clean it).

Well, that’s how it works for a project.

How do you write your own program?

Let’s start by modifying the routine.

Add ~ \ ESP IDF / examples / get started / Hello_ Copy all the files (three files) under the world to the app directory you just created, select overlay paste, and then right-click the general directory on the left, and select refresh to update it. Now you can also compile, but it is someone else’s. (the compilation time is too long, if you want to test your own code, you’d better modify it first.) This is the basic procedure for writing a program later. If you want to change the name, you can go to the makefile file to change it (you may have to change it in other places, so you can find out for yourself).

Its code is as follows:

1 /* Hello World Example

Two

3 This example code is in the Public Domain (or CC0 licensed, at your opTIon.)

Four

5 Unless required by applicable law or agreed to in wriTIng, this

6 software is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR

7 CONDITIONS OF ANY KIND, either express or implied.

8 */

9 #include 《stdio.h》

10 #include “freertos/FreeRTOS.h”

11 #include “freertos/task.h”

12 #include “esp_ system.h”

13 #include “esp_ spi_ flash.h”

Fourteen

Fifteen

16 void app_ main()

17 {

18 printf(“Hello world! \N ‘); / / serial port printing

Nineteen

20 /* Print chip information */

21 esp_ chip_ info_ t chip_ info;

22 esp_ chip_ info(&chip_ info);

23 printf(“This is ESP32 chip with %d CPU cores, WiFi%s%s, ”,

24 chip_ info.cores ,

25 (chip_ info.features & CHIP_ FEATURE_ BT) ? “/BT” : “”,

26 (chip_ info.features & CHIP_ FEATURE_ BLE) ? “/BLE” : “”);

Twenty-seven

28 printf(“silicon revision %d, ”, chip_ info.revision );

Twenty-nine

30 printf(“%dMB %s flash\n”, spi_ flash_ get_ chip_ size() / (1024 * 1024),

31 (chip_ info.features & CHIP_ FEATURE_ EMB_ FLASH) ? “embedded” : “external”);

Thirty-two

33 for (int i = 10; i 》= 0; i–) {

34 printf(“Restarting in %d seconds.。。 \n”, i);

35 vTaskDelay(1000 / portTICK_ PERIOD_ MS);

36 }

37 printf(“Restarting now.\n”);

38 fflush(stdout);

39 esp_ Restart(); / / restart option

40 }

Refer to the example of GPIO under example, and modify it as follows:

  Copy code

1 * Hello World Example

Two

3 This example code is in the Public Domain (or CC0 licensed, at your option.)

Four

5 Unless required by applicable law or agreed to in writing, this

6 software is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR

7 CONDITIONS OF ANY KIND, either express or implied.

8 */

9 #include 《stdio.h》

10 #include “freertos/FreeRTOS.h”

11 #include “freertos/task.h”

12 #include “esp_ system.h”

13 #include “esp_ spi_ flash.h”

Fourteen

Fifteen

16 #include 《string.h》

17 #include 《stdlib.h》

18 #include “freertos/FreeRTOS.h”

19 #include “freertos/task.h”

20 #include “freertos/queue.h”

21 #include “driver/gpio.h”

Twenty-two

23 #define GPIO_ OUTPUT_ IO_ LED 2

24 #define GPIO_ OUTPUT_ PIN_ SEL ((1《《GPIO_ OUTPUT_ IO_ LED) )

25 int i=0;

26 void app_ main()

27 {

Twenty-eight

29 / / initializes the GPIO pin and copies it directly from the GPIO example

30 gpio_ config_ t io_ conf;

31 //disable interrupt

32 io_ conf.intr_ type = GPIO_ PIN_ INTR_ DISABLE;

33 //set as output mode

34 io_ conf.mode = GPIO_ MODE_ OUTPUT;

35 //bit mask of the pins that you want to set,e.g.GPIO2

36 io_ conf.pin_ bit_ mask = GPIO_ OUTPUT_ PIN_ SEL;

37 //disable pull-down mode

38 io_ conf.pull_ down_ en = 0;

39 //disable pull-up mode

40 io_ conf.pull_ Up_ en = 0;

41 //configure GPIO with the given settings

42 gpio_ config(&io_ conf);

Forty-three

Forty-four

45 printf(“Hello world! \n”);

Forty-six

47 /* Print chip information */

48 esp_ chip_ info_ t chip_ info;

49 esp_ chip_ info(&chip_ info);

50 printf(“This is ESP32 chip with %d CPU cores, WiFi%s%s, ”,

51 chip_ info.cores ,

52 (chip_ info.features & CHIP_ FEATURE_ BT) ? “/BT” : “”,

53 (chip_ info.features & CHIP_ FEATURE_ BLE) ? “/BLE” : “”);

Fifty-four

55 printf(“silicon revision %d, ”, chip_ info.revision );

Fifty-six

57 printf(“%dMB %s flash\n”, spi_ flash_ get_ chip_ size() / (1024 * 1024),

58 (chip_ info.features & CHIP_ FEATURE_ EMB_ FLASH) ? “embedded” : “external”);

Fifty-nine

60 // for (int i = 10; i 》= 0; i–)

61 while(1)

62 {

63 //printf(“Restarting in %d seconds.。。 \n”, i);

64 vTaskDelay(1000 / portTICK_ PERIOD_ MS); / / delay

65 printf(“I am ZhiNianZhiZhan! \n”);

66 printf(“Try To Study ESP32\n”);

67 gpio_ set_ level(GPIO_ OUTPUT_ IO_ LED, I% 2); / / turn the LED on the board continuously to make IO flash

68 i++;

69 if(i》499)i=0;

70 }

71 //printf(“Restarting now.\n”);

Seventy-two

73 //fflush(stdout);

74 //esp_ Restart(); / / restart the function. If it is blocked, it will not restart.

75 }

Next, build. A long wait….. . build successfully will display the following:

After the build is successful, it is downloaded.

You can find the address on the official website of Lexin, open it after downloading, select esp32 to download, and then the interface is as shown in the figure below. Select the firmware according to the following, fill in the corresponding address, select the serial port, and click to download.

1. 2 and 3 are to select the. Bin file and download address to download (the address should not be mistaken). The three files are all in the build folder.

Click in. There are so many folders?

Don’t worry. First, select the bootloader in the build folder bootloader.bin Put a tick in the front and fill in 0x1000 at the back,. Then the second and third are all in the build directory, just two. Remember partitions_ singleapp.bin Fill in the address of 0x8000, your main file. Bin (here is hello- world.bin )Fill in the address of 0x10000.

Then, select the following options (the default should be), and then fill in the COM port according to the serial port number of the USB port inserted into your board (if you don’t know or the driver is not installed, just Baidu, you can plug in and use the driver wizard to install the driver, and then check the com number in the device management).

Finally, click download. The latest downloader does not need to press the button on the board, it downloads itself.

After the download is completed, the word “finish” will appear in the lower left corner of the downloader. Then you can connect the serial port, or press the en key on the board directly. When the blue light flashes and the serial port continuously outputs two lines of characters, the whole step is successful.

Of course, you can also see the serial output. Like serial hunters. I use SecureCRT, which is very easy to use. I can directly use it as an interactive interface. However, software such as serial port hunter can’t work or it’s difficult to input. Recommend this, can baidu search.

Esp32 pin diagram

Esp32 environment construction and entry programming_ Esp32 pin diagram

Esp32 environment construction and entry programming_ Esp32 pin diagram

Esp32 environment construction and entry programming_ Esp32 pin diagram

Recommended reading:

Which is better, esp32 or STM32_ Esp32 vs. esp8266

What language is esp32 programmed in_ Construction of SP32 development environment


Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *