This tutorial will show how to edit the C code that gets generated by using the Waijung2 block-set. The user will also be introduced to ESP-IDF development environment as well.
Step1: Setup ESP-IDF Command Console
This tutorial will use the ADC demo for the demonstration. Check How to use demo file?
Step 1: Build the model file.
First set the Build Options to Generate code in the Waijung2_target setup block. By setting this option the C code will be generated but will not get uploaded to the ESP32 board.
Use the 'Build' button in Matlab Simulink to build the current model. This will generate the C code and relevant build files in the Matlab 'Current Folder'.
Step 2: Open the generated C code from your favorite editor.
The following three C files are responsible for the program generated by your Matlab model file.
Step 3: Edit the C code.
Open the esp32_adc_demo.c file. We are are going to change the threshold from which the LED status is determined. Current value is set to 2047 from Matlab. Change it to 3000 as shown in the image.
Step 1: Open pre-configured CMD in Setup ESP-IDF
Step 2: Change the directory to the esp32_adc_demo_esp32_build_system folder
cd [adc_demo_folder_path]\esp32_adc_demo_esp32_build_system
Step 3: Compile and Upload code
Type the following command in the CMD window.
idf.py -p COM[COM port number] flash
•To upload and monitor the program.
idf.py -p COM[COM port number] flash monitor
•To just monitor the program.
idf.py -p COM[COM port number] monitor
•To open the configuration menu
idf.py menuconfig
•Check out the official ESP-IDF.