The Raspberry Pi is the swiss army knife of small computers and is perfect for learning to code. Let’s combine them and install Rust on Raspberry Pi.
Setting up your Raspberry Pi
For this project you will need:
- Raspberry Pi.
- LIGHT-EMITTING DIODE.
- Resistor 220-1k Ohm.
- Breadboard and connecting wires.
Set up your circuit with GPIO 18 connected to the positive leg of the LEDs and the negative leg of the LEDs to the resistor and back to the GND pin on the Pi.
This tutorial was made using a Raspberry Pi 3B+ with Raspbian Stretch in desktop mode. It also works fine over a remote SSH connection, although different Pi models and different operating systems may have different results.
How to install Rust on Raspberry Pi
To install rust, go to the rust-lang installation page and copy the installation command into your terminal. When prompted, select the default installation.
The installer will notify you of completion, although the installation may take some time depending on your connection.
The installation was successful, but you can’t start using it yet. If you try to check Rust and Cargo by version, you will get an error. Usually, you must add the language to your PATH variable in order to use it on the command line.
Luckily, Rust will do this for you, and all you have to do is reboot your Pi or log out and log back in. Now checking for Rust and Cargo should work.
You will be compiling and building all your scripts from the terminal, but you will also need a code editor. For this project, I’ll be using Code-OSS, a community build of Code VS that you can install on the Pi, but it doesn’t have to. Any code editor will do.
Creating a Rust Project
To create a Rust project, create a new directory and enter it by typing
mkdir YourFolder cd YourFolder
Use Cargo to create a new Rust project.
cargo new YourProject
You will receive confirmation that a new project has been created.
Enter the new project folder and list its contents.
cd YourProject ls
You will see a folder named src and a file named Cargo.toml . These two elements form the core of every Rust project.