Learn Zephyr-rtos - 3 Code Examples & CST Typing Practice Test
Zephyr RTOS is a scalable, open-source real-time operating system designed for resource-constrained embedded devices. It provides a small, configurable kernel, drivers, and networking stacks to enable IoT, wearable, and sensor-based applications with predictable timing and low memory footprint.
View all 3 Zephyr-rtos code examples →
Learn ZEPHYR-RTOS with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
Blink LED Task
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#define LED_PIN 2
#define SLEEP_TIME_MS 500
default struct device *led_dev;
void blink_led(void)
{
while(1) {
gpio_pin_toggle(led_dev, LED_PIN);
k_msleep(SLEEP_TIME_MS);
}
}
void main(void)
{
led_dev = device_get_binding("GPIO_0");
gpio_pin_configure(led_dev, LED_PIN, GPIO_OUTPUT);
blink_led();
}
Toggle an LED on a GPIO pin using a Zephyr thread.
Periodic Thread Example
void periodic_task(void *arg1, void *arg2, void *arg3)
{
while(1) {
printk("Periodic task running\n");
k_sleep(K_SECONDS(1));
}
}
K_THREAD_DEFINE(periodic_thread, 1024, periodic_task, NULL, NULL, NULL, 7, 0, 0);
Create a periodic thread to execute a task every 1 second.
Sensor Reading Example
#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>
void main(void)
{
struct device *dev = device_get_binding("SENSOR_0");
struct sensor_value val;
while(1) {
sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_ALL, &val);
printk("Sensor value: %d\n", val.val1);
k_sleep(K_SECONDS(2));
}
}
Read data from a sensor and print values periodically.
Frequently Asked Questions about Zephyr-rtos
What is Zephyr-rtos?
Zephyr RTOS is a scalable, open-source real-time operating system designed for resource-constrained embedded devices. It provides a small, configurable kernel, drivers, and networking stacks to enable IoT, wearable, and sensor-based applications with predictable timing and low memory footprint.
What are the primary use cases for Zephyr-rtos?
Real-time task scheduling for embedded applications. Low-power IoT devices and wearables. Sensor data acquisition and processing. Networking-enabled devices with MQTT, CoAP, or BLE. Industrial automation and edge computing
What are the strengths of Zephyr-rtos?
Small memory footprint suitable for constrained devices. Highly configurable and modular to optimize resource usage. Strong community and open-source ecosystem. Supports real-time deterministic behavior. Cross-platform portability across multiple MCUs
What are the limitations of Zephyr-rtos?
Limited to embedded and resource-constrained platforms. Complex for beginners without RTOS experience. Networking and advanced features require configuration knowledge. Debugging multi-threaded real-time applications can be challenging. Smaller ecosystem compared to Linux or FreeRTOS in certain areas
How can I practice Zephyr-rtos typing speed?
CodeSpeedTest offers 3+ real Zephyr-rtos code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.