Skip to content

Latest commit

 

History

History
296 lines (166 loc) · 14.9 KB

Final_Project_Report.md

File metadata and controls

296 lines (166 loc) · 14.9 KB

Final Project Report

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:

you_tube_preview.jpg

Application Description

This application is an embedded controller to monitor grill propane tank weight to replace the existing mechanical spring scale:

Existing_tank_scale.png

Hardware Description

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.

Software description

The application is written in C/C++ and targets the STM32 ARM Platform.

Describe the code in general

The code is a multi-threaded FreeRTOS embedded application. There are 5 threads named LED1, LED2, UART1, DISPLAY, and PWM.

LED1 Thread

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.

LED2 Thread

The LED1 Thread monitors the state machine and blinks LED2 depending on the current state:

  • IsBlinking - one blink
  • AlwaysOn - two blinks
  • AlwaysOff - three blinks

UART1 Thread

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.

Hello_UART.png

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));



DISPLAY Thread

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.

PWM Thread

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()

main_code_explorer.png

Describe the parts you wrote in some detail (maybe 3-5 sentences per module)

The main code repository can be found at github.com/gojimmypi/IoT_BBQ/tree/main/IoT_BBQ_STM32. MIT License.

Describe code you re-used from other sources, including the licenses for those

This project was created using the Sysprogs VisualGDB Extension for Visual Studio 2019. A tiny amount of initialization code was generated using the STM32CubeIDE.

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!

Diagram(s) of the architecture

Show below is the basic diagram of the architecture. The network feature has not yet been implemented:

iot_bbq_block_diagram.png

Build Instructions

There are two options for building: the GUI from Visual Studio and a command-line batch file, both on Windows.

Build in Visual Studio

Open the Visual Studio Solution File called IoT_BBQ_STM32.sln. Find the IoT_BBQ_STM32 Project. Right-click and select "Build...":

VisualGDB_build.png

To build and upload code, simply click the green VisualGDB Debugger button:

VisualGDB_Debugger_Button.png

If the build was successful, the code will be sent to the board:

VisualGDB_build_and_upload.png

Build from Command-Line

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

How to build the system (including the toolchain(s))

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:

VisualGDB_STM32_project_config

Project Config Step 2:

VisualGDB_STM32_project_config_step2

Project Config Step 3:

VisualGDB_STM32_project_config_step3

See above for the build instructions.



Hardware

Hardware wiring diagram:

wiring_diagram.png



Software

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.)



How you debugged and tested the system

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:

HAL_GPIO_ReadPin_code_snippet.png

Heap pointer check:

myHeapPointer_cross_check.png

Memory address inspection:

address_memory_swap_oddity.png

Breakpoints, code explorer, and other system monitoring features were quite helpful:

hard_fault_detail.png



Future

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.

What would be needed to get this project ready for production?

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.

Grading

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.

Final Project Submission

See Final Project Submission