Skip to content

My sandbox to play with kgrech original project to test out my ideas.

License

Notifications You must be signed in to change notification settings

arildlangseid/rust_arduino

 
 

Repository files navigation

Example of an Arduino library usage in a Rust project

The project tested with Arduino UNO on Ubuntu 24.04.1 LTS.
It demonstrates the usage of LiquidCrystal_I2C with rust project to control I2C Text Display from Rust. It also shows how to combine it with existing Arduino rust crates. arduino_hal crate is used to blink the LED.

This is the source code for Five simple steps to use any Arduino C++ library in a Rust project 🦀. Demo video.

Project setup

  • Install curl to install rust by rustup and other prerequisites
sudo apt install curl git libudev-dev libclang-dev
  • Install avr toolchain and avrdude
sudo apt install gcc avrdude gcc-avr avr-libc
  • Install dependencies to compile ravedude
sudo apt install systemd-dev pkg-config
  • Install bindgen dependencies:
sudo apt install libudev-dev libclang-dev
  • Install Rust (& Cargo)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Install ravedude:
cargo install ravedude
  • Install arduino IDE and validate it is working by compiling a simple sketch.
  • Install LiquidCrystal_I2C library to Arduino Libraries folder (manually or using Arduino IDE like you would normally do)
  • Edit arduino.yaml to configure your arduino installation and version of core library
  • Ensure to have rustfmt installed
rustup component add rustfmt
  • Plug in your Arduino UNO and run the project:
cargo run

If you see the following error

> avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied

then try editing the permission or adding you user to dialout group (require re-login):

sudo chmod a+rw /dev/ttyACM0
sudo usermod -aG dialout $USER

Windows

If you are running on Windows, consider different way of system dependencies installation.

  • Instead of install avr tools using dnf, locate them in your Arduino IDE installation and add the folders containing avr-gcc and avrdude to the PATH. I had to add the following:
    • %LOCALAPPDATA%\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\
    • %LOCALAPPDATA%\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\
  • Ensure avr-gcc and avrdude are found.
  • Download and install clang for Windows here
  • Setup LIBCLANG_PATH to point to <CLANG_INSTALL_DIR>\bin
  • Setup AR to point to %LIBCLANG_PATH%\llvm-ar.exe
  • Don't forget to update arduino.yaml with correct paths.
  • cargo build and cargo run should work now!

About

My sandbox to play with kgrech original project to test out my ideas.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%