Challenge

Project 2 - Integrate following sensors to the Dev Board

Integrate following sensors to the Dev Board:

  • GPS
  • 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.

Program Flow:

  1. The program starts with the main function, where FreeRTOS is initialized, and two tasks are created: vTaskGPS and vTaskIMU. These tasks represent the GPS and IMU sensor tasks.

  2. Inside the vTaskGPS task:

    • The GPS sensor is initialized.
    • The task continuously checks if the GPS sensor is connected and reads GPS data (latitude and longitude).
    • If GPS data indicates a significant location change (greater than 100 meters), it notifies the vTaskIMU task.
    • The GPS data is sent to the UART for communication.
  3. Inside the vTaskIMU task:

    • The IMU sensor is initialized.
    • The task continuously checks if the IMU sensor is connected and reads IMU data (accelerometer and gyro data).
    • It waits for a notification from the vTaskGPS task, indicating a significant location change.
    • Once notified, it prints GPS coordinates and IMU sensor data to UART for communication.

Important Commands and Concepts:

  • xTaskCreate: Used to create tasks for GPS and IMU sensors with specific priorities and stack sizes.
  • vTaskDelay: Adds a delay in each task loop to control the sensor reading frequency.
  • xTaskNotify and xTaskNotifyWait: Used for inter-task communication between vTaskGPS and vTaskIMU.
  • UART communication: Used to send and receive data between the microcontroller and the external terminal (Serial to USB).
  • Sensor initialization functions: initGPS and initIMU functions are expected to initialize the GPS and IMU sensors, respectively.
  • Sensor data reading functions: readGPSData and readIMUSensorData functions are expected to read data from the GPS and IMU sensors, respectively.

Key Learnings:

  • FreeRTOS is a real-time operating system that allows you to create tasks and manage concurrency in embedded systems.
  • Tasks in FreeRTOS run concurrently, and inter-task communication can be achieved using notifications or other synchronization mechanisms.
  • This program showcases a basic structure for integrating sensors and performing actions based on sensor data.
  • Proper error handling and sensor disconnection detection are essential in real-world applications

UART (Universal Asynchronous Receiver/Transmitter):

  • UART is a communication protocol used for serial communication between a microcontroller and external devices.
  • It involves transmitting and receiving data serially, often through physical pins (TX and RX).
  • In this program, UART is used to send and receive data between the microcontroller and an external terminal for debugging and monitoring.

1. UART Reception Interrupt for GPS Data:

Enabling UART Reception Interrupt is a common approach for efficiently receiving data from UART devices, such as the GPS module. It allows the microcontroller to react immediately when new data arrives, rather than polling the UART continuously.

Implementing UART reception with an interrupt-driven approach typically involves the following steps:

  • Initialize the UART module with the desired baud rate, data format, and other settings.
  • Enable UART reception interrupts.
  • Implement an interrupt service routine (ISR) that is triggered when UART data is received. This ISR should handle receiving and processing incoming data.
  • Use a circular buffer or queue to store received data in the ISR.
  • Modify the vTaskGPS task to read data from the circular buffer or queue instead of directly reading from UART.

2. I2C Communication and Data Queuing for IMU Data:

IMU sensor initialization and data reading functions (initIMU and readIMUSensorData) are declared Implementing I2C communication and data queuing for IMU data typically involves these steps:

  • Initialize the I2C module to communicate with the IMU sensor.
  • Implement functions to read IMU data (accelerometer and gyro data) from the sensor via I2C.
  • Create a queue (e.g., using xQueueCreate) to store the IMU data.
  • In the vTaskIMU task, read IMU data from the sensor and send it to the queue for further processing or storage.
  • Other tasks or processes can then consume data from the IMU data queue as needed.

I2C (Inter-Integrated Circuit) is a serial communication protocol commonly used to connect components in embedded systems. It uses two wires, SDA (Serial Data) and SCL (Serial Clock), for data transfer. I2C enables multiple devices to communicate on the same bus, each with a unique address. It's popular for connecting sensors, displays, and other peripherals to microcontrollers due to its simplicity and versatility.

In the context of the this program, I2C (Inter-Integrated Circuit) is used for communication with the IMU (Inertial Measurement Unit) sensor. The IMU sensor provides data on accelerometer and gyroscopic measurements. I2C is an ideal choice for this task because it allows multiple sensors to be connected to the same bus.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.