Rust on ESP (esp-rs), toggle GPIO to control LED on ESP32-C6.

With Embedded Rust for ESP32 installed on Linux Mint 21.3 over VirtualBox/Windows 11, this video show steps to run esp-rs on YD-ESP32-C6-N16, toggle GPIO to control LED.



Connect a LED and resistor (for current limit) between 3V3 and GPIO15 of ESP32-C6 board

					YD-ESP32-C6-N16
					|		    |
					|		    |
				+-------| GPIO15	    |
				|	|		    |
				|	|                   |
				|	|               3.3V|---+
				|	+-------------------+	|	
				|			        |
				|				|
				|				|
				+-------|<|-----|/\/\/\|--------+
					LED	Resistor
						(current limit)


Generate project:

Generate a project based on esp-template(no_std):
cargo generate esp-rs/esp-template
- Project Name : rs-c6-blink
- Target MCU : esp32c6
- false : not to configure advanced template options

Edit /src/main.rs:
#![no_std]
#![no_main]

use esp32c6_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, gpio::IO};
use esp_backtrace as _;
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);
    
    //Set GPIO15 as push-pull output, high at start-up
    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
    let mut led = io.pins.gpio15.into_push_pull_output();
    led.set_high().unwrap();

    println!("Hello world!");
    loop {
        println!("Loop...");
        delay.delay_ms(100u32);
        led.toggle().unwrap();
    }
}


Build and Run the project:

Build project:
cargo build
Run project: compile, flash, and open a serial monitor with target device:
cargo run


Comments

Popular posts from this blog

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module