Riverdi STM32 Display #2. How to control LED using Buttons on the Display

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] Tech [Music] a lot of you guys requested me to do this so here I am today with another video on the rivety display we will see how to use the button on the display to control the LED attached to the MCU this seems like a very easy topic but if you have a rivety display you know how challenging it is the method I am going to use isn't going to be an easy one but it will be a universal method for a lot of things you can use the same method to display the data from uart any sensor pretty much anything I have covered so far in the touch gfx I am using the latest version of the touch gfx that is 4.21.4 but rivety has mentioned that they only support the version 4.20 I have already tested this version and it works fine although you won't see the bsp folder generated like it used to generate on the version 20. I am not going to use any BSB replated files so this is fine with me here I am creating a new project with the rivety display first of all I am adding a background image to this project I already have a 1280x800 ping image for the background let's add a text area to display the LED status I don't want the auto size choose the alignment the typography Etc now go to text typography and add the wildcard range to this typography we will use the wildcard for the text area and the buffer size will be 10 bytes the default status for the LED is set to off now let's add the buttons to turn the LED on and off I am using the flex button so that I can resize it as per my need I will modify this button to look a little more attractive so under the visual element click add and select icon now in the icon option we will add some button icon to our button I am using this Clay theme as it has some good circular icons the image size should be less than the button size choose the images for the button released and button pressed now remove the button with border element so that the background is removed let me adjust the button size so that the image fits a little more perfectly all right let's name this button as the on button we need to create one more button the off button so we will just copy this button and change some things now the buttons have been created so we will also Define the interactions when the on button is clicked it will call a new virtual function the on clicked similarly when the off button is clicked the off-clicked function will be called that is it for the designing let's generate the project now open the project in the cube ID here is the project structure let's take a look at the gpio.c file here some pins are already configured for certain purposes so when you choose a certain pin to be an input or output pin make sure not to choose from these I need one pin to be configured as output where I can connect the LED to let's quickly see the data sheet to see the availability of the pins I have this particular display from rivity here is the link to download the datasheet all right as you already know we have the expansion connector on the display which can be used to connect gpio i2c SPI Etc I will use one of the pins from this connector to be used as the output pin I am going to use this pa5 but this is already being used as the DAC pin so we need to First disable the initialization of this pin as the DAC pin and then initialize it as the output pin here in the DAC source file you can see the pin pa5 is being used as the DAC output pin so go to the main file and comment out the DAC initialization function now we will initialize the pin in the output mode if you know the initialization code write it or you can refer to the gpio.c file here this pin is being initialized in the output push-pull mode so I will copy this part let's write a function LED in it we also need the definition of initialization structure also reset the pin before initializing it now change the gpio port to gpioa and the PIN to pin 5. make sure the clock for the respective Port is enabled if not then enable yourself now in the main function call the LED init function to initialize the LED pin as output let's build the code once we have few warnings but that's all right as I mentioned in the beginning I will use a harder but more common method to control this led I am going to create a new task to Blink the LED and Q to transfer the data from GUI to the MCU a much better way of approaching this is to create a new source file to write our code this way we will have our code separated from the predefined one and whenever needed we will only make changes in that particular file so I am creating a new source file my file.c and a new header file my file.h now we need to move these files to the main project folder where the rest of the files are stored open the newly created file in the system Explorer now we will move these files to a different location go to the main project folder CM7 core source move the dot C file here and dot h file in the include folder now both the files have been removed from the IDE so we will link the source file to the core directory make sure you link relative to the project location now we have the file here and we can write it we will start with certain inclusions so here I have included the main header file my file header cmsys OS for the rtos task header file for the task related functions and Q header file for the queue related functions next we will create a task and a queue we need to First create the attributes for the task and the queue if you don't know the functions for the same you can refer to the free rtos.c file let's copy the attributes of the default task now we will change the word default with the LED so we have the LED task handle and the LED task attributes now create the attributes for the queue let's define the LED Q handle the Q attributes just require the name parameter next we need to create the task and the queue let's write a separate function to create the LED task the start LED task function will be defined later all right let's create the queue now the size of the queue should be one element and the element size is the size of the integer basically this is going to be an integer Q with one element this is because we only need to transfer with a 1 or a zero now we will write the start LED task again I am taking the reference from the start default task I have covered this part in detail in the previous touch gfx videos we will first check if there is some message in the queue if there is we will copy the message into the variable LED state let's define the integral variable LED state now the LED state will be set as per the value of the LED State variable this task will run every 10 milliseconds but the LED will only set when there is some data in the queue that is when the button is pressed Define the start LED task at the beginning so we create the task attributes and the queue attributes then we create the task and the queue and in the end we write the task function we need to Define these initialization functions in the my file header file now go to the main file include the my file header and initialize the task and the queue after the free rtos initialization function now we will write the code for the GUI open the GUI folder and we will start with the screen one view source file we have defined the interactions when the buttons are clicked so we first need to Define these functions in the view header file now when the on button is pressed the on clicked function will be called and here we will call the LED control function in the presenter and pass the parameter true we also need to display the LED status in the text area so first use the string copy function to copy the LED on string to the text area buffer and then invalidate the text area similarly when the off-clicked function is called we will pass the force parameter to the LED control function and update the text area with the string LED off now we need to define the LED control function in the presenter here we will call the same function in the model and also pass the state as the parameter we also need to Define this function in the presenter header file finally we will write the main code in the model file first include the cmsis OS header file so that we can write the Q functions include the my file header also Now define the ledq handle as the external variable in the LED control function first check if there is some space available in the queue if it is then put the message in the queue the message is the state variable that is being passed from The View file let's build the code now we have to Define this in the model header file also I'll write the code builds fine but it will show an error when you flash it via the touch gfx so let's fix that too open the project folder and go to the root folder here go inside the GCC folder and edit the make file for CM7 scroll down till you see the board C files section we need to add one more file for the compilation so add the my file.c here save the make file and open the touch gfx again let's see the simulator first the project is running fine on the touch gfx so let's flash it to the board target has been flashed successfully here you can see in logs my file.c was also compiled and therefore there was no error let's see the project working on the board you can see the LED is responding well and the text area is showing the status so everything is working well I will continue with the rivety display and make more videos covering the uart and some sensor we will continue with this file we created today and add more functions to it this is it for the video I hope this video sheds some light on how to work with rivety display the link to download the code is in the description below leave comments in case of any doubt keep watching and have a nice day ahead
Info
Channel: ControllersTech
Views: 2,546
Rating: undefined out of 5
Keywords: stm32, stm32f4, f103, discovery, nucleo, stm32f7, stm32G, cubeIDE, sensor, module, tutorial, example, can, i2c, spi, uart, learn, tutorials, touchgfx, gfx, button, display, stm32h7, riverdi, embedded, getting, started, custom, board, slider, gauge, LED, cubeMX, project, data, MCU, configuration, library, file
Id: cIZZHnPD-0c
Channel Id: undefined
Length: 16min 21sec (981 seconds)
Published: Sat Jun 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.