STM32 development board tutorial: Using STONE HMI display to develop beauty equipment

Projetos com STM32
alani
Membro
Mensagens: 5
Registrado em: 01/Set/2020, 07:40

STM32 development board tutorial: Using STONE HMI display to develop beauty equipment

Mensagem por alani » 11/Set/2020, 08:17

Brief
STM32 development board tutorial:Use STONE LCD control STM32

Imagem

Tutorial: Use the STM32 development board and STONE LCD screen to develop beauty devices with touch screens



Because I have a lot of contacts with ST, MCU like this type can generally plug in the screen through IIC or SPI or serial port, such as 0.96 inch display screen, 1602 LCD screen, and various TFT LCD screens, and I decided to use STONE LCD screen to do this project. Speaking of STM32 board.





Project requirements


Here we want to do a project about the use of medical devices and instruments. This project is mainly through our STVC101WT-01 serial port screen, through the touch mode. After pressing the key, the serial port screen sends the serial port command to STM32l053r8 through the serial port command. When our STM MCU receives the specific command, it starts to analyze the command, This resolution protocol is specific, which will be discussed later. After that, MCU will analyze and recognize specific fan instructions and led instructions, so as to realize the control of fan and led.



There are four functions:


• Serial port screen realizes touch key function

• Send touch command

• MCU analyzing instruction

• Control the FAN and LED



After the function is determined, we need to select the model of each module:


• Type of touch screen

• What kind of MCU module do we use

• What kind of peripheral module to use



I plan to use STVC101WT-01 serial port screen for touch screen, after all, it is very convenient to use, and the market also has a certain proportion, the most important thing is that it is easy to use; the problem of the screen is solved, and then an MCU should be selected. Why do I use STM32l053r8 for MCU? Because the global market share of St MCU is more than 11% in 2015;

We use a 5V 4W DC power supply for the fan, so that it can be controlled directly through IO port; ordinary LED is used.





Introduction and principle of each hardware


Fan


Generally speaking, fans have fan blades, which are electric driven devices to generate current. The fans configured in the fans are powered and then turned into the natural wind to achieve the cool effects.




Structure


Rotor: it is composed of the magnet, fan blade, and shaft; stator: it is composed of silicon steel sheet, coil, and bearing; control circuit: it is composed of IC induction magnet N.S. pole to control its coil conduction through the circuit and generate internal excitation to make rotor rotate. Type: an axial fan, DC fan. Size: 40mm * 40mm * 15mm.



STM32 development board tutorial Use STONE LCD control STM32


Imagem
Imagem





Working principle

The main components of the electric fan are DC motor. Its working principle is: the electrified coil rotates under the force in the magnetic field. The transformation form of energy is: electrical energy is mainly converted into mechanical energy, and because the coil has resistance, it is inevitable that part of electrical energy will be converted into thermal energy.


Imagem





LED


LED. It is made of compounds containing gallium (GA), arsenic (as), phosphorus (P), nitrogen (N), it can radiate visible light when electrons are combined with holes, so it can be used to make light-emitting diodes. In circuits and instruments as indicator lights, or composition of text or digital display.





Characteristics of LED


It uses the solid semiconductor chip as the light-emitting material. Compared with traditional lamps, LED lamps to have the advantages of energy-saving, environmental protection, color rendering and response speed. It has the following characteristics:

① Energy saving is the most prominent feature of LED lamps. In terms of energy consumption, the energy consumption of LED lamps is one-tenth of that of incandescent lamps and one-quarter of that of energy-saving lamps. This is one of the biggest characteristics of LED lights. Now people are advocating energy-saving and environmental protection, and it is precisely because of this feature of energy-saving that the application of the LED lamps is very wide, It makes the LED lamps very popular.

② It can work in the high-speed switch state. When we walk on the road, we will find that every LED screen or picture is unpredictable. This shows that the LED lamp can work at high speed. However, for the incandescent lamps we usually use, we can not achieve such a working state. In normal life, if you switch too many times, it will directly lead to filament breakage. This is also an important reason for the popularity of LED lights.





Principle of LED

The LED has a single guide electricity. When a positive voltage is applied to the LED, the holes injected from the P-region to the N-region and the electrons injected from the N-region to the P-region are combined with the electrons in the N-region and the holes in the P-region within a few microns near the PN junction, respectively, to produce spontaneous emission fluorescence. The energy states of electrons and holes are different in different semiconductor materials. When electrons and holes compound, the amount of energy released is different. The more energy released, the shorter the wavelength of light.





Describe of STVC101WT-01


• 10.1 inch 1024x600 industrial grade TFT panel and 4-wire resistance touch screen;

• brightness is 300cd / m2, LED backlight;

• The RGB color is 65K;

• visual area is 222.7mm * 125.3mm;

• visual angle is 70 / 70 / 50 / 60;

• working life is 20000 hours. 32-bit cortex-m4 200Hz CPU;

• CPLD epm240 TFT-LCD controller;

• 128MB (or 1GB) flash memory;

• USB port (U disk) download;

• toolbox software for GUI design, simple and powerful hex instructions.





Basic functions


• touch screen control / display image / display text / display curve / read and write data / play video and audio. It is suitable for various industries.

• UART interface is RS232 / RS485 / TTL;

• voltage is 6v-35v;

• power consumption is 3.0w;

• working temperature is - 20 ℃ / + 70 ℃;

• air humidity is 60 ℃ 90%.



STVC101WT-01 module communicates with MCU through a serial port, which needs to be used in this project. We only need to add the designed UI picture through the upper computer through the menu bar options to buttons, text boxes, background pictures, and page logic, then generate the configuration file, and finally download it to the display screen to run.

Imagem
Imagem


The manual can be downloaded through the official website:

https://www.stoneitech.com/support/download

in addition to the data manual, there are user manuals, common development TOOLBox, drivers, some simple routine demos, video tutorials, and some for testing projects.





STM32L0538


The ultra-low-power STM32l053x6 / 8 microcontroller combines the connection capability of the universal serial bus (USB 2.0-less crystal) with the high-performance arm ® cortex ® - M0 + 32-bit RISC core running at 32 MHz.

STM32l053x6 / 8 device has many analog functions, one 12 bit ADC, one DAC, two ultra-low-power comparators, multiple timers, one low power timer (LPTIM), three general 16-bit timers, one basic timer, one RTC, and one stick can be used as a time base. They also have two watchdogs, a watchdog with independent clock and window functions, and a window watchdog based on the bus clock.

In addition, the STM32l053x6 / 8 device also embeds standard and advanced communication interfaces: up to two I2C, two SPI, one I2S, two USART, one low-power UART (LPUART) and one crystal-free USB. The device provides up to 24 capacitive sensing channels, which can simply add the touch sensing functionality to any application.

Imagem




STONE LCD Development steps


Generally speaking, the following steps are needed to develop a serial port screen:



• Design with Tool 2019 software;

• Realize the interface communication project between MCU and screen;

• Realize MCU's analysis of each command and trigger the action of response.







STONE TOOLBox 2019 (free gui design software)


STONE TOOLBox 2019 and related USB serial port drivers The software is as follows:



Imagem




STM32CubeMx


STM32CubeMX is a graphical tool that allows a very easy configuration of STM32 microcontrollers and microprocessors, as well as the generation of the corresponding initialization C code for the Arm® Cortex®-M core or a partial Linux® Device Tree for Arm® Cortex®-A core), through a step-by-step process. The first step consists of selecting the STMicroelectronics STM32 microcontroller or microprocessor that matches the required set of peripherals. For microprocessors, the second step allows to configure the GPIOs and the clock setup for the whole system and to interactively assign peripherals either to the Arm® Cortex®-M or to the Cortex®-A world. Specific utilities, such as DDR configuration and tuning, make it easy to get started with STM32 microprocessors. For Cortex®-M core, the configuration includes additional steps that are exactly similar to those described for microcontrollers. For microcontrollers and microprocessor Arm® Cortex®-M, the second step consists in configuring each required embedded software thanks to a pinout-conflict solver, a clock-tree setting helper, a power-consumption calculator, and an utility that configures the peripherals (such as GPIO or USART) and the middleware stacks (such as USB or TCP/IP). Eventually, the user launches the generation that matches the selected configuration choices. This step provides the initialization C code for the Arm® Cortex®-M, ready to be used within several development environments, or a partial Linux® device tree for the Arm® Cortex®-A.



stm32 datasheet:

https://www.st.com/resource/en/datashee ... f205rb.pdf

Download link:

https://www.st.com/

After installation, the interface will open as follows:

Imagem


Click here to open, we just need to select MCU model STM 32l053r8, and then generate the project.



how to interface TFT LCD with microcontroller STM32


Hardware is the basis of all electronic design and the carrier of code. To make the code run, there must be hardware, and to ensure that the code can run normally, there must be a normal hardware connection. Therefore, the connection diagram is as follows:


Imagem





TOOL 2019 interface design


Use the installed tool 2019, click the new project in the upper left corner, and then click OK.


Imagem
Imagem

After that, a default project will be generated, with a blue background by default. Select it and right-click, then select remove to remove the background. Then right click picture file and click Add to add your own picture background, as follows:



Imagem



Then add the required controls, which are mainly button control, numerical addition and subtraction control, and data variable control.


Imagem



The following operations are available when configuring the add / subtract buttons:

Imagem





Expressed as follows:


• configure the effect of button pressing;

• configure the variable address of the control to write the value;

• configure addition or subtraction;

• configure the value range.





When configuring a digital text box:

Imagem



Followed by:



• set the variable address of the control;

• set the number of digits;

• set the size of the number;

• set the alignment of the numbers.

​​​​​​​

Finally, we click generate configuration tool


Imagem



Now the configuration is complete

The interface is mainly used to adjust the speed, dose and radio frequency, so as to achieve the cosmetic effect of the face and waist.

speed adjuSTMent address 0x0001

dose regulation address 0x0002

RF regulation address 0x0003



Note:

The relationship between touch addition and subtraction and digital display box is related by variable address, so it is necessary to maintain consistency to achieve correct control.





The development of STM32L053R8


Imagem




After selecting the corresponding chip model, click start project to enter the configuration interface.



Imagem



Configure and select the project name and storage path, then click generate code to generate the code. After adding the protocol code, the demo can be tested. The detailed code is as follows:


Código: Selecionar todos

* USER CODE BEGIN Header */

/**

  ******************************************************************************

  * @file           : main.c

  * @brief          : Main program body

  ******************************************************************************

  * @attention

  *

  *

 
© Copyright (c) 2019 STMicroelectronics.
 

  * All rights reserved.

 

  *

  * This software component is licensed by ST under BSD 3-Clause license,

  * the "License"; You may not use this file except in compliance with the

  * License. You may obtain a copy of the License at:

  *                        opensource.org/licenses/BSD-3-Clause

  *

  ******************************************************************************

  */

/* USER CODE END Header */

 

/* Includes ------------------------------------------------------------------*/

#include "main.h"

 

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

 

/* USER CODE END Includes */

 

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

 

/* USER CODE END PTD */

 

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

uint8_t aTxStartMessage[] = "\r\n****UART-Hyperterminal communication based on IT ****\r\nEnter 10 characters using keyboard :\r\n";

uint8_t aRxBuffer[20];

uint8_t RxBuffer[9];

uint8_t IOSwitch = 0;

uint8_t PWM_DUTY = 20;// Adjust duty cycle, this value can only be 0-100

/* USER CODE END PD */

 

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

 

/* USER CODE END PM */

 

/* Private variables ---------------------------------------------------------*/

TIM_HandleTypeDef htim2;

 

UART_HandleTypeDef huart1;

 

/* USER CODE BEGIN PV */

#define VGUS_Variable_cmd 0x83

/* USER CODE END PV */

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_USART1_UART_Init(void);

static void MX_TIM2_Init(uint16_t param);

void FAN_ON();

void FAN_OFF();

/* USER CODE BEGIN PFP */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)// Analyze the received data

{

  if(huart->Instance==USART1)//

  {

    HAL_UART_Transmit(&huart1, (uint8_t *)RxBuffer, 9,  0xFFFF);

    

    switch(RxBuffer[3])//Analysis 

    {

      case VGUS_Variable_cmd:

      {  

        //

        /********* Stop timer, reconfigure ******/

        HAL_TIM_Base_Stop_IT(&htim2);//Stop timer

        MX_TIM2_Init( (uint16_t)RxBuffer[8] );

//        MX_TIM2_Init( 1);

        PWM_DUTY = RxBuffer[8];

        HAL_TIM_Base_Start_IT(&htim2);

        break;

      }

      default:

          break;

    

    }

  }

}

 

void FAN_ON()//Open LED

{

    HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_SET);

 

}

void FAN_OFF()//Close LED

{

    HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_RESET);

}

/* USER CODE END PFP */

uint8_t cout = 0;

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

  

    if (htim->Instance == htim2.Instance)

    {

      cout ++;

      if(cout <= PWM_DUTY)// Adjust LED brightness

      {

//        HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_SET);

        HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);      

      }

      else if((cout > PWM_DUTY)&& (cout < 100))

      {

//        HAL_GPIO_WritePin(FAN_GPIO_Port, FAN_Pin, GPIO_PIN_RESET);

        HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

      }

      else

      {

        cout = 0;

      }

      

      if(cout == 20)

      {

        HAL_TIM_Base_Stop_IT(&htim2);

      }

    }

}

/* USER CODE END 0 */

 

/**

  * @brief  The application entry point.

  * @retval int

  */

int main(void)

{

  /* USER CODE BEGIN 1 */

 

  /* USER CODE END 1 */

  

 

  /* MCU Configuration--------------------------------------------------------*/

 

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

 

  /* USER CODE BEGIN Init */

 

  /* USER CODE END Init */

 

  /* Configure the system clock */

  SystemClock_Config();

 

  /* USER CODE BEGIN SysInit */

 

  /* USER CODE END SysInit */

 

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_USART1_UART_Init();

  MX_TIM2_Init(1);

  /* USER CODE BEGIN 2 */

  HAL_UART_Transmit_IT(&huart1, (uint8_t *)aTxStartMessage, sizeof(aTxStartMessage));

 

  HAL_TIM_Base_Start_IT(&htim2);

 

  /* USER CODE END 2 */

 

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

    /* USER CODE END WHILE */

 

    /* USER CODE BEGIN 3 */

  }

  /* USER CODE END 3 */

}

 
Then you can download the code to the stm32 board + STONE LCD development board for testing.



Imagem

Responder