DEV Community

Cover image for Embedded Rust on the ESP32 : Getting started - Setup
Vaishnav-sabari-girish
Vaishnav-sabari-girish

Posted on • Edited on

Embedded Rust on the ESP32 : Getting started - Setup

What are Embedded Systems ?

Embedded systems are tiny computers built into devices to perform specific tasks. Unlike general-purpose computers, they are designed for control, automation, and real-time operations. You'll find them in everything from smartwatches to washing machines.

What is ESP32 ?

The ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi and Bluetooth, developed by Espressif Systems. It's widely used in IoT projects due to its rich set of peripherals, dual-core processor, and community support. Perfect for smart devices, sensors, and wireless applications.

What is Rust ?

Rust is a systems programming language focused on safety, speed, and concurrency. It’s known for preventing common bugs at compile time without needing a garbage collector.

Features of Rust

  1. Memory Safety : Eliminates NULL pointer and buffer overflows due to it's ownership and lifetimes features.
  2. Zero-cost abstraction : High-level code with low-level performance.
  3. Concurrency : Fearless Multithreading without Race conditions.
  4. Modern Tooling : cargo makes it easier for project management and installing Rust tools. cargo is for Rust what pip and uv are for Python.
  5. Cross-platform support : From Bare-metal Linux to WebAssembly.

Why use Rust for Embedded Systems ?

Rust offers the performance of C/C++ with memory safety guarantees, making it ideal for low-level, resource-constrained environments. Its strong compile-time checks prevent many common embedded bugs early in development. With growing ecosystem support (like esp-hal), Rust is becoming a powerful and ergonomic choice for writing safe, efficient firmware for microcontrollers like the ESP32.


Setting up the Environment

This blog assumes that :

  1. You are using a Linux Distribution (Like Ubuntu, Fedora , Debian or Arch).
  2. You have installed Rust. If not install it by following the instruction here
  3. You are familiar with using the Terminal.

Hardware

  1. ESP32-WROOM

esp32wroom

For future blogs, the following sensors are required :

  1. HC-SR04 Ultrasonic Sensor

us

  1. DHT22 Temperature and Humidity Sensor:

dht22

  1. Touch Sensor :

ts

Installing the tool chain

ESP32 doesn't have enough power to run a full OS based program, so we will be using the no_std library for Embedded Programming.

Install the following tool chains

  1. Installing espup . This is a tool that simplifies installing and maintaining the components required to develop Rust applications for the Xtensia and RISC-V architectures. (Make sure that cargo is in your PATH).
cargo install espup
Enter fullscreen mode Exit fullscreen mode
  1. Installing the necessary tool-chains
espup install
Enter fullscreen mode Exit fullscreen mode
  1. Now a file named export-esp.sh will be created in your $HOME directory. Add it's contents to your ~/.bashrc or ~/.zshrc using the following command
cat $HOME/export-esp.sh >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

The export-esp.sh file consists of all the environment variables required to run the Rust Code.

You are now ready to write Embedded Rust Code

Find the other blogs here

  1. Hello World
  2. LED Blinking
  3. Button interfacing
  4. Sensor Integration
    1. DHT22 Temperature and Humidity Sensor
    2. [Ultrasonic Sensor]
    3. [Touch Sensor]

Miscellaneous Links

  1. GitHub Repository
  2. Official Documentation

Top comments (0)