1. Home
  2. /
  3. Embedded-rust
  4. /
  5. Read Analog Sensor

Read Analog Sensor - Embedded-rust Typing CST Test

Loading…

Read Analog Sensor — Embedded-rust Code

Read a potentiometer value from an ADC pin and print via serial.

#![no_std]
#![no_main]

use panic_halt as _;
use cortex_m_rt::entry;
use stm32f4xx_hal::{adc::Adc, prelude::*, serial::Serial, stm32};

#[entry]
fn main() -> ! {
	let dp = stm32::Peripherals::take().unwrap();
	let mut adc = Adc::adc1(dp.ADC1, true);
	let mut serial = Serial::usart2(dp.USART2, ...);

	loop {
		let value: u16 = adc.read(&mut dp.GPIOA.pa0).unwrap();
		writeln!(serial, "ADC value: {}", value).unwrap();
	}
}

Embedded-rust Language Guide

Embedded Rust refers to using the Rust programming language to develop software for embedded systems, microcontrollers, and resource-constrained devices. It focuses on safety, performance, and concurrency without relying on runtime environments or garbage collection.

Primary Use Cases

  • ▸Firmware development for microcontrollers
  • ▸Real-time control of sensors and actuators
  • ▸IoT device programming and communication
  • ▸Embedded systems prototyping and development
  • ▸Safety-critical and low-level hardware software

Notable Features

  • ▸Memory safety without runtime overhead
  • ▸Zero-cost abstractions and high performance
  • ▸Strong type system preventing common bugs
  • ▸Hardware-level control through HALs and PACs
  • ▸Support for concurrency and async programming

Origin & Creator

Rust was created by Mozilla in 2010 to offer a safe, fast, and concurrent systems programming language. Embedded Rust emerged through the community’s adaptation of Rust for microcontroller and bare-metal programming.

Industrial Note

Embedded Rust is increasingly adopted in safety-critical industries such as automotive, aerospace, and industrial IoT for reliable, memory-safe firmware development.

More Embedded-rust Typing Exercises

Blink an LEDControl Servo Motor

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher