/RPI-first-steps

Setup instructions for Raspberry Pi 3: burn jessie-lite on micro sd, connect via ethernet from computer, install EMACS, SuperCollider

Instructions for setting up a Raspberry Pi 3 for work with Emacs and SuperCollider over WiFi.

Introduction

The present instructions show how to set up the system of a Raspberry Pi on a micro-sd and to install Emacs and SuperCollider on it, using an Ethernet cable to connect to a computer and a WiFi network for access to the Internet.

The procedure was first tested on 27 Oct 2016 using from a MacBook Pro 2013 running MacOS 10.12.1, using jessie lite on an RPI 3.

Subsequently it was tested on 3 and 4 November 2017 from a MacPro 2011 running manjaro linux 17.0.6, and on jessie lite on RPI 3 as well as stretch lite on RPI 1 B+.

Requirements

The following items are needed to complete the setup:

  1. A Raspberry Pi (The present instrucions are for Raspberry Pi 3 and Raspberry Pi 1 B+).
  2. A power supply for the Raspberry Pi.
  3. A Micro-sd disc with 8GB capacity.
  4. A computer equipped with an ethernet interface (the present instructions assume that you are working on a mac with MacOS 10.13 High Sierra and / or Manjaro Linux 17.0.6).
  5. For initial connection, an Ethernet cable for connecting the Raspberry Pi to the computer, optionally via a switch.
  6. For later convenience, optionally, a WiFi network for connecting both the computer and the Raspberry Pi to the Internet.

Steps

The present instructions include the following steps:

  1. Download and store a Linux image on a micro sd disc, so as to boot the Raspberry Pi with it.
  2. Connect the Raspberry Pi to the Computer via Ethernet, log onto the Raspberry Pi via ssh, and enable passwordless access using ssh-keygen.
  3. Configure the Pi to access your WiFi network and the internet.
  4. Get and install EMACS.
  5. Get and install SuperCollider.
  6. Configure EMACS to work with SuperCollider.

Load a Linux image on micro sd for the Pi (Jessie-lite)

Obtain Jessie-lite

Get Jessie-lite from here: https://www.raspberrypi.org/downloads/raspbian/

Load the Jessie-lite Image on micro-sd

Here are the instructions for burning it onto your micro-sd:

https://www.raspberrypi.org/documentation/installation/installing-images/mac.md

For me, using a macbook pro with MacOS 10.11.5 (El Capitan), the first part of the above instructions did not work. I had to try the instructions marked “ALTERNATIVE METHOD”, which I quote immediately below this paragraph. Note: I had to use the rdisk naming convention but did not have to erase the SD card’s partition table.

From the terminal run df -h.

Connect the SD card reader with the SD card inside.

Run df -h again and look for the new device that wasn’t listed last time. Record the device name of the filesystem’s partition, for example /dev/disk3s1.

Unmount the partition so that you will be allowed to overwrite the disk:

sudo diskutil unmount /dev/disk3s1
  

Alternatively, open Disk Utility and unmount the partition of the SD card. Do not eject it, or you will have to reconnect it.

Using the device name of the partition, work out the raw device name for the entire disk by omitting the final s1 and replacing disk with rdisk This is very important, as you will lose all data on the hard drive if you provide the wrong device name. Make sure the device name is the name of the whole SD card as described above, not just a partition of it - for example, rdisk3, not rdisk3s1. Similarly, you might have another SD drive name/number like rdisk2 or rdisk4; you can check again by using the df -h command both before and after you insert your SD card reader into your Mac. For example, /dev/disk3s1 becomes /dev/rdisk3. In the terminal, write the image to the card with this command, using the raw device name from above. Read the above step carefully to be sure you use the correct rdisk number here:

sudo dd bs=1m if=2016-05-27-raspbian-jessie.img of=/dev/rdisk3
  

If the above command reports the error dd: bs: illegal numeric value, please change the block size bs=1m to bs=1M.

If the above command reports the error dd: /dev/rdisk3: Permission denied, it means the partition table of the SD card is being protected against being overwritten by Mac OS. Erase the SD card’s partition table using this command:

sudo diskutil partitionDisk /dev/disk3 1 MBR "Free Space" "%noformat%" 100%
  

That command will also set the permissions on the device to allow writing. Now try the dd command again.

Note that dd will not provide any on-screen information until there is an error or it is finished; when complete, information will be shown and the disk will re-mount. If you wish to view the progress, you can use Ctrl-T; this generates SIGINFO, the status argument of your terminal, and will display information on the process.

After the dd command finishes, eject the card:

sudo diskutil eject /dev/rdisk3
  

Alternatively, open Disk Utility and use this to eject the SD card.

Connect to your rpi via ssh over ethernet

  • Connect the RPI via ethernet to the router at your workplace
  • Connect the computer from which you want to access the RPI via ethernet to the same router where the RPI is connected.
  • Follow the instructions in https://www.raspberrypi.org/documentation/remote-access/ip-address.md to find the IP of your raspberry pi. Note: under the current version of raspbian jessie-lite as of 27 Oct 2016, the hostname of raspberry pi is not printed in the output of the command =nmap -sn <ip range>=. Therefore, the only way to identify the ip is to try logging in with each of the numbers printed out by nmap. I suggest trying this out in reverse order, starting with the last number printed out.. For example, to try out an ip, type: ssh pi@192.168.16.107. The password to try at the prompt is raspberry.

If you are working on MacOS, you can download nmap from its official website at: https://nmap.org/book/inst-macosx.html.

What to do if you get a message “POSSIBLE DNS SPOOFING DETECTED!”

In many cases you may not be able to connect to your pi the first time. Instead, you get a message:

WARNING: POSSIBLE DNS SPOOFING DETECTED! :

The whole message is:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for raspberrypi.local has changed,
and the key for the corresponding IP address fe80::bbec:ad14:de8d:5f49%bridge100
has a different value. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /Users/iani/.ssh/known_hosts:46

This is due to a security mechanism on the mac and will be renewed each time that your computer gets a new ip. To overcome this obstacle, edit the file Users/iani.ssh/known_hosts on your computer, and remove the line that contains the Offending key. In the above case, this is line 46. You can also search for the line by searching for the name of the raspberry pi host: raspberrypi.local. After removing the line, you should be able to ssh on your pi.

In the following subsection we show how to make it possible to log in via ssh to the raspberry pi, without having to type in the password every time.

Enable access to your pi via ssh (and to github) using ssh-keygen

Instructions for doing this are described here: https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md

The following comments may be useful for understanding the mechanism:

ssh-keygen creates two files:

  1. ~/.ssh/id_rsa : Local encrypted key
  2. ~/.ssh/id_rsa.pub : Public key shared with other computers.

You use the key contained in the second file, ~/.ssh/id_rsa.pub, in order to enable access to other computers or systems. For every system that you want to access from your local computer, you need to add the contents of id_rsa.pub at an appropriate place. For example, to ssh to a remote unix computer, the contents of id_rsa.pub from your local computer must be appended to the contents of the file ~/.ssh/authorized_keys on the remote computer that you want to access. Basic applications:

To be able to ssh to your pi from your computer, you must create a public key on your computer (the one that is used for github), and then add the id_rsa.pub key from your own computer to the file ~/.ssh/authorized_keys on the raspberry pi. If you do not already have one, create a new key on your local computer. For instructions see https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/. After creating a key on your computer, copy it to your pi by doing:

cat ~/.ssh/id_rsa.pub | ssh pi@raspberrypi.local 'cat >> .ssh/authorized_keys'

If you get a response:

bash: .ssh/authorized_keys: No such file or directory

This means that your pi does not yet have an .ssh directory. You should create this on your ssh shell on the pi with:

mkdir ~/.ssh

To gain full access to your github account’s repositories, add the contents of id_rsa.pub as a new key in the section for keys in your github account. If you are logged into github on your browser, you can access this section here: https://github.com/settings/keys. To add a key on your pi do:

ssh-keygen -t rsa -C "your@email.address"

Configure your rpi to access your Wifi network

Background

The contents of file /etc/network/interfaces define the internet configuration of the Pi. Furthermore, this interfaces file may also load a different file to configure WiFi access, usually this one:

/etc/wpa_supplicant/wpa_supplicant.conf

More information is given in the following links, however you can skip this and go directly to the Instructions.

The mechanism that gives the raspberrypi.local DNS name to your RPI is explained here:

http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/

To understand the text in /etc/network/interfaces see the documentation in:

https://help.ubuntu.com/lts/serverguide/network-configuration.html

Instructions

  • 1. Edit the /etc/network/interfaces file to enable WiFi configuration through wpa_supplicant.conf.

Edit using nano with this command:

nano /etc/network/interfaces

Here are the contents of my current /etc/network/interfaces file, which permit me to access the pi over WiFi:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

The relevant sections are those which are headed with a line containing wlan. wlan refers to WiFi lan. The next line after iface wlan0 instructs the Pi to load a file which configures WiFi access:

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Wpa supplicant is an open source program which enables WiFi access using WPA, that is, WiFi Protected Access.

After editing the interfaces file to make wlan0 and wlan1 look as in the example above, type Control-O to write the contents of the file and Control-X to exit nano.

  • 2. Edit the file /etc/wpa_supplicant/wpa_supplicant.conf to add the name of the WiFi and password of the network.

You can find the name and password of the network from your KeyChain application on a Mac, or from a corresponding utility on Linux or Window.

Edit the wpa_supplicant.conf file using sudo, because it is writeable only by root:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Here are the full contents of the file in my current working configuration:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="{WIFI_NAME}"
    psk="{PASSWORD}"
}

You should substitute {WIFI_NAME} with the name of your wifi network and {PASSWORD} with the password for that network.

After writing the file, you may reboot the wifi with:

sudo reboot

If the configuration was correct, then after the reboot is complete, you should be able to login to your pi over WiFi (without Ethernet cable), over the terminal, through the command:

sudo ssh pi@raspberrypi.local

The password for user pi is raspberry.

Check that you can access the internet via WiFi

If you have successfully logged into the Pi, then you can test if you can access the internet via WiFi, by pinging a common address. For example:

ping google.com

will periodically ping and post the results line this:

ping google.com
PING google.com (172.217.20.78) 56(84) bytes of data.
64 bytes from fra02s27-in-f14.1e100.net (172.217.20.78): icmp_seq=1 ttl=55 time=60.4 ms
64 bytes from fra02s27-in-f14.1e100.net (172.217.20.78): icmp_seq=2 ttl=55 time=55.8 ms
64 bytes from fra02s27-in-f14.1e100.net (172.217.20.78): icmp_seq=3 ttl=55 time=53.9 ms

Stop the ping by typing Control-C.

Before doing anything else: update+upgrade apt-get

As soon as your Pi is connected to the Internet, run the following two commands to update and upgrade your apt-get packet manager:

sudo apt-get update

sudo apt-get upgrade

Run first the first command, let it finish, and then run the second command.

Finding your pi on a WiFi lan, if it is not accessible as raspberrypi.local

If you have added WiFi access on your pi, but still cannot find it with ssh pi@raspberrypi.local, then you can find its address by scanning the lan with the nmap command.

First, find the ip of your computer. You can do this by running

ipconfig getifaddr en0

Or if that gives no answer:

ipconfig getifaddr en1

Or else look it up on Network preferences.

Then scan your lan for the range of possible IPs deduced from your IP. For example, if your ip is 192.168.1.6, then scan for:

nmap -sP 192.168.1.1-255

Here is an example of the output of nmap:

Starting Nmap 6.47 ( http://nmap.org ) at 2016-06-07 13:53 EEST
Nmap scan report for speedport-entry-2i.ote.gr (192.168.1.1)
Host is up (0.010s latency).
Nmap scan report for android-157524dbd8c37c49 (192.168.1.3)
Host is up (0.010s latency).
Nmap scan report for turangalila2 (192.168.1.6)
Host is up (0.00042s latency).
Nmap scan report for raspberrypi (192.168.1.8)
Host is up (0.0088s latency).
Nmap done: 255 IP addresses (4 hosts up) scanned in 12.36 seconds

The above says that the ip for raspberrypi is 192.168.1.8. So one may alternatively ssh on it like this:

ssh pi@192.168.1.8

Create a standalone wifi server on RPI sharing internet access over ethernet

This rather long procedure is an optional step. It is needed if you want the RPI to act as web server for devices connected over wifi. For example, when you want to control supercollider or anything else running on RPI via OSC, by using a GUI that appears on a webpage, and which is shared from the RPI via WiFi.

https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software

These instructions are also included in the present repository as PDF file under the name: setting-up-a-raspberry-pi-as-a-wifi-access-point.pdf

Install EMACS

Before you start, run this to make sure that your apt-get package manager is up to date:

sudo apt-get update && sudo apt-get upgrade

After that follow the instructions here:

http://ubuntuhandbook.org/index.php/2014/10/emacs-24-4-released-install-in-ubuntu-14-04/

Step by step details:

This first command should run “as-is” (no preparation needed):

sudo apt-get install build-essential

The next command needs some configuration:

sudo apt-get build-dep emacs24

This will fail, and post this error:

E: You must put some 'source' URIs in your sources.list

To fix this, edit the file sources.list and uncomment the last line:

Run

sudo nano /etc/apt/sources.list

The original contents of the file before editing are:

deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

You need to uncomment the last line, which means to remove the # sign at the beginning of the line. The last line becomes:

deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

Save, and then run the command

sudo apt-get update

again. This is to update the list of dependencies/packages that need to be installed, before running the next command build-dep, to build the libraries.

After that run this command to build all libraries that emacs24 needs in order to compile.

sudo apt-get build-dep emacs24

Now get the source for emacs24 from the web. Visit this site: http://ftp.gnu.org/gnu/emacs/

It will show an index containing all current sources of emacs. Find the one that you want. As of this writing, the most recent is: emacs-24.5.tar.xz. Right-click on the name of this file to get a menu and select “Copy Link Address”. The address copied should be: “http://ftp.gnu.org/gnu/emacs/emacs-24.5.tar.gz”. You will use this address with wget to download the file directly on your PI from the shell with wget. Use the command:

wget http://ftp.gnu.org/gnu/emacs/emacs-24.5.tar.gz

This will download the file emacs-24.5.tar.xz on your Pi. Now unzip and unarchive the file in two steps:

  • 1. unzip (“Gunzip”).
gunzip emacs-24.5.tar.gz
  • 2. Unarchive (extract from tar archive:)
tar -xvf emacs-24.5.tar

The v tells tar to print out what it is unarchiving, so that you can follow the progress of the unpacking.

Next you can proceed with the rest of the instructions in http://ubuntuhandbook.org/index.php/2014/10/emacs-24-4-released-install-in-ubuntu-14-04/, namely:

cd emacs-24.5
./configure
make
sudo make install

After this is done, you can run the emacs command to start emacs from the terminal:

emacs

Install SuperCollider

The installation instructions here are according to this site: http://supercollider.github.io/development/building-raspberrypi.html

Step 1: Preliminaries: Connect, update package system

First, be sure that you have enabled login to your Pi using the steps above, and also that you have access to the internet, and have performed apt-get update and apt-get upgrade. After that, go through the following steps:

Step 2: Install basic libraries for audio

sudo apt-get install alsa-base libicu-dev libasound2-dev libsamplerate0-dev libsndfile1-dev libreadline-dev libxt-dev libudev-dev libavahi-client-dev libfftw3-dev cmake git gcc-4.8 g++-4.8

Step 3: Get and install jack audio drivers

 git clone git://github.com/jackaudio/jack2 --depth 1
cd jack2
./waf configure --alsa #note: here we use the default gcc-4.9
./waf build
sudo ./waf install
sudo ldconfig
cd ..
rm -rf jack2
sudo nano /etc/security/limits.conf #and add the following two lines at the end
@audio - memlock 256000
@audio - rtprio 75
exit #and log in again to make the limits.conf settings work

Step 5 (compile & install sc master)

git clone --recursive git://github.com/supercollider/supercollider #optionally add –depth 1 here if you only need master
cd supercollider
git submodule init && git submodule update
mkdir build && cd build
export CC=/usr/bin/gcc-4.8 #here temporarily use the older gcc-4.8
export CXX=/usr/bin/g++-4.8
cmake -L -DCMAKE_BUILD_TYPE="Release" -DBUILD_TESTING=OFF -DSSE=OFF -DSSE2=OFF -DSUPERNOVA=OFF -DNOVA_SIMD=ON -DNATIVE=OFF -DSC_ED=OFF -DSC_WII=OFF -DSC_IDE=OFF -DSC_QT=OFF -DSC_EL=OFF -DSC_VIM=OFF -DCMAKE_C_FLAGS="-mfloat-abi=hard -mfpu=neon" -DCMAKE_CXX_FLAGS="-mfloat-abi=hard -mfpu=neon" ..
make -j 4 #leave out flag j4 on single core rpi models
sudo make install
sudo ldconfig
cd ../..
rm -rf supercollider
sudo mv /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI /usr/local/share/SuperCollider/SCClassLibrary/scide_scqt/GUI
sudo mv /usr/local/share/SuperCollider/SCClassLibrary/JITLib/GUI /usr/local/share/SuperCollider/SCClassLibrary/scide_scqt/JITLibGUI

Step 6 (start jack & sclang & test)

jackd -P75 -dalsa -dhw:0 -p1024 -n3 -s -r44100 & #edit -dhw:1 to match your soundcard.

Edit -dhw:1 to match your soundcard. Usually it is 1 for usb and 0 for built-in audio.

sclang #should start sc and compile the class library with only 3 harmless class overwrites warnings
s.boot #should boot the server
a= {SinOsc.ar([400, 404])}.play #should play sound in both channels
a.free
{1000000.do{2.5.sqrt}}.bench #benchmark: ~0.58 for rpi3, ~0.89 for rpi2, ~3.1 for rpi1
a= {Mix(50.collect{RLPF.ar(SinOsc.ar)});DC.ar(0)}.play #benchmark
s.avgCPU #should show ~12% for rpi3, ~19% for rpi2 and ~73% for rpi1
a.free
0.exit #quit sclang
pkill jackd #quit jackd

Step 7: Configure EMACS for work with SuperCollider

For this you need 2 libraries and one configuration file:

  1. “scemacs” library on SuperCollider, for connecting to EMACS
  2. “sclang” library on EMACS, for connecting to SuperCollider
  3. initialize.el file for configuring SuperCollider on EMACS

Get these from the following github repository: https://github.com/iani/pimacsc.

Installation instructions are on the README file of the above repository and appear on its home page: https://github.com/iani/pimacsc#installation

NOTE: Configure jack startup on linux

scsynth needs jack2 for sound i/o. Depending on the audio hardware characteristics of the computer where you are running scsynth, you may need to start jackd with different options. Here we give a solution which works with Raspberry Pi when using a usb audio card as audio interface instead of the built-in audio interface. This solution may also be useful for users that run supercollider on different computers using linux. In that case you have to figure out the jackd options for your particular computer and specify this by editing the script below. (This information is also found on http://swiki.hfbk-hamburg.de/MusicTechnology/634).

The script should be saved in a file named .jackdrc and placed in the root directory of your home folder. To find your home folder use this command:

echo $HOME

To go to your home folder type this command:

cd

Alternatively use the ~ as identifier for your home directory. For example:

cd ~/

The contents for ~/.jackdrc on raspberry pi using usb audio card are:

/usr/local/bin/jackd -R -dalsa  hw:1 -r 44100 -n3

Other stuff

Changing the hostname of your Pi

This is useful if you are working with several Pis on the same WiFi lan and want to access each Pi from a different name.

See http://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/

The hostname is configured in two files:

  1. this file:
/etc/hosts

and 2. this file:

/etc/hostname

Additionally, there is a script file which takes the information from the above 2 files and configures the system in order to register the new host name. The script file is:

/etc/init.d/hostname.sh

Therefore, to change the hostname of your Pi, do 3 things:

  1. edit the two files /etc/hosts and /etc/hostname,
  2. the hostaname.sh script with sudo /etc/init.d/hostname.sh
  3. finally reboot the raspberry pi with sudo reboot

Here is how to edit /etc/hosts/

Leave all of the entries alone except for the very last entry labeled 127.0.1.1 with the hostname “raspberrypi“. This is the only line you want to edit. Replace “raspberrypi” with whatever hostname you desire. We replaced it on our device with “weatherstation“. Press CTRL+X to close the editor; agree to overwrite the existing file and save it.

/etc/hostname/ contains the current hostname on a single line, only. Replace the current hostname with the new hostname.

Configuring Static IP address over WiFi

Following links concern setting up your raspberry pi to have a static IP address. You do not need this to connect to your Pi wirelessly if you have successfully completed the steps above. But it can be useful if you are programming a network of Pi’s and want to communicate with them over their IP numbers rather than their domain names.

I have not yet tried to do this.

https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

Maybe a more useful page is this one:

https://www.raspberrypi.org/forums/viewtopic.php?&t=42670

And even better this one:

https://www.raspberrypi.org/forums/viewtopic.php?f=26&t=22660t