【DigiKey Creative Contest】Home Sharing Smart Pill Box 06+ Submission
[Copy link]
Family Sharing Smart Pill Box
Author: oet
1. Introduction to the work
Previously, smart medicine boxes were mainly designed for a single user. In actual applications, with the increasing severity of aging, there are two or more elderly people in the family who need to take medicine for a long time to maintain blood pressure and blood sugar levels. Single-user medicine boxes are not very suitable. In order to solve this pain point, I designed this family-sharing smart medicine box to support multiple users. This solution uses STM32H7B3I-DK as the main control, uses OpenMV for face recognition, and cooperates with screen display and voice prompts to automatically identify users, actively display the medicine grid number, and light up the medicine grid indicator light, so that users can make as few choices as possible. The work also installs a BME280 sensor to collect and display indoor temperature and humidity information. The picture below is a photo of the final work. I used white paper with squares instead of the medicine box to facilitate demonstration and look more intuitive.
The components purchased from Digi-Key for this project are:
Serial number |
model |
name |
use |
1 |
OPENMV4 CAM H7 |
OPENMV Development Board |
For face recognition |
2 |
BME280 |
BME280 Sensor |
Collect humidity and temperature parameters |
3 |
T1341MND |
White light tube |
For general indicator lights |
The devices prepared for this work:
Serial number |
model |
name |
use |
1 |
STM32H7B3I-DK |
STM32 Development Board |
Implementing the main control interface |
2 |
DFR0745 |
Voice recording and playback module + small speaker |
Used to play various prompt voices |
3 |
PicoW |
Raspberry Pi MCU Development Board |
Used to control voice module and light strip |
4 |
WS2812B |
RGB Light Strip |
Used as a medicine box indicator |
2. System Block Diagram
The entire system block diagram is shown below.
As shown in the figure above, I chose an STM32H7B3I-DK development board as the main control. The development board comes with a 480*272 resolution capacitive touch screen and uses the STM32H7 series CPU, which has powerful computing power and rich peripheral interfaces. The OpenMV module is connected to the main control through the serial port and passes the face recognition results to the main control. The BME280 sensor is connected to the main control through the I2C interface and is responsible for collecting temperature and humidity parameters. In order to facilitate the debugging of the program and modular processing, I chose a PicoW development board to control the light strip and voice recording and playback module to realize the indicator light prompt and voice prompt of the medicine box. The PicoW development board is connected to the main control through the serial port.
3. Functional description of each part
- STM32H7B3I-DK development board main control
Using this development board, it is easy to make a beautiful human-computer interaction program based on TouchGFX. This work has three human-computer interaction interfaces, namely the home page, the medicine collection page, and the management page, which are introduced below.
(1) Home page
This page is the interface displayed when the computer is turned on. The design picture is as follows.
The left half is the information interface, which mainly displays the year, month, day, time, temperature and humidity. There are two buttons on the right half, pointing to the two main function pages respectively.
The time data comes from the RTC built into the microcontroller. The temperature and humidity data come from the humidity and temperature sensor BME280. At this time, no connection has been established, and a random number is displayed.
(2) Medicine collection page
This page is an automatic or manual medicine collection interface, which supports up to 6 people to store medicine, and each person supports up to 16 kinds of medicine. The design picture is as follows.
There are two ways to collect medicine: automatic face recognition and manual. When you click the "Get Medicine" button on the homepage, the camera will start to automatically recognize the face. If the recognition is successful, the person picking up the medicine and the corresponding medicine box number will be automatically displayed. If the recognition fails, you can only manually click the corresponding person button, and the medicine box number will be displayed on the right. The person picking up the medicine can pick up the medicine according to the number.
(3) Management page
This page is used to set the person and medicine, and enter the face information. The number of people and medicines supported is consistent with the medicine picking interface. The design picture is as follows.
When setting, first click the person character on the left, then click the medicine box number on the right. The medicine box number button that lights up represents the corresponding medicine box. Then click the Save button to store the setting information. Finally, click the Enter button to start face shooting. The face storage number corresponds to the selected person character.
- OpenMV Face Recognition Module
At first, I used the official website routines for design. The routines required manually creating folders on the TF card and then recording pictures separately. The whole operation process was cumbersome and the structure was loose. I had no idea where to start if I wanted to integrate it into my work this time. After thinking about it, I planned to refer to the routines and rewrite a program myself to achieve the specific functions of this work. I used Kimi as an assistant, and after several continuous debugging, I finally adjusted the program. It mainly realizes the following functions.
(1) If the character commands '1', '2', '3', '4', '5', '6' are received through serial port 3, six face images will be recorded and placed in six folders named '1', '2', '3', '4', '5', '6' in the SD card.
(2) For each face, 10 pictures should be recorded in grayscale pgm format with a resolution of 128*128. The recording interval is 1 second, and the green indicator light flashes once to indicate that the storage of each picture is completed;
(3) If the character command 'r' is received through serial port 3, the face recognition program is started and the find_lbp function is used for feature extraction;
(4) Use the match_descriptors function to compare the features extracted in the previous step with the features of all stored face images and calculate the difference to find the value with the smallest difference.
(5) If the minimum value is less than a preset threshold, it means the recognition is successful. Send the folder name where the minimum difference value picture is located through serial port 3;
(6) If the minimum value is not less than a preset threshold, it means that the recognition fails and '0' is sent through serial port 3.
The serial communication protocols corresponding to these functions are as follows:
(1) The MCU sends characters '1'-'6' corresponding to 6 characters, and enters the face. After the entry is completed, OpenMV returns the character 'k'.
(2) The MCU sends the character 'r' for face recognition. If the recognition is successful, OpenMV returns the characters '1'-'6' corresponding to the 6 characters respectively. If the recognition fails, the character '0' is returned.
After the code is edited, it is time to do experiments. It is too troublesome to find real people to take photos continuously at this time, so I thought it would be the same to find ready-made photos on the Internet for testing. After searching for information, I finally decided to use the "CK Expression Classification Dataset". This dataset contains various expression pictures of multiple people. Each expression records a few to more than ten pictures, and the total number of pictures for each person is more than dozens. I selected 7 people and used part of each person's pictures as training comparison references, and the rest as test pictures. This solved the problem of needing different people to take pictures.
I just need to display a reference or test image on another monitor, adjust the camera to the right distance, and I can test it perfectly. The picture below is the actual debugging and taking pictures, and the test effect is very good.
The debug information output in OpenMV IDE shows that the program runs correctly.
The expected functions of sending instructions and receiving results are also fully realized on the serial port terminal.
3. BME280 sensor
Due to the limited amount of money, I can only buy one BME280 chip. The chip package is very small, so I need to make a PCB myself. I designed a simple circuit on EasyEDA, which mainly realizes three functions: a. screen transfer; b. humidity and temperature sensor BME280 transfer; c. A package for the MLX90640 infrared thermal imaging sensor is reserved.
The specific circuit is shown in the figure below:
After the schematic is drawn, the PCB designer first connects some power lines, and the remaining signal lines are directly routed automatically, basically without any brainstorming, and it is done in a short time. As shown in the figure below.
The BME280 sensor has two interfaces, SPI and I2C. I use the I2C interface to connect to the main control board. I find the driver on GitHub and configure it in the main program. It is very easy to use. After reading the temperature and humidity parameters successfully, the effect displayed on the screen is as shown below.
4. PicoW-driven voice module and light strip display
In the initial plan, we wanted to use the STM32 main control to directly drive the voice module and the light strip display. However, during the debugging process, we found that the timing of connecting the STM32H7 to the WS2812B light strip was difficult to deal with. We did not have a logic analyzer to find the cause, so we added a PicoW development board in the middle as a transfer. We had used this PicoW development board to debug the WS2812B light strip before, and the program was easier to design. We also had debugging experience on the voice module on the PicoW development board, so we integrated it together.
First, let me introduce the design of the light strip indicator light. According to the plan, the medicine box has 16 grids. Each time you take medicine, you need to light up the lights of the corresponding grids according to the pre-set settings. In the software, I use a 16-bit variable to store the setting value, and each bit represents a light. The light strip I bought is 1 meter long with a total of 30 lights. In order not to destroy the entire light strip, I use a serpentine layout, as shown below.
There are 3 idle lights at each corner and 5 idle lights at the end of the light strip, so the 16 lights I need to use are not continuous. When designing the program, I need to remap the 16-bit numbers to correspond to these lights. The specific implementation is to make a table and sort the order by looking up the table. The specific program is shown in the figure below.
The program of PicoW development board is written in CircuitPython. The lighting program realizes the function of lighting up 4 lamp beads and leaving 3 idle lamp beads in between. The code is as follows.
The expected function is achieved through the cooperation of the two parts.
The voice part is relatively simple, just send AT commands through the serial port. For details, please refer to the attached code. Here is the method of voice generation. I found a free website as follows:
Text can be synthesized into multiple voices, which is very convenient.
The synthesized MP3 format voice file is stored in the chip according to the sequence number specified by the voice chip, and the corresponding audio can be specified to be played in the program.
4. Source Code
The STM32H7B3I-DK program is developed based on TouchGFX.
OpenMV programs are developed using OpenMV IDE.
The PicoW program is developed using CircuitPython.
Home Sharing Smart Pill Box Source Code
5. Demonstration video of the work’s functions
6. Project Summary
Thanks to EEWorld and Digi-Key Electronics for providing me with this opportunity to experience the various wonderful applications of OpenMV. The other boards used in this work were also obtained from participating in our forum activities. I feel that participating in these activities can not only try new technologies and new solutions, but also continuously improve my technical level. I hope that the forum activities will continue and the boards will continue to be updated.
The link below is a sharing post about the experience in the development of this work. The content that is not introduced in detail in this article can be found in the post below.
VII. Others
none.
|