This Final Project Report is a supplement to the Final Project Minimum Project Requirement Detail. An embedded microscontroller was used to create a propane tank weight measurement system. Source code is available on GitHub.
See also the YouTube Video:
This application is an embedded controller to monitor grill propane tank weight to replace the existing mechanical spring scale:
This project uses the STM32L475VG,
part of the STM32 Ultra Low Power Arm Cortex-M4 32-bit MCU+FPU series
found on the B-L475E-IOT01A Discovery Board.
The application is written in C/C++ and targets the STM32 ARM Platform.
The code is a multi-threaded FreeRTOS embedded application. There are 5 threads named LED1, LED2, UART1, DISPLAY, and PWM.
The LED1 Thread is a simple state machine and controls LED1 (blinky, on, or off).
This thread also sends pressure reading and scale weight text to the UART.
The LED1 Thread monitors the state machine and blinks LED2 depending on the current state:
IsBlinking
- one blinkAlwaysOn
- two blinksAlwaysOff
- three blinks
Just to test RTOS concurrency (and hard fault avoidance!) the UART1 Thread sends a "Hello UART1" message to the UART about every 1.35 seconds. An odd number was chosen to ensure pseudo-random conflicts in timing with other messages.
This particular screen snip (above) is interesting. Note the seemingly stray "105" value. Apparently this is where the thread tried to grab a mutex to use the UART, but one was not available on a timely basis, so it skipped the entire "1 weight" part of the message. Recall this occurs in two steps:
UART_TxMessageIntValue(WeightMessage, sizeof(WeightMessage), CurrentTankWeight);
// (RTOS Thread swtich occured around here)
UART_TxMessage(CrLf, sizeof(CrLf));
The Display Thread is where the scale is monitored and the value displayed on the screen.
There's also a small state machine monitoring for a button long press to then tare the scale and save the offset value to flash.
The PWM thread is included only for "interesting" experiements and is not required for basic functionality.
After some initial code experiments, the thread runs in a loop sending barometric pressure reading to the UART every 2 seconds.
Code Explorer View of main()
The main code repository can be found at github.com/gojimmypi/IoT_BBQ/tree/main/IoT_BBQ_STM32. MIT License.
-
Display Code was written specifically for this project. MIT License.
-
Flash Config was created from scratch for this project. MIT license.
-
LED Blinky and State Machine created by gojimmypi for this project. MIT license.
-
UART created for this project, MIT license. Uses stm32l4xx_hal.h assumed to still be BSD 3-Clause license
This project was created using the Sysprogs VisualGDB Extension for Visual Studio 2019. A tiny amount of initialization code was generated using the STM32CubeIDE.
-
HX711 Arduino Library was ported to this STM32 HAL environment with FreeRTOS support. MIT License.
-
STM hsensor HAL BSD 3-Clause license.
-
STM Pressure Sensor HAL BSD 3-Clause license
-
ssd1306 display driver was created by Aleksander Alekseev and modified for this project. MIT License
-
Flash HAL. Assumed to still be Licensed by ST under BSD 3-Clause license, but the license File is now blank.
Additional thanks to Elecia White (the Making Embedded Systems Instructor) for the code review, in particular to help find the cause of those nasty Hard Faults.
Also thanks to the class mentors Erin, Daniel, Thomas, and Jeff... as well as all my classmates on the discord channel. A lot of smart and creative people
with all sorts of interesting ideas!
Show below is the basic diagram of the architecture. The network feature has not yet been implemented:
There are two options for building: the GUI from Visual Studio and a command-line batch file, both on Windows.
Open the Visual Studio Solution File called IoT_BBQ_STM32.sln.
Find the IoT_BBQ_STM32
Project. Right-click and select "Build...":
To build and upload code, simply click the green VisualGDB Debugger
button:
If the build was successful, the code will be sent to the board:
If the STM32 toolchain is installed (for Windows) there's also an auto-generated batch file to build from command-line.
See also Project Readme Build Instructions
The only toolchain required for this project is the VisualGDB Extension. See the Developing STM32 projects with Visual Studio walk-through.
These settings are included the project solution file but included here for reference:
Project Config Step 1:
Project Config Step 2:
Project Config Step 3:
See above for the build instructions.
- Mouser ST B-L475E-IOT01A1
- Amazon SSD1306 I2C Serial
- Sparkfun Load Cell Amplifier HX711
- Adafruit Strain Gauge Load Cell - 4 Wires - 20Kg
Hardware wiring diagram:
The source code can be downloaded from GitHub gojimmypi/IoT_BBQ. The only other software needed is Visual Studio and VisualGDB (and an internet connection, as VissualGDB will download and install toolchains and libraries as needed.)
All of the development and debugging was completed in Visual Studio using breakpoints and the single-step-debugging features available from the VisualGDB extension.
Single-step inspection:
Heap pointer check:
Memory address inspection:
Breakpoints, code explorer, and other system monitoring features were quite helpful:
Although the discovery board was convenient from a getting started perspective, it is also massive and power hungry.
The next steps are to port this project to a Blue Pill.
Key to a production deployment would be an enclosure and some way to have them mass-produced. For large-scale production, some means of
mass-programming the devices would be needed. It would not be practical to manually plug in a million boards and program them each one at a time.
How would you extend this project to do something more? Are there other features you'd like? How would you go about adding them?
I chose this particular IoT Discovery board for the WiFi capabilities. As it turns out, the power consumption is simply way too high for battery operation. Our grill is located a bit far from the house; I certainly don't want to run an extension cord. I have some LoRa experience and plan to see if I can get that working with an MQTT server.
There are also plans for including a firebox temperature sensor, specifically the MAX6675 Module + K Type Thermocouple Temperature
as described in the original README from a few years back
when I created something for the ESP8266.
Self assessment of the project: for each criteria, choose a score (1, 2, 3) and explain your reason for the score in 1-2 sentences. Have you gone beyond the base requirements? How so?
Criteria | 1 - Needs Improvement | 2 - Meets Expectations | 3 - Exceeds Expectations |
---|---|---|---|
Project meets minimum project goals | 2+ Basic State Machine, additional sensors LPS22HB, HX711, well documented. No serial commands | ||
Completeness of deliverables | Readable code, each point addressed, video | ||
Clear intentions and working code | 2+ System works as decribed | (docs not as professionally polished as I'd like) | |
Reusing code | License summary and Build Info | ||
Originality and scope of goals | This is clearly an awesome Propane Tank Weight Project! ;) The scope of goals was appropriately challenging yet reasonable for the class. | ||
Self-assessment (Mentor category only) | n/a | ||
Bonus: Power analysis, firmware update, or system profiling | Power Analysis also shared on Twitter | ||
! Bonus: Version control was used. | hundreds of commits |
- I created the video footage of the project in action on my phone and took all the pictures, but the final consolidated video was assembled and subtitled by someone else. Thank you!!!
See the Class Assignment additional links for other resources.