Please enable JavaScript to view this site.

Waijung 2 User Guide

Navigation: ESP32 target > Tutorials > M5StickC tutorials

Simple GPIO digital input output example

Scroll Prev Top Next More

Description

This example demonstrates how to use onboard button and LED to ON the LED when the button is pressed. For this, GPIO37 (push button) is used as the input and GPIO10 is used as LED.

simple_digital_input_output_1

Hands-on Simulink model

Step 1: Open Matlab Simulink

 

Step 2: Import Waijung 2 target setup block from library browser

simple_digital_input_output_2

 

Step 3: Import digital input and digital output blocks to the model

simple_digital_input_output_3

 

simple_digital_input_output_4

 

Step 4: Change the mask parameters of each block according to the hardware board

 

Change following parameters in the ESP32 tab in Waijung 2 Target Setup block

1.Select the correct COM port

2.Change the Baudrate to 115200

simple_digital_input_output_5

 

Change the Digital Input block mask parameters

1.Select Pin37 (for push button)

2.set the Sample time to 0.01

simple_digital_input_output_6

 

Change the Digital Output block mask parameters

1.Enable Override pin selection constraints check box

2.Select only the Pin 10 (for LED)

simple_digital_input_output_7

 

Step 5: Connect the Digital Input output port with Digital Output input port and save the model file properly

 

simple_digital_input_output_8

 

Step 6: Go to Apps tab and select Embedded Coder. Then Go to C CODE tab and Build it

simple_digital_input_output_9

 

Step 7: Once the Simulink model is built and upload it to ESP32 successfully, if the push button is ON the LED will be ON.

 

Simulink model file: led_toggel.slx

Copyright 2024 Aimagin Co.,Ltd. Rev.1680