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.
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.
| Level | Time needed |
|---|---|
| Advanced | 3-4 hours |
What you need (tools and setup)
| Tool | What it is | Why you need it | Cost |
|---|---|---|---|
| This course's live C sandbox | A 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) — optional | The 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
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
- Create a sensor-reading producer task at a moderate priority.
- Create a logging/processing consumer task at a lower priority.
- Connect them with an RTOS message queue (or software queue if no RTOS is available).
- Confirm the consumer processes every reading the producer posts, in order.
- Verify the system behaves correctly even if the consumer is temporarily slower than the producer.
Checklist before you call it done
| Check | Why it matters | How to verify |
|---|---|---|
| Every posted reading is eventually consumed, none lost | Confirms the queue is sized and used correctly | Count postings vs consumptions over a test run |
| Producer and consumer run independently without direct coordination | Confirms proper decoupling via the queue | Review that neither task directly calls or blocks on the other |
| System remains stable if the consumer briefly falls behind | Confirms the queue absorbs temporary rate mismatches gracefully | Temporarily slow the consumer and observe behavior |
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?
This project applies the RTOS group's message-queue lesson directly: a queue decouples the producer and consumer tasks' independent timing.