DEV Community

Hasan Yousef
Hasan Yousef

Posted on

Prepare Raspberry Pi and starting with Rust Embeded

I just got my Raspberry Pi 3 (along with sensors kit), and below how I did the setup and got it run:

  1. Download Etcher for copying the iso.
  2. Download Raspbian Stretch Lite (Minimal image based on Debian Stretch), the November 2018 version is only 351MB (the Raspbian Stretch with desktop is 1GB, while the Raspbian Stretch with desktop and recommended software is 1.8GB)
  3. Flash the SD card with Etcher
  4. Connect the Raspberry Pi 3 to:
    • HDMI cable connected toscreen
    • Keyboard
    • Mouse
    • USB cable connected to power source (or computer)
    • Ethernet cable (if you or your device do not have WiFi network)
  5. Insert the flashed SD card into the Raspberry slot.
  6. Power on the device (by connecting the other edge of the USB cable to computer or power source)
  7. Once the device boot up (may take 2 minutes depending on your SD card speed), you'll be prompted to enter your login, default user is: pi, default pswd is rasbperry:
Raspbian GNU/Linux 9 raspberrypi tty1
rasbperrypi login: pi 
Password: raspberry

Then you'll get the device ready to use showing a:

pi@raspberrypi:~$
  1. Do the require changes in the configuration, like user password, WiFi and ssh connection as below:
pi@raspberrypi:~$ sudo raspi-config
- For `changing password` select `1 Change Password`
- For `wifi` select `2 Network Options`, you'll be asked to select country of the WiFi, then entering the SSID (i.e. the wifi name) and the wifi passphrase, BE CAREFULL both network name and password are case-sensetive.
- For `ssh` select `5 Interfacing Options`, scroll down to `P2 SSH`, and confirm `Yes` as an answer to `Would you like the SSH server to be enabled`
- For `Updating the OS` select `8 Update`
- for `Auto login`, i.e avoid being asked everytime for username and password, select `3 Boot Options` then `B1 Desktop / Cli` then `B2 Console Autologin`
- Change the `keyboard layout if required` you can check if the correct one selected or no, by trying printing `#` and `|`
  1. Click finish once done to go back to the command prompt:
pi@raspberrypi:~$
  1. Setup static ip
// check your current ip
pi@raspberrypi:~$ sudo ifconfig
// update your ip in the DHCPCD configeration file as static ip
pi@raspberrypi:~$ sudo nano /etc/dhcpcd.conf
- Scroll down to `define static profile`, and uncommit (i.e. remove the `#`)notice the ip is appearing as `static ip_address=192.168.x.xx`
- Press `Ctrl+X` to exit, confirm `Yes` that you want to save, then press `Enter` to save with the same name
  1. Reboot your device:
pi@raspberrypi:~$ sudo reboot
  1. To check if your device is connected to internet, run the below:
$ sudo ping -c 5 www.google.com
  1. Now you can disconnect the monitor, keyboard and mouse.
  2. In your other device, ssh login to your raspberry pi as:
ssh pi@192.168.x.xx
  1. If you want to map the raspberry files with your system, so you can open the files saved in the raspberry with the apps in your PC, you need to have Fuse and SSHFS from here
    • Create mapped folder in your pc, let's say ssh_pi
$ mkdir ~/ssh_pi
//Map the raspberry pi `home` folder
$ sshfs pi@192.168.x.xx:/home/pi ~/ssh_pi
pi@192.168.1.43's password:

Install your apps, and work the way you like, from keyboard / ssh / FUSE_SSHFS, I was able to install rust

$ curl https://sh.rustup.rs -sSf | sh

Make my first app

$ cargo new my_rust

And open the files at Intellij at my mac.
Now will start playing with Rust Embeded and physical-computing-with-rust-on-raspberry-pi and physical-computing-rust

Note: Compiling at Raspberry itself is slow, so better to compile for raspberry platform in your PC, work at your ssh_pi folder, then it will sync smoothly with the Pi.

In your PC, open the ssh_pi folder at the terminal, and write:

// get the raspberry pi platform target
$ rustup target add armv7-unknown-linux-gnueabihf
// set the raspberry pi platform as default target for this folder (ssh_pi if covring all the folders in the raspberry pi)
$ rustup override set stable-armv7-unknown-linux-gnueabihf
// To confirm you set the atrget correctly
$ rustup show
// To compile for rasberry pi in your pc
$cargo build --target=armv7-unknown-linux-gnueabihf

To shutdown your Pi

$ sudo shutdown

Top comments (0)