DEV Community

Ryan Kopf
Ryan Kopf

Posted on

2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay