Project 2 - Integrate following sensors to the Dev Board
Project 2 - Integrate following sensors to the Dev Board
Integrate following sensors to the Dev Board:
l GPS
l IMU Sensor
Achieve the following task with the help of these sensors:
1. The microcontroller should automatically detect sensor’s (GPS + IMU) connection and disconnection and print suitable string over the terminal (Serial to USB used)
2. You should use buffer for receiving GPS data over UART, and should enable UART Reception Interrupt.
3. IMU data to come over I2C, you should carry this data in Separate Queue according to Sensor (Accelerometer + Gyro) to a particular task.
4. Main Objective is to identify the GPS location and whenever there is a change in distance greater than 100m, the system should print out the Co-ordinates along with IMU sensor values.
5. Printing of the values can be done by transferring values over UART and then Serial to USB can be used to view at Terminal Window.
Aim:
To integrate an Inertial Measurement Unit (IMU) with a microcontroller and classify data coming from the accelerometer and gyroscope. The goal is to send the respective sensor data to separate queues and use a dedicated task to identify the data source using Queue Sets. Finally, the project transfers the data to the appropriate UART channel for monitoring and analysis.
Tools and components Used:
1. STM32CubeIDE for writing and compiling the code,
2. STM32CubeMX for configuring the microcontroller peripherals, and
3. Hercules for monitoring the UART output,
4. STM32F446RE Nucleo64 Board,
5. MPU6050 Sensor module.
Theory:
The MPU6050 is initialized via I2C for acquiring Accelerometer and Gyroscope data. GPS data is received over UART using the USART1 interface. Two separate queues are created for storing Accelerometer and Gyroscope data. A Queue Set is utilized to wait for data from either queue. UART interrupts are used for GPS data reception.
Code:
Note: click the below URL to download the complete Project ZIP file
URL:https://drive.google.com/drive/folders/1AVRtF4cXikpa-38bRgrUWakd90VT0y8s?usp=sharing
CODE EXPLANATION:
Ø Initialization:
n MCU, GPIO, I2C, and UART peripherals are initialized.
n MPU6050 module is configured for accelerometer and gyroscope parameters.
Ø Task Creation:
n Three tasks are created:
u DataAcquisitionTask: Acquires and logs Accelerometer and Gyroscope data.
u DataProcessingTask: Processes and logs data from the accelerometer and gyroscope queues.
u GPS_ProcessDataTask: Processes received GPS data.
Ø Data Acquisition Task:
n Acquires accelerometer and gyroscope data.
n Logs data over UART.
Ø Data Processing Task:
n Waits for data in the Queue Set.
n Processes and logs accelerometer and gyroscope data.
Ø GPS Process Data Task:
n Monitors GPS data reception flag.
n Processes and prints GPS data.
n Calculates distance change using Haversine formula.
n Prints coordinates and IMU sensor values if the distance change is greater than 100m.

EXPECTED OUTPUT:
1. Initial data from GPS:
UART initialized
[0] Sent Accelerometer: X= 0.1, Y= -0.2, Z= 9.8
[1] Sent Gyroscope: X= 2.5, Y= -1.0, Z= 0.3
[2] Received Accelerometer: X= 0.1, Y= -0.2, Z= 9.8
[3] Received Gyroscope: X= 2.5, Y= -1.0, Z= 0.3
GPS Data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
Distance Change: 0.0m, Latitude: 48.117300, Longitude: 11.516700, Altitude: 545.4,
Accelerometer: X= 0.1, Y= -0.2, Z= 9.8, Gyroscope: X= 2.5, Y= -1.0, Z= 0.3
2. Subsequent data after a simulated distance change:
[GPS] Received Data: $GPGGA,34.0535,-118.2420,100
[GPS] Distance Change: 150.05m
[IMU] Accelerometer: X= 0.1, Y= -0.2, Z= 9.8
[IMU] Gyroscope: X= 1.5, Y= 2.0, Z= -0.5
[INFO] Distance Change > 100m. Coordinates: Lat= 34.0535, Lon= -118.2420, Alt= 100.0
[INFO] Accelerometer: X= 0.1, Y= -0.2, Z= 9.8, Gyroscope: X= 1.5, Y= 2.0
CONCLUSION:
The code successfully integrates GPS and IMU sensors, demonstrating accurate data acquisition and processing. The implementation ensures proper sensor connections and effectively detects and reacts to significant changes in distance.
KEY leanings:
The project provides a practical example of integrating sensors, specifically an Inertial Measurement Unit (IMU) with an accelerometer, gyroscope and GPS, into a FreeRTOS-based embedded system. The key learnings from this project include:
1. Sensor Integration:
l Learned how to integrate and manage different sensors, such as GPS and IMU, in a microcontroller-based system.
2. Interrupt-driven UART Communication:
l Gained experience in setting up and handling UART communication with interrupt-driven reception, enhancing the efficiency of data transfer.
3. Multitasking with FreeRTOS:
l Explored the implementation of multitasking using FreeRTOS, organizing tasks for data acquisition, processing, and GPS handling concurrently.
4. I2C Communication with MPU 6050:
l Understanding of I2C communication for interfacing with the MPU 6050 sensor, retrieving accurate accelerometer and gyroscope data.
5. Queue-based Communication:
l Utilized queues for efficient communication between tasks, ensuring a synchronized flow of data and preventing race conditions.
6. Mutex for Data Integrity:
l Implemented a mutex to protect shared data, ensuring thread-safe operations and preventing conflicts in data manipulation.
7. Coordinate Distance Calculation:
l Learned the Haversine formula for calculating distances between GPS coordinates, a crucial skill for location-based applications.
8. Debugging and Monitoring:
l Gained proficiency in debugging embedded systems using tools like Hercules for monitoring UART output, aiding in identifying and resolving issues.
9. Real-world Application Understanding:
l Applied theoretical knowledge to solve real-world problems, emphasizing the practical application of sensor data in a location-based context.
10. System Responsiveness:
l Achieved a system that responds dynamically to changes, such as significant shifts in GPS coordinates, demonstrating the importance of real-time responsiveness in embedded systems.
These key learnings collectively contribute to a comprehensive understanding of sensor integration, communication protocols, multitasking in embedded systems, and practical application scenarios.
Drive link for documents:
https://drive.google.com/drive/folders/1hULcZ_CHRFdBo4thDJ7pzZsdPS2g5R6w?usp=sharing