DEV Community

Ryan Kopf
Ryan Kopf

Posted on

Rust ESP32 Code - Windows Dev - ESP32-WROVER-DEV

First, set everything up.

  • Install VS Code
  • Install Extensions: Rust Analyzer, Even Better TOML

Run some commands:

  • cargo install espup
  • espup install
  • C:/Users/YourUsername/export-esp.ps1

Note: The esp installer may say you don't need to set these environment variables. However this is often WRONG!

Here is code to blink the onboard LED of the ESP32-WROVER-DEV board!

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{clock::ClockControl, IO, peripherals::Peripherals, prelude::*, Delay};
use esp_println::println;

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.SYSTEM.split();

    let clocks = ClockControl::max(system.clock_control).freeze();
    let mut delay = Delay::new(&clocks);

    // let io = peripherals.IO.split();
    // let io = peripherals.GPIO.p
    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
    let mut led = io.pins.gpio2.into_push_pull_output();

    println!("Hello world!");
    loop {
        println!("Loop...");
        delay.delay_ms(500u32);

        led.set_high().unwrap(); // Turn the LED on
        delay.delay_ms(500u32); // Wait for 500 milliseconds

        led.set_low().unwrap(); // Turn the LED off
        delay.delay_ms(500u32); // Wait for 500 milliseconds
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)