2186 views|17 replies

280

Posts

7

Resources
The OP
 

【Smart water cup holder】06-Work submission [Copy link]

 
 

Smart cup holder

Author: sipower

1. Brief introduction of the work (100-200 words)
(Design name, work photo, function introduction, etc.)

This work designs a smart cup holder that can detect the use status of the cup and remind users to drink water in time. By connecting to the Alibaba Cloud platform, the clock can be automatically calibrated. You can also set parameters for the cup holder in the cloud terminal. The main work of this work is to design a beautiful interface that is pleasing to the eye. The other is to connect to Alibaba Cloud to achieve cloud sharing and intelligent connection.

The picture below is a photo of the final physical work.

Figure 1. Photo of the work

2. System Block Diagram (Combined with Pictures and Text)
(System Software and Hardware Implementation Block Diagram)

The hardware uses the STM32L496G-DISCO evaluation board as the main control, and uses a reflective photoelectric sensor RPR-220 to detect whether the cup is on the cup holder. The ESP8266 module is used to connect to Alibaba Cloud, obtain network time, synchronize the cup status, set parameters, and other operations. The hardware block diagram is as follows.

Figure 2. Hardware block diagram

The software uses FreeRTOS system as the basic software platform and uses TouchGFX to design the interface. The system state machine is shown in the figure below.

Figure 3. State machine

In standby mode, an analog clock is displayed. If the user does not pick up the cup within a certain period of time, the next reminder state will be entered. If the user drinks water before the timeout, the encouragement state will be entered.

In the reminder state, the text "It's time to drink water!" is displayed. If the user picks up the water cup, the encouragement state is entered.

In the encouragement state, the text "Great!" is displayed. If the user puts down the cup, the system enters the standby state. If the user does not put down the cup within a certain period of time, the system enters the water receiving state.

In the water receiving state, the text "Have you gone to get water?" is displayed. If the user puts down the water cup, it enters the standby state.

3. Functional description of each part (combined with pictures and text)

(The functional description and explanation of each part are presented in a combination of pictures and text.)

1. UI interface implementation

First, let me introduce the development environment I use:

TouchGFX software version: 4.20.0

IAR EWARM software version: 9.30.1

STM32CubeMX software version: 6.6.1

STM32CubeProgrammer software version: 2.11.0

Development board: STM32L496G-DISCO

Desktop system: Window11

The following describes how to design the interface using TouchGFX 4.20.0 Designer. First, create an empty project based on STM32L496G-DISCO, as shown below.

Figure 4. Create a project

Add background, controls, etc. The following figure shows adding a simulated clock.

Figure 5. Adding controls

After some trial and error, I finally configured the interface as shown below. Due to my lack of experience, I also added a screen to test the usage of each control.

Figure 6: Interface design

I first tried out the various elements used on the test screen and confirmed that the code could be implemented before porting it to the official main screen. The following figure shows what the test screen looks like.

Figure 7. Test screen

Here is a special note. In order to simulate the picking up and putting down of a water cup, I set two transparent buttons on the main interface to realize the state change. The following figure is the description of one of the buttons. In order to make it easier to press, I use the upper half of the screen as the touchable area, and then put the button on the top layer and set it to transparent. Add interaction on the far right and call a virtual function.

Figure 8. Transparent button

The following figure is a detailed introduction to the implementation of the transparent button interaction virtual function. Note that some codes are automatically generated and some are added by me.

Figure 9. Virtual function implementation

Then add code to the <MainView.cpp> file to implement the state machine I designed. See the attachment for the specific code.

By using the simulation function of TouchGFX to test and debug, once you are sure there is no problem, you can download it to the development board with one click and test it directly on the hardware. See the video for the debugged interface.

Above, the basic interface is designed. It may look simple, but for those who are learning TouchGFX from scratch, they still need to refer to multiple examples, think about which functions can be used, how to configure them, and in what form to display them. But once you get started, it will be easy to use later.

2. Cup position detection solution

I use a reflective photoelectric sensor RPR-220 to detect whether the cup is on the cup holder. The sensor principle and the actual object are shown in the figure below.

Figure 10: Photoelectric sensor

To detect whether the cup is in place, you can actually use a mechanical pressure touch switch, which is simpler to use. The reason why the photoelectric type is finally used is that the photoelectric sensor does not contact, has a simple structure and high reliability. The circuit design of this sensor is shown in the figure below.

Figure 11. Sensor circuit diagram

This kind of sensor is mostly used to detect black marks with clear boundaries. I used it to detect water cups. Affected by the surface colors of different water cups, the output voltage signal was not consistent. Therefore, I designed a dynamic detection method, which is to detect the output voltage of the receiving tube when the light-emitting tube is turned on and off, and then make a difference. If there is no cup, the difference will be very small, otherwise it will be much larger, so the detection result will be more accurate.

The connection between the sensor and the STM32L496G-DISCO development board uses the reserved Arduino uno interface, using an ADC port to collect voltage and an IO port to control the light-emitting diode switch. The specific resources used are shown in the figure below.

Figure 12: Arduino uno interface

I found a bare PCB and soldered the photoelectric sensor with flying wires, as shown in the figure below.

Figure 13: Flying wire board

The final effect of connecting to the STM32L496G-DISCO development board is as shown in the figure below.

Figure 14: Connect the circuit board

The expected usage scenario is as shown below.

Figure 15: Usage scenario

After connecting the hardware circuit, the next step is to debug the program. First, configure the ADC and IO port output in STM32CubeMX. The figure below shows the ADC configuration. Using DMA to transfer sampled data, the CPU does not need to intervene in any operation, which is more efficient.

Figure 16. ADC configuration

The following figure shows the IO configuration, with the default high level, pull-up, and medium speed.

Figure 17. IO configuration

Here I would like to emphasize that you should not forget to configure the reference source. I forgot to configure it, but STM32CubeMX did not prompt me, which took me a long time to find the reason. As shown in the figure below.

Figure 18. Reference source configuration

Next, generate the code and add the specific implementation in the editor. The following code implements the cup detection and sends a message to the UI. The hardware obtains the parameters and passes them to the UI according to the MVP structure specified by TouchGFX. The specific transmission process is shown in the figure below.

Figure 19: Parameter passing

After all files are modified, compile, download, and run, you can see the final running results. The use process of the actual work is shown in the video.

  1. Connect to Alibaba Cloud to synchronize time and data

The development board connects to Alibaba Cloud through the ESP8266 module, and obtains network time, synchronizes water cup status, sets parameters, etc. The ESP8266 module I use is the ESP-12S produced by Anxinke, as shown below.

Figure 20: WiFi module

Since I bought it a long time ago, the firmware inside does not support the MQTT protocol, so the first thing to do is to upgrade the WiFi firmware. The link below is the official page of Anxinke, and all the software packages you need can be found on this page.

https://docs.ai-thinker.com/esp8266

There are many specific upgrade tutorials on the Internet, so I will not go into details. I will just list one here.

https://blog.csdn.net/jdhuzb/article/details/119678009

The hardware connection between the development board and the WiFi module, I use the UART1 port, corresponding to the PMOD#2 and PMOD#3 pins of CN3 on the board, as shown in the figure below.

Figure 21, Serial port interface

The CN3 interface can directly provide 3.3V power supply, which can be led out to the WiFi module with 4 wires. The connected experimental board is as shown in the figure below.

Figure 22: Connected experimental board

After the hardware is connected, start designing the software. First, use STM32CubeMX to configure the serial port, as shown below. Since you need to receive string frame data of indefinite length, you use the serial port idle interrupt + serial port DMA interrupt to achieve it, so you need to set the DMA channel.

Figure 23, Configuring the serial port

STM32CubeMX will automatically generate the basic configuration of the serial port. What is more important is that you need to write your own idle interrupt callback function, which is not provided by the official HAL library. I wrote the callback function for UART1 and UART2 transparent transmission, which basically realizes DMA fully automatic transmission and reception, and only occupies very few CPU resources.

There are two points to note: First, the DMA buffer must be long enough, at least larger than the maximum message length sent back by Alibaba Cloud. Second, the ORE flag must be cleared before the next interrupt is enabled to prevent data from coming in during the interrupt processing to disable DMA, causing an ORE error.

The next step is to build products and devices on the Alibaba Cloud platform. There are too many online tutorials for this, so I won’t go into detail here. I’ll just post the following link for your reference.

https://blog.csdn.net/u014421313/article/details/125412417

The following figure shows a device I created on Alibaba Cloud, with three attributes: water cup status, water cup at location timeout, and water cup out of location timeout.

Figure 24. Devices created on Alibaba Cloud

The next step is to write the networking program for the MCU. There are many routines on the Internet. Most of them are complicated and difficult to understand, probably because of various abnormal situations. I use the simplest and crudest way to connect to Alibaba Cloud. The code structure is also very simple, which is suitable for beginners to practice. I first defined the networking information in the header file "esp_mqtt.h". Considering that this is just a demonstration project and does not require flexible configuration, I did not split it into flexible ones.

Then in "esp_mqtt.c", send frames directly through the serial port, leaving a little delay between each frame, and wait for Alibaba Cloud to return the data.

Here I will focus on the data parsing callback function. This is divided into two parts. The first part is to extract the three parameters of the hour, minute, and second in the received time string and send them to the analog clock for time calibration. This is relatively simple. Just find the string position and use the atoi() function to convert the string into an int number. The second part is to parse the setting message received from Alibaba Cloud. Most of the routines on the Internet use string functions to extract this kind of json string with few parameters and simple content bit by bit. I think this is more troublesome, so here I directly call the cJSON library for parsing, which is refreshing! Finally, the results are printed out from the debugging serial port. After repeated debugging, Alibaba Cloud data reporting and subscription were finally realized. See the video for specific demonstration.

Then, the updated time data and the subscribed setting data are synchronized to the TouchGFX interface. Finally, a web application is made to implement the cloud settings.

When writing this part of the program, I initially planned to use osMessageCreate to create two message queues pointing to structures, and pass the time data and setting data obtained from Alibaba Cloud to the TouchGFX code. However, after repeated research, I found that due to the re-encapsulation of STM32CubeMX, the default osMessageCreate can only create queues pointing to int32 types. If it points to a pointer, memory space must be allocated separately, which is quite troublesome. Here I am lazy and only create a message queue to pass the flag to indicate what information is currently updated, and set the structures corresponding to the time data and setting data as global variables, which are directly called in the TouchGFX code. Since the flag bit transfer follows the MVP method, there is no problem in actual use.

Finally, a WEB application was designed to indicate and set the parameters of the water cup holder. The specific application interface is shown in the figure below.

Figure 25: WEB application

4. Source Code

The code is in the following link:

https://download.eeworld.com.cn/detail/sipower/625171

5. Demonstration video of the work’s functions

(Video introduction + link)

The video is available at the following link:

  1. Design UI and implement state machine.

https://www.bilibili.com/video/BV1WD4y1y7nF?share_source=copy_web

2. The software and hardware debugging of the smart cup holder was successful.

https://www.bilibili.com/video/BV1kg411Y7ts?share_source=copy_web

3. The smart cup holder is connected to Alibaba Cloud.

https://www.bilibili.com/video/BV1wD4y1C727?share_source=copy_web

4. Alibaba Cloud display and settings for smart water cup holder.

https://www.bilibili.com/video/BV1QD4y1k72e?share_source=copy_web

6. Project Summary

(Project text summary + post sharing link summary)

Through this work design, I have basically mastered the development process of TouchGFX and became familiar with the operation of integrating TouchGFX and hardware interfaces on the FreeRTOS system. By adding a WiFi module, communication with Alibaba Cloud and IoT operations were achieved. This has added new skills for future work.

In short, I would like to thank Digi-Key and EEWORLD for providing this creative opportunity. You have provided financial and technical support for the learning and research of engineers, which has a positive impact on the entire industry. I hope that both companies will do better and better.

The post link is as follows:

1. Unboxing sharing:

https://en.eeworld.com/bbs/thread-1206983-1-1.html

2. Construction of TouchGFX development environment based on STM32L496G-DISCO

https://en.eeworld.com/bbs/thread-1220158-1-1.html

3. UI design based on TouchGFX

https://en.eeworld.com/bbs/thread-1220165-1-1.html

4. Add hardware support for TouchGFX interface

https://en.eeworld.com/bbs/thread-1220212-1-1.html

5. Connect to Alibaba Cloud to synchronize time and data

https://en.eeworld.com/bbs/thread-1220875-1-1.html

VII. Others

None. 智能水杯托_作品提交.doc (6.83 MB, downloads: 3)

This post is from DigiKey Technology Zone

Latest reply

I've always wanted to try TouchGFX   Details Published on 2022-10-21 12:04
 
 

5998

Posts

6

Resources
2
 

I wish the OP a prize in advance. Everyone did a great job this time. I am the one who collapsed halfway.

This post is from DigiKey Technology Zone

Comments

Thank you, best wishes  Details Published on 2022-10-16 14:29
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

6818

Posts

11

Resources
3
 

I wish the author of this post wins the prize in advance. Everyone has done a great job this time. I guess I won’t be able to hand in my homework.

This post is from DigiKey Technology Zone

Comments

There's still one week left. Come on, boy.  Details Published on 2022-10-16 14:30
 
 
 

280

Posts

7

Resources
4
 
This post was last edited by sipower on 2022-10-16 14:34
Qintianqintian0303 posted on 2022-10-16 08:57 I wish the host a win in advance. Everyone did a great job this time. I am a half-way collapse

Thank you! The STM32F7508-DK development board you chose has a lot more resources than the one I chose. It should be easier to use and not crash.

This post is from DigiKey Technology Zone
 
 
 

280

Posts

7

Resources
5
 
lugl4313820 posted on 2022-10-16 09:02 I wish the OP a prize. Everyone did a great job this time. I guess I won’t be able to hand in my homework.

There's still one week left. Come on, boy.

This post is from DigiKey Technology Zone

Comments

It's hard work. The hardware is done, but the software is still quite troublesome. The epidemic has just ended. I work every day without weekends. I am exhausted. How can I have the energy? I also have to prepare for the career interview. I feel like I am Nezha and I can't spare any effort. There are also two assessments. The assessment is okay as a seasoning. I am concentrating on this  Details Published on 2022-10-16 15:54
 
 
 

5998

Posts

6

Resources
6
 
sipower posted on 2022-10-16 14:30 There is still one week left, come on, young man

It's laborious. The hardware is done, but the software is still quite troublesome. The epidemic has just ended, and I have to work every day without weekends. I am exhausted. How can I have the energy? I also have to prepare for the career interview. I feel like I am Nezha and I can't spare any effort. There are also two assessments. The assessment is okay as a seasoning, but I don't feel I have enough energy to focus on this.

This post is from DigiKey Technology Zone

Comments

You can consider trying TouchGFX, which has the best support for 4.3-inch screen development boards and has many examples. You only need to make simple changes to use it.  Details Published on 2022-10-17 10:30
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

280

Posts

7

Resources
7
 
Qintianqintian0303 posted on 2022-10-16 15:54 It’s hard work. The hardware is done, but the software is still quite troublesome. The epidemic has just ended. I work every day without weekends. I am exhausted. How can I have the energy...

You can consider trying TouchGFX, which has the best support for 4.3-inch screen development boards and has many examples. You only need to make simple changes to use it.

This post is from DigiKey Technology Zone

Comments

I used TouchGFX, but I had to design the interface myself, which was also quite troublesome. Moreover, the initial program I generated would report an error as soon as I ran RTOS, indicating that there was insufficient memory.  Details Published on 2022-10-17 10:57
 
 
 

5998

Posts

6

Resources
8
 
sipower posted on 2022-10-17 10:30 You can consider trying TouchGFX, which has the best support for 4.3-inch screen development boards and many examples. You only need to make simple changes to use it

I used TouchGFX, but I had to design the interface myself, which was also quite troublesome. Moreover, the initial program I generated would report an error as soon as I ran RTOS, indicating that there was insufficient memory.

This post is from DigiKey Technology Zone

Comments

TouchGFX has an option to download to the development board with one click. Try it first to see if it works. If it works, it's a problem with your IDE configuration.  Details Published on 2022-10-17 11:53
TouchGFX has an option to download to the development board with one click. Try it first to see if it works. If it works, it's a problem with your IDE configuration.  Details Published on 2022-10-17 11:02
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

280

Posts

7

Resources
9
 
Qintianqintian0303 posted on 2022-10-17 10:57 I used TouchGFX, but I still had to design the interface myself, which was also quite troublesome. Moreover, the initial program I generated would report an error as long as it ran RTOS, and...

TouchGFX has an option to download to the development board with one click. Try it first to see if it works. If it works, it's a problem with your IDE configuration.

This post is from DigiKey Technology Zone

Comments

I think there is something wrong with icf. The extended Flash on the development board should be usable. The GFX tutorial directly changes an icf file. However, we dare not change this thing randomly. It can be compiled successfully without RTOS system. Let's deal with it this way first.  Details Published on 2022-10-17 11:56
 
 
 

190

Posts

1

Resources
10
 
Qintianqintian0303 posted on 2022-10-17 10:57 I used TouchGFX, but I still had to design the interface myself, which was also quite troublesome. Moreover, the initial program I generated would report an error as long as it ran RTOS, and...

To put it simply, UI design is framework + parameters. Art design is the parameters. You don’t need art design. A simple framework interface is enough.

This post is from DigiKey Technology Zone

Comments

There are common interface designs in it, so you still have to learn it systematically, but learning by yourself according to the tutorial is slow.  Details Published on 2022-10-17 11:57
 
 
 

5998

Posts

6

Resources
11
 
sipower posted on 2022-10-17 11:02 TouchGFX has an option to download to the development board with one click. Try to see if this works. If it works, it is a problem with your IDE configuration

I think there is something wrong with icf. The extended Flash on the development board should be usable. The GFX tutorial directly changes an icf file. However, we dare not change this thing randomly. It can be compiled successfully without RTOS system. Let's deal with it this way first.

This post is from DigiKey Technology Zone

Comments

If you use IAR, download the latest version 9.30.1, and then use the latest example library of cubeMX. For the stm32f7 chip, you can basically find all the files needed to use external flash. The files for the stm32l496 I used did not exist. I wanted to do it myself, but found it was troublesome and I didn't have enough time, so I didn't do it.  Details Published on 2022-10-18 08:58
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

5998

Posts

6

Resources
12
 
huihuihaha posted on 2022-10-17 11:53 To put it simply, UI design is framework + parameters, and art design is parameters. No art design is needed, a simple framework interface is enough

There are common interface designs in it, so you still have to learn it systematically, but learning by yourself according to the tutorial is slow.

This post is from DigiKey Technology Zone
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

280

Posts

7

Resources
13
 
Qintianqintian0303 posted on 2022-10-17 11:56 I think there is a problem with icf. The extended Flash on the development board should be usable. The GFX tutorial directly changed an icf file, but this thing...

If you use IAR, download the latest version 9.30.1, and then use the latest example library of cubeMX. For the stm32f7 chip, you can basically find all the files needed to use external flash. The files for the stm32l496 I used did not exist. I wanted to do it myself, but found it troublesome and time-consuming, so I didn't do it. I tried to compress the code as much as possible and run it on the on-chip flash.

This post is from DigiKey Technology Zone

Comments

I am using IAR8.30, and the generated project can be opened normally. This should not be a problem with the development environment, but a problem with the project configuration or adaptation.  Details Published on 2022-10-18 16:31
 
 
 

5998

Posts

6

Resources
14
 
sipower posted on 2022-10-18 08:58 If you use IAR, download the latest version 9.30.1, and then use the latest example library of cubeMX. For the stm32f7 chip, you can basically find the use of external...

I am using IAR8.30, and the generated project can be opened normally. This should not be a problem with the development environment, but a problem with the project configuration or adaptation.

This post is from DigiKey Technology Zone

Comments

Try the new version 9.30.1, the difference is huge.  Details Published on 2022-10-19 09:28
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

280

Posts

7

Resources
15
 
Qintianqintian0303 posted on 2022-10-18 16:31 I am using IAR8.30, and the generated project can be opened normally without any problems. This should not be a problem with the development environment, but a problem with the project configuration or...

Try the new version 9.30.1, the difference is huge.

This post is from DigiKey Technology Zone

Comments

I'll try  Details Published on 2022-10-19 09:47
 
 
 

5998

Posts

6

Resources
16
 
sipower posted on 2022-10-19 09:28 You can try the new version 9.30.1. The experience difference is very big

I'll try

This post is from DigiKey Technology Zone
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

407

Posts

7

Resources
17
 

I've always wanted to try TouchGFX

This post is from DigiKey Technology Zone

Comments

Try it, it works great  Details Published on 2022-10-22 20:38
 
 
 

280

Posts

7

Resources
18
 
lansebuluo posted on 2022-10-21 12:04 I have always wanted to get in touch with TouchGFX

Try it, it works great

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list