How to use STM32 and STONE HMI display to make coffee machine with touch screen operation?

Introduction

I am an MCU software engineer, recently received a project to make a coffee machine for household requirements with a touch screen operation. I choose the STM32 as it is kind of simple and easy MCU to use. I choose STONE’s touch screen display, the screen is simple and easy to use. My STM32 MCU uses UART for communicating with the display.

STONE serial LCD display screen, which can communicate through the serial port of MCU. At the same time, the logic design of the UI interface of this display screen can be designed directly by using the STONE TOOL Box provided by STONE’s official website, which is very convenient. So I’m going to use it for this coffee machine project.

At the same time, I will simply record the basic development. Since this is a project of my company, I will only record a simple demo and not write the complete code. Some basic tutorial about the STONE display screen available here: https://www.stoneitech.com/

The website has a variety of information about the model, use and design documentation, as well as video tutorials. I won’t go into too much detail here.

Coffee machine display screen function introduction

  • This project has the following functions:
  • Displays the current time and date.
  • There are four buttons on the display for americano, latte, cappuccino and espresso.
  • Displays the current amount of remaining coffee beans, milk, and coffee sugar.
  • A text display box displays the current state.

With these concepts in mind, you can design a UI interface. STONE’s touch screens UI design is relatively simple. The STONE TOOL Box help you to design UI with good pictures into the screen and add your own buttons.

Make UI pictures for STONE display

According to functional requirements, I made the following two UI display interfaces, one is the main interface and the other is the button effect.

1-STONE-display-STM32-Coffee-Maker
2-STONE-display-STM32-Coffee-Maker

Use of STONE TOOL Box

Open the STONE TOOL Box to create a new project, then import the designed UI to display pictures, and add your own buttons, text display boxes, etc. The official website of STONE has a very complete tutorial on how to use this software:

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

The effects of adding buttons and displaying components in the STONE TOOL Box are as follows:

STONE TOOL Box has the function of simulation display, through which you can see the operation effect of UI interface:

At this point, my UI display is complete, and all I have to do is write the MCU code. Download the files generated by the STONE TOOL Box onto the display screen to see the actual results.

6-STONE-display-STM32-Coffee-Maker

STM32F103RCT6

STM32F103RCT6 is powerful MCU. Here are dome of its basic parameters of the MCU:

  • Series: STM32F10X
  • Architecture: ARM - CORTEX32
  • Speed: 72 MHZ
  • Communication interface: CAN, I2C, IrDA, LIN, SPI, UART/USART, USB
  • Peripheral equipment: DMA, motor control PWM, PDR, POR, PVD, PWM, temperature sensor, WDT
  • Program storage capacity: 256KB
  • Program memory type: FLASH
  • RAM capacity: 48K
  • Voltage - power supply (Vcc/Vdd) : 2 V ~ 3.6 V
  • Oscillator: internal
  • Operating temperature: -40°C ~ 85°C
  • Package/housing: 64-lqfp

In this project, I will be using UART, GPIO, Watch Dog and Timer of STM32F103RCT6. The development of these peripherals is documented below.

I use Keil MDK software development, which is no stranger to you, so I will not introduce the installation method of this software.

STM32 can be programmed by j-link or st-link programmers. The following picture is the STM32 circuit board I used:

7-Coffee machine display screen

UART Serial

STM32F103RCT6 has several serial ports. In this project, I am using the serial port channel PA9 and PA10. The baud rate is set to 115200 bits/sec.

GPIO

In the user interface of this project, there are a total of four buttons, which are actually the making of four kinds of coffee. In the coffee machine, controlling the number of coffee beans, milk consumption and water flow for different coffees are actually realized by controlling sensors and relays, while I simply control the GPIO pin.

Timer

When initializing the timer, specify the frequency division coefficient PSC, here is our system clock (72MHz) for frequency division. Then specify the reload value ARR, which means that when our timer reaches this ARR, the timer will reload other values.

For example, when we set the timer to count up and when the value of the counter is equal to ARR, it will be automatically cleared by the timer to 0. The timer count is restarted and once the ARR value is updated.

Calculate the Update time formula Tout = ((ARR+1)*(PSC +1))/Tclk

Where Tclk is the clock source of the timer, here its is 72Mhz.

We divide the allocated clock frequency, specify the frequency division value as PSC, then divide our Tclk into PSC +1, the final frequency of our timer is Tclk/(PSC +1) MHz

So what we mean by the frequency here is that we have 1s of Tclk over PSC +1 M Numbers (1M=10 ^ 6), and the time for each number is PSC +1 /Tclk, and it’s easy to understand that the inverse of the frequency is the period, and the period for each number here is PSC +1 /Tclk seconds and then we go from 0 to arr is (arr+1)*(PSC +1)/Tclk

For example, let’s set arr=7199 and PSC =9999. We divided 72MHz into 9999+1 is equal to 7200Hz
This is 9,000 counts per second, and each count is 1/7,200 of a second. So we’re recording 9,000 Numbers here to go to the timer update (7199+1)*(1/7200)=1s, so 1s goes to an update. I needed a timer interrupt to time how much coffee and milk I had left, so I wrote the code for the timer driver and wrote a timer interrupt function:

Watch Dog

To prevent the system from crashing while the program was running, I added the watchdog. In fact, all projects that use the MCU generally use a watchdog.

STM32 has two built-in watchdogs, providing greater security, time accuracy and flexibility. Two watchdog devices (independent watchdog and window watchdog) can be used to detect and resolve faults caused by software errors. When the counter reaches a given timeout value, an interrupt (window watchdog only) or system reset is triggered.

Independent watchdog (IWDG):

Driven by a dedicated low-speed clock (LSI), it works even if the master clock fails.

It is suitable for use in situations where the watchdog is required to work completely independently outside the main program and requires low time accuracy.

Window watchdog (WWDG):

Driven by the clock from APB1 clock after frequency division. Detect abnormally late or premature application operation through a configurable time window. Suitable for programs that require watchdogs to function in precise timing Windows.

The Main logic in the Main function is as follows:

In the timer interrupt, my goal is to check how much coffee and milk is left, and then send the detected value to the display screen through a serial port.

Measuring how much milk and coffee beans are left is usually done by sensors. Simple methods include pressure sensors, which measure the current weight of the milk and coffee beans to determine how much is left over.

Write in the last

This article only records the simple development process of my project. Considering the confidentiality of the company’s project, the UI display interface I used was also made by myself, not the real UI display interface of this project.

The code part of STM32 only adds the peripheral driver of MCU and related logic code. Also considering the confidentiality of the company’s project, the specific key technology part is not given, please understand. However, according to the code I provided, cooperate with STONE display screen. my friends who are also software engineers need only spend a few days to add key technical parts to my code framework to complete the project.

Article source:
https://www.stoneitech.com/application/civil-electronic/stone-display-stm32-coffee-maker.html

2 Likes

Thats a wonderful description of the Coffee Vending Machine using STM 32