Skip to content

ichi0915/Raspberry-ArduinoRust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Arduino Rust

Welcome to the Raspberry Arduino Rust repo, in this repo we are going to explore the basics of Rust and the Arduino platform all from a Raspberry pi 4.

The rasberry pi use in this project is running: Raspberry pi os lite 64-bits (Debian GNU/Linux 11 (bullseye)).

We are going to use the avr-hal library to compile rust to avr.

Prerequisites

Update an upgrade you pi.

sudo apt update && sudo apt upgrade

Install Rust compiler.

#Rust lang
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# When prompted if raspberry pi os is 64 bits use option 1
1

# Else if raspberry pi os is 32 bits select option "2) Custom installation"
2
# When prompted for "Default host triple?" enter ""
arm-unknown-linux-gnueabihf

You can check that Rust is install properly using the following commands:

$ cargo --version
cargo 1.58.0 (f01b232bc 2022-01-19)

$ rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)

Then we need to set the build chain of rust to a specific version that is compatible with the rust-avr runtime:

rustup override set nightly-2021-01-07

If you don't you will get the next error:

error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /home/ichi0915/.cargo/registry/src/github.com-1ecc6299db9ec823/avr-device-0.3.2/src/lib.rs:53:12
   |
53 | #![feature(llvm_asm)]

We also need to install this programs:

sudo apt install avr-libc gcc-avr pkg-config avrdude
  • avr-libc: A C library to use with GCC on Atmel AVR.
  • gcc-avr: The arduino uses an avr chip so we need to have the gcc toolchain that can compile c code for rust down to avr.
  • pkg-config: To help compile libraries.
  • avrdude: Is the programmer we are going to use to flash the elf code to the Arduino.

Repo structure

This repo will contain different programs that will be label from 0 to f64::INFINITY, they might be in increase difficulty but as we progress we are going to explain the new code/functionality in the form of comments example in project 3 we use a new function and comment its usage, so the project 4 will not explain that section of the code because the previous one explained it.

Compiling the projects and flashing to Arduino

To compile simple cd into any project and run:

cargo build

Then to Flash to an Arduino you need to connect the Arduino to the pi and use the following command:

sudo avrdude -p m328p -c arduino -P /dev/ttyACM0 -b 115200 -U flash:w:target/avr-atmega328p/debug/arduino_blink.elf
# -p Is the type of processor we are programming to
# -c Specifies the programmer we are using
# -P Is the port
# -b The baud rate
# -U The operation which is to the flash : a writeable section : and we are going to write the .elf file

Hardware Required:

If you wish to run the projects on your own this are some of the components you may need.

  • Raspberry pi
  • Arduino Uno
  • USB 2.0 cable type A/B (To connect Raspberry to Arduino)
  • Buttons
  • LEDs
  • Resistors
  • Breadboard and jumpers.

Projects

About

A repo where we explore the basics of Rust and the Arduino platform all from a Raspberry pi 4

Topics

Resources

License

Stars

Watchers

Forks

Languages