Home / Learn Embedded C / Project: Two-Task RTOS Demo

Project: Two-Task RTOS Demo

Create two independent RTOS tasks at different priorities, communicating through a queue.

Bottom lineCreate two independent RTOS tasks at different priorities, communicating through a queue.

Breaking it down

The basic idea

Two RTOS tasks — one producing sensor readings, one consuming and logging them — communicating safely through a message queue, demonstrating the producer-consumer pattern at the RTOS level.

Why this comes up

Real projects are where embedded C patterns become habits instead of theory.

The mechanics

Work through the steps in order; do not skip the checklist.

Where it is used

  • Portfolio project
  • Interview preparation
  • Real hardware practice

What you will build

Two RTOS tasks — one producing sensor readings, one consuming and logging them — communicating safely through a message queue, demonstrating the producer-consumer pattern at the RTOS level.

LevelTime needed
Advanced3-4 hours

What you need (tools and setup)

ToolWhat it isWhy you need itCost
This course's live C sandboxA small in-browser C interpreter with simulated GPIO/UART/ADC/PWM.Every project in this course can be tried here first with zero setup, no board required.free, built in
Code editor (VS Code or similar)The program you write firmware source files in.You need somewhere to write and organise the real .c/.h files for the project.free
A real development board (Arduino/AVR, STM32 Nucleo, or ESP32 dev board) — optionalThe actual microcontroller hardware.Lets you move from the simulated board to a real one once the logic works here.low cost, optional

Step 1: see it working in the sandbox

Simulating a producer task posting to a queue, and a consumer task reading itC: edit and run

This models the RTOS queue concept with a plain circular buffer; a real RTOS queue API (like xQueueSend/xQueueReceive) handles the synchronization automatically.

Step by step

  1. Create a sensor-reading producer task at a moderate priority.
  2. Create a logging/processing consumer task at a lower priority.
  3. Connect them with an RTOS message queue (or software queue if no RTOS is available).
  4. Confirm the consumer processes every reading the producer posts, in order.
  5. Verify the system behaves correctly even if the consumer is temporarily slower than the producer.

Checklist before you call it done

CheckWhy it mattersHow to verify
Every posted reading is eventually consumed, none lostConfirms the queue is sized and used correctlyCount postings vs consumptions over a test run
Producer and consumer run independently without direct coordinationConfirms proper decoupling via the queueReview that neither task directly calls or blocks on the other
System remains stable if the consumer briefly falls behindConfirms the queue absorbs temporary rate mismatches gracefullyTemporarily slow the consumer and observe behavior
Tip:Commit the first working version and every later improvement as separate commits, so the diff itself becomes a teaching example.
Sending a 2nd message through the inter-task queueC: edit and run

This models two messages flowing through the same small queue structure used by the main two-task demo.

Quick check

1. What RTOS concept from earlier in the course does the queue in this project directly rely on?