DEV Community

Cover image for Getting Started With Embedded Development Using Rust and Arduino
Rajesh
Rajesh

Posted on

Getting Started With Embedded Development Using Rust and Arduino

Using rust for embedded development is much more easier than setting up a C/C++ environment now. You will be able to program and flash your firmware to an Arduino in just a few minutes.

First setting up an environment may take a little while and then it is as swift as cloning a repository. Let's jump to the initial environment setup.

  • Run this to install AVR compiler and library header files
sudo apt install avr-libc gcc-avr pkg-config avrdude
Enter fullscreen mode Exit fullscreen mode
  • We need cargo-generate to get project template from git
cargo install cargo-generate
Enter fullscreen mode Exit fullscreen mode
  • Also to run the program once you compiled it you can use the ravedude cargo package
cargo install ravedude
Enter fullscreen mode Exit fullscreen mode

That's all. The configuration part is over.

Now whenever you want to start a new project you can just run

cargo generate --git https://github.com/Rahix/avr-hal-template.git 
Enter fullscreen mode Exit fullscreen mode

You will be prompted to enter a name for your project, and the board that you have.(Arduino Uno, Mega etc.,)

cargo run 
Enter fullscreen mode Exit fullscreen mode

will build and flash the program to your embedded system but before running it you need to tell the ravedude which of your serial port is connected to arduino.

export RAVEDUDE_PORT=/dev/ttyUSB0
Enter fullscreen mode Exit fullscreen mode

Replace ttyUSB0 with the name of the port your arduino is connected to.

Once the default project from the template is flashed you will be greeted with the blinking led in your arduino. You can edit the src/main.rs file to control the Universe... Nope! Just your Arduino.😄
That's how easy it is to start programming embedded systems in Rust.

P.S: I am new to blogging so if you find anything odd in this blog let me know.

Image Credit: https://commons.wikimedia.org/wiki/File:Arduino_Leonardo_PCB.jpg

Discussion (0)