Giter VIP home page Giter VIP logo

raspberry-arduinorust's Introduction

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

raspberry-arduinorust's People

Contributors

ichi0915 avatar

Stargazers

Roman avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.