Unleash the power of multitasking FreeRTOS-like (Real Time Operating System) for your tiny MCU!
Well, kind of. TinyRTOS is a cooperative task scheduler for 8-bit AVR MCUs
with at least 256 byte RAM.
Enables multiple tasks to run seemingly simultaneously on the popular microcontrollers with as little as 256 bytes of RAM.
🆕 What's new?
- 01.12.2026 Release V1.6.0 with cooperative
delay()– even inside libraries.
-- More news? Check the newsblog.
-
Tested: Attiny45/85/44/84, ATmega328 (Arduino Uno/Nano).
-
Any other ATtiny MCU with 32 general-purpose registers and at least 256 bytes of RAM should be compatible (e.g. ATtiny461, ATtiny861). ATtinys with only 16 registers (ATtiny4/5/9/10/20/40/102/104) or less than 256 bytes of RAM (e.g. ATtiny13, ATtiny2313, ATtiny25) are not supported.
-
Any other AVR MCU with up to 128 KB flash should be compatible (e.g. ATmega88, ATmega1284P, ATmega32U4) – the kernel uses only standard AVR instructions and registers.
-
Newer AVR Dx MCUs (e.g. AVR128DA28) should be compatible via DxCore, but are not yet tested.
-
Experimental: ATmega2560 (No board available)
- Arduino IDE with ATTinyCore (Spence Konde) for classic ATtiny MCUs
- Arduino IDE with megaTinyCore (Spence Konde) for tinyAVR 0/1/2-series MCUs
- Arduino IDE with Arduino AVR Core for ATmega MCUs
- millis()/micros():
Enabled
TinyRTOS can be installed directly via the Arduino IDE Library Manager.
Search for TinyRTOS and click Install.
#include "TinyRTOS.h"
void taskA() {
pinMode(3, OUTPUT);
while (true) {
digitalWrite(3, HIGH); rtos_delay(500);
digitalWrite(3, LOW); rtos_delay(500);
}
}
void taskB() {
pinMode(4, OUTPUT);
while (true) {
digitalWrite(4, HIGH); rtos_delay(125);
digitalWrite(4, LOW); rtos_delay(125);
}
}
void setup() {
rtos_add_task(taskA);
rtos_add_task(taskB);
rtos_run(); // Never returns
}
void loop() {} // Will never runPB3 and PB4 are free I/O pins used in the example sketch.
| Function | Description |
|---|---|
rtos_add_task(func) |
Register a task (before rtos_run()) |
rtos_run() |
Start the scheduler |
rtos_yield() |
Yield the CPU cooperatively |
rtos_delay(ms) |
Wait and yield during the delay |
rtos_lock(lock) |
Lock a shared resource – waits if already in use |
rtos_unlock(lock) |
Release the lock |
ATtiny85 (doubleBlink):
2 tasks, 1 × 64 bytes stack = 64 bytes
+ kernel overhead = 8 bytes
+ millis() (Arduino core) = 9 bytes
──────────────────────────────────────────
Total = 81 bytes
ATmega328 (without Serial):
3 tasks, 2 × 192 bytes stack = 384 bytes
+ kernel overhead = 10 bytes
──────────────────────────────────────────
Total ≈ 394 bytes
ATmega2560:
4 tasks, 3 × 192 bytes stack = 576 bytes
+ kernel overhead = 12 bytes
──────────────────────────────────────────
Total ≈ 588 bytes
Stack size and task count can be adjusted before including the library:
#define TINYRTOS_MAX_TASKS 3
#define TINYRTOS_STACK_SIZE 96
#include "TinyRTOS.h"The first task registered with rtos_add_task() runs on the normal Arduino stack
and can use all free RAM. Register the task with the deepest call stack
(e.g. the one using Serial) first.
⚠️ Minimum: 40 bytes per task (except the first). Deep call stacks require more.
When all tasks are waiting in rtos_delay() or rtos_lock(), TinyRTOS puts the CPU
to sleep until the next millisecond tick. Timer0 keeps running, so millis() stays
accurate. A task waiting in rtos_lock() checks the lock once per tick. A task waiting in
delay() keeps the CPU awake.
Costs ~80 bytes of flash and 2 bytes of RAM. To disable, uncomment in TinyRTOS.h:
#define TINYRTOS_NO_IDLE_SLEEPWorth doing on a 4 KB ATtiny when flash runs short, or when your sketch manages sleep modes itself.
TinyRTOS is a cooperative task scheduler, not an operating system. There is no memory protection, no process isolation, and no dynamic memory management. A misbehaving task can corrupt others and will not be caught.
On an ATtiny45 with 256 bytes of RAM this is not a limitation but the only sensible approach. TinyRTOS replaces nested state machines with readable, linear task code. Nothing more, nothing less.
So why call it an RTOS? Because TinyCooperativeRoundRobinTaskScheduler or TinyCRRTS sounds really weird. And FreeRTOS calls itself an RTOS too – it's a preemptive scheduler with considerably more RAM, a much longer feature list and better marketing. But on a chip so tiny you can lose it between your keyboard keys, RTOS feels just about right.
Note
TinyRTOS relies on programming discipline instead of preemptive interruption. Alas.
- Prefer
rtos_delay()overdelay()– both let other tasks run, but onlyrtos_delay()lets the CPU sleep.delayMicroseconds()and_delay_ms()still block, and so doesdelay()on megaTinyCore (tinyAVR 0/1/2) - No long loops without
rtos_yield()in between - Never call
rtos_yield()from an ISR or with interrupts disabled, it always returns with interrupts enabled - Always call
rtos_unlock()– a missing unlock blocks the other task forever. - Tasks must be infinite loops – returning causes undefined behavior
TinyRTOS defines yield() to make delay() cooperative, so it can't be combined
with other libraries that define yield() (e.g. other schedulers).
Apache 2.0 – free to use, including commercially.
TinyRTOS is free and open source. If it saved your day, consider buying me a coffee! ☕
Every contribution helps keep this project alive! 🚀
