Tips for using a Raspberry Pi.
A lot of information on the Raspberry Pi (RPi) can be found at eLinux.org. Below are some basic information I found useful.
In order to get your RPi working, you need a few parts:
- A mini USB power supply,
- An HDMI cable, with a VGA/DVI adapter if you screen does not support HDMI,
- An SD card with a suitable Linux distribution on it, such as Raspbian,
- A keyboard and a mouse,
- A USB hub, if you need to connect more than 2 periphericals (e.g., when you need to connect a USB stick),
- An Ethernet cable, or a Wifi dongle, to enable web access and updates.
When you start your RPi for the first time, you should see the raspi-config tool. Use this tools to configure your time zone, keyboard (by default: qwerty) and locale settings.
You can also activate remote ssh access.
The default login and password are pi
and raspberry
, respectively.
Some basic commands:
startx
: launches the user interfaceifconfig
: displays network connectivity informationshutdown -r now
, orreboot
: rebootslogout
: logoutdate -s "Thu Aug 9 21:31:26 UTC 2012"
: manually sets the date to a specific value (input the UTC time)sudo passwd root
: changes the root passwordsudo -s
: access console as rootdf -h
: get data on available space on disks
Learn more about Linux basics here.
The following is valid for UTBM and with Raspbian, but a similar process should work in other cases. General procedures may also be found here.
- Contact the CRI via GLPI, asking them for an IP for the RPi. You have to provide the MAC address of the RPi, using the
ifconfig
command in the terminal. - Once the IP is obtained, you can check that the RPi is correctly assigned to this address (using
ifconfig
) when it connects on the network. you can also ping other computers on the same network. - You then need to configure the proxy, using the procedure described by VAXXi in this post:
- Go to folder
/etc/apt/apt.conf.d
, - Create a file named
10proxy
, - Add to this file the following command:
Acquire::http::Proxy "http://proxy.utbm.fr:3128";
- You may also check this address by downloading the [http://www.utbm.fr/proxy.pac proxy.pac] file.
- Go to folder
- Once this is done, you should be able to access the web. You can test this using an
apt-get update
command, or by pingingwww.google.com
, for example. If this doesn't work, try rebooting first. Although this should work for terminal commands, you may also need to configure some software manually with the correct proxy.
In some cases, e.g., for some wget
commands, connecting might fail and give you a Connection refused error
. Inputing the following command should solve the problem:
export http_proxy='http://proxy.utbm.fr:3128'
export https_proxy='http://proxy.utbm.fr:3128'
Similarly, for access to git:
git config --global http.proxy http://proxy.utbm.fr:3128
git config --global https.proxy http://proxy.utbm.fr:3128
ntp (automatic date update) does also not work behind the proxy. A workaround can be found here:
sudo date -s "$(wget -S "http://www.google.com/" 2>&1 | grep -E '^[[:space:]][dD]ate:' | sed 's/^[[:space:]][dD]ate:[[:space:]]*//' | head -1l | awk '{print $1, $3, $2, $5 ,"GMT", $4 }' | sed 's/,//')"
At UTBM, the following parameters need to be used to connect to the eduroam wifi network [source]:
- WPA2-Enterprise (EAP)
- Encryption: CCMP
- EAP Method: TTLS
- Identity:
yourID@utbm.fr
- Password: your password
- CA certificate:
/etc/ssl/certs/AddTrust_External_Root.pem
- Inner auth: MSCHAPv2
This can be configured using the dedicated interface on the RPi's desktop. This has been tested with a Wi-Pi USB stick in building B. The package wicd-curses
has been installed on the RPi.
Most 4+ GB SD cards can be used for running Raspbian, the default RPi distribution. This can be easily done using the NOOBS installer, and by following the instructions given in this tutorial.
In some cases, e.g., when the SD card already has a distribution installed, regular formatting tools do not work and do not let you retrieve the entire space available on the card, but only a fraction of it. The solution here is to use Windows' diskpart
tool:
- Launch a command window using Run >
cmd
, - Type
diskpart
, - List your disks using
list disk
, - Select the proper disk using
select disk 1
(or the number corresponding to the disk you want to format; make sure you have the right one!), - Type
clean
, to remove the existing partitions, - Create a new primary partition using
create partition primary
, - Format the card using
format fs=fat32 quick
, - Assign a drive letter using
assign
.
If SDFormatter gives you an error indicating the drive is not supported, use another SD card reader (preferably an external, USB, one).
A first solution is to use SSH:
- Set a root password,
- Activate ssh using the raspi-config tool,
- Download PuTTY, run it and input the IP address of the RPi, with port 22 (default),
- Login,
- You should then be able to run commands in the terminal,
- When you are done, type
exit
orlogout
.
A second solution, that actually gives you an interface like TeamViewer, is to use a VNC:
- Install TighVNC, using
sudo apt-get install tightvncserver
, - Run TightVNC, using
tightvncserver
, and set a password for remote access, - Create a new file using
nano svnc.sh
, and add the following lines:#!/bin/sh vncserver :0 -geometry 1920x1080 -depth 24 -dpi 96
* Set the file to execute, using chmod +x svnc.sh
,
* Run this file, using ./svnc.sh
,
* From your computer, install and run TighVNCViewer, and use you RPi's IP address with port 5900 or 5901 (e.g., 192.168.0.1::5900
). You should be able to see the RPi's desktop.
* Note that this does not auto-start VNC, so you might have to start it via SSH first.
* Check out [this page](http://www.framboise314.fr/prenez-la-main-a-distance-sur-votre-raspberry-pi-avec-vnc/) (in French) for more details.
Changing the default hostname (raspberrypi) of the RPi can be done in 4 steps:
- Run
sudo nano /etc/hosts
, and replace the current name at the line starting with127.0.1.1
(and only this one) with the name you want to use, - Run
sudo nano /etc/hostname
, and replace the current name with the same name you used in the previous step, - Commit the changes using
sudo /etc/init.d/hostname.sh
, - Reboot and check the hostname using the
hostname command
.
The cron
utility enables running instructions or scripts at a given frequency or time, e.g., every miunute or each monday at 7:30am. The basic way to change that is supposed to be through the crontab -e
, but this does not seem to work properly.
I found the following procedure to work better:
- Edit the crontab file with
sudo nano /etc/crontab
, - Add the script or instruction to run, such as, for a Python script run every 10 minutes as root:
*/10 * * * * root python /home/pi/script.py
, - Save and exit.
To make sure cron is running at startup, use: sudo update-rc.d cron enable 2 3 4 5
.
The following describes how to use the GPIO pins with a one-wire temperature sensor, the Dallas DS18B20:
- turn on the RPi and login,
- Load the drivers with the following commands:
sudo modprobe w1-gpio
, andsudo modprobe w1-therm
, - Move to the following folder:
cd /sys/bus/w1/devices/
, and list directories usingls
, - You should see a folder with a name containing mostly numbers, such as
28-000005209981
, move to this folder, - Run this command:
cat w1_slave
, - Two lines should appear; the last part of the second line contains the measured temperature (divide by 1000 to get the actual temperature).
You can also check Adafruit's tutorial on the same topic. As explained on this webpage, the temperature can then be read using Python scripts.
The GPIO drivers are not loaded at boot, by default. This means that you will need to run the modprobe
commands each time. To avoid that, use the following procedure [source]:
- Edit the blacklist file via
sudo nano /etc/modprobe.d/raspi-blacklist.conf
, - Comment the
i2c
andspi
lines, - Save and exit,
- Edit the modules file via
sudo nano /etc/modules
, - Add the following lines:
i2c-dev
,w1-gpio
, andw1-therm
, - Save and exit.
The following instructions are based on this link.
The first step is to install I2C:
- Edit the following file
sudo nano /etc/modules
and addi2c-bcm2708
andi2c-dev
at the end - Reboot
- Install the following packages:
sudo apt-get install python-smbus
,sudo apt-get install i2c-tools
- Edit this file:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
and comment both lines ending withbcm2708
with a#
- Reboot
- Check what addresses are being used:
sudo i2cdetect -y 1
- If an Adafruit LCD Plate is connected, it should show up at
0x20
The second step is to install the screen:
- Install the packages:
sudo apt-get install build-essential python-dev python-smbus python-pip git
- Install the GPIO:
sudo pip install RPi.GPIO
- Clone the git repository:
git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
- Move to the folder:
cd Adafruit_Python_CharLCD
- Install the LCD screen package:
sudo python setup.py install
Finally, test the library:
- Move to the right folder:
cd examples
- Run the example:
sudo python char_lcd_plate.py
The screen should light up, and pushing the buttons should change the color.
The Raspicam package can be used with the camera module.
- Plug-in the camera as instructed here,
- To capture stills with raspistill:
raspistill -o cam.jpg
- To capture videos with raspivid:
raspivid -o video.h264 -t 10000
(10 seconds video) - Create a time-lapse using
cron
Interface with LabView: blog post and code on GitHub.
- Using Java on the RPi: instructions from Oracle and forum.
- Installing Oracle's JAVA 7 JDK:
sudo apt-get install oracle-java7-jdk
- To run JADE: Download and unzip [http://jade.tilab.com/ JADE], check whether it works using:
java -cp lib\jade.jar jade.Boot -gui