How to set up a Raspberry Pi 3 over the Command Line

The purpose of this post is to document my instructions for when I get a new RPi, and covers the Raspberry Pi 3.

Head over to the Raspberry Pi Raspbian download page. You can chose between Raspbian Jessie, or Raspbian Jessie Lite. The Lite version is "headless", meaning it doesn't have the UI installed. I don't need a UI so I downloaded the Lite. Next, install the operating system onto a SD card.

Now you need to a way to SSH into the Raspberry Pi 3. The easiest way to do this is to plug an Ethernet cable into your Raspberry Pi 3 from your home router, and logging into your routers UI to find the IP address. If you cannot log into the router's UI, for example if you are at work, then you can to SSH into your Pi by directly connecting it to your laptop by an Ethernet cable and running a DHCP server.

sudo raspi-config

Once you are in, issue sudo raspi-config to change the configuration.

With "Expand File system highlighted, hit enter. It should respond with "Root partition has been resized".

Then go to Change User Password and make a secure password.

Go to Internationalisation Options and then Change Timezone. I selected America then Los Angeles.

If required, go to Advanced Options and then Hostname to change it.

Then go to Finish.

It will ask you if you want to reboot now, but I wanted to reboot after configuring my Wifi settings.

Configure Wifi

If you are on Raspberry Pi 1 or 2, use this post instead.

Raspberry Pi 3 is supposed to have much better default Wifi settings. All I needed to do was add my router's settings to wpa_supplication.conf and it started working immediately; I did not have to mess around with the interfaces file like on RPI 1/2.

Open up the wpa supplication file via:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Then add your network. For me, I use settings like the follow. Append this to the wpa_supplicant file.

network={  
   ssid="YourSSD"  
   psk="YourPassword"  
   proto=RSN  
   key_mgmt=WPA-PSK  
   pairwise=CCMP  
   auth_alg=OPEN  
}

Update: My WiFi worked fine for 1 week, but then it suddenly stopped working. I had forgotten to run sudo apt-get upgrade and and sudo apt-get dist-upgrade. I am configuring my next Pi now and hope this will solve the issue.

I like to change my hostname, so I needed to reboot now with

sudo reboot

Basic apt-get downloads

The Raspberry Pi 3 will need some applications downloaded via apt-get. Issue the following (NB, copy and paste these commands one at a time; for some reason it doesn't work if you copy and paste them all):

sudo apt-get update  
sudo apt-get upgrade  
<code>sudo apt-get dist-upgrade</code> -y  
sudo apt-get install vim -y  
sudo apt-get install git -y  
sudo apt-get install python-pip -y  
sudo apt-get install python-dev -y  
sudo apt-get install python-rpi.gpio -y  
sudo apt-get install python-mysqldb -y  
sudo apt-get install screen -y

Raspberry Pi 3 comes shipped with vim-tiny. With vim-tiny, if you use the arrow keys while in insert mode it ruins everything. I prefer the full vim program that doesn't have this issue. We downloaded vim in the previous command.

The python modules are useful if you are using python.

Screen is great for running applications when you are not connected. I use it to run my brewing app.

At this point you are ready to go and your Raspberry PI 3 is set up.

The following is for when I have to install my brewing application related stuff and isn't necessary for you to read.

Enable the temperature sensor settings for DS18B20 probes:

Open up the rc.local file, which lets you add commands that will be executed after boot:

sudo vi /etc/rc.local

Add the following lines BEFORE exit 0:

sudo modprobe w1-gpio  
sudo modprobe w1-therm

Edit /boot/config.txt

sudo vi /boot/config.txt

Add the following line:

dtoverlay=w1-gpio

Download and Configure the Brew app for Raspberry Pi 3

cd ~  
mkdir brew  
cd brew  
git init  
git remote add origin https://github.com/mkmoisen/brew.git  
git pull origin master

Create a local_settings.py file with the database settings:

vi local_settings.py

Add the following to local_settings.py:

MYSQL_USERNAME='username' MYSQL_DATABASE='database' MYSQL_PASSWORD='password'

MYSQL_HOST='host'

MYSQL_USERNAME='username'  
MYSQL_DATABASE='database'  
MYSQL_PASSWORD='password  
MYSQL_HOST='host'

Python modules via pip:

sudo pip install bottle  
sudo pip install peewee

When I attached the DS18B20 temperature probes, I noticed in /sys/bus/w1/devices there was a 00-200000000000 directory that was concerning - this never happened on the RPi1/2. However after about a minute it disappeared.

To make sure the brewing script kicks off in a screen after the pi restarts, for example due to a power outage, add the following to /etc/rc.local:

runuser -l pi -c "screen -dmS brew bash -c 'cd ~/brew && sudo python start_fermentation.py'"

runuser lets you run a command as another user. This is important because /etc/rc.local is run as root. We want the screen to be associated with user pi instead of root.

screen -dmS <screenName> <command> tells screen to start a "detached" session with a particular name and to run a command. If the command runs in a while loop then screen won't exit. We are startng the screen with the session name brew. I'm not sure if bash -c is required here; I don't think it is but most people tend to follow this pattern.


Comments

Add Comment

Name

Email

Comment

Are you human? + two = 11