Install Ubuntu on Raspberry Pi

Install Ubuntu on Raspberry Pi

TL;DR

This is to install Ubuntu 14.04 on Raspberry Pi, instead of Raspbian. With Ubuntu installed, it is much easier to install ROS from package repositories, or we need to build ROS from sources, which is a lot of work.
Thanks to a ready-to-use Ubuntu image for RPi, it is quite easy to install Ubuntu, and pretty the same as you did for a laptop. You can follow this wiki to install. If possible, please find a 8G or bigger SD card, so you can have swap-file (and be sure to create swap-file.) That helps me a lot while doing some heavy image processing later. Since this RPi is for a rover, there will be no monitor/keyboard connected, so I need WiFi connection, which needs to install firmware package and SSH server. Also, please install VideoCore packages if you need to use camera or OpenCV in the future. I don't need desktop components, so I choose not to install any. 

By following above wiki link, you should have a Ubuntu running immediately. If this RPi have wired connection, you should be able to login to your RPi with SSH client by
ssh -l your-login-name -X your-rpi-host-name
It is good to upgrade your system now by
sudo apt-get dist-upgrade
Then, some extra configuration you may want to add

Wifi

To setup wifi is kind of pain to me, but should be still straight forward. First, plugin your wifi USB dongle. I will use "wlan0" as name of the wireless card as example, and this card will get dynamic IP from DHCP. You can see your wireless card by
ifconfig
You may see lo, wlan0, eth1 in command output. wlan0 (or wlanx) is the name for your wifi dongle. Open the interfaces file
sudo vi /etc/network/interfaces
then add these lines
#wifi
auto wlan0
iface wlan0 inet dhcp
#enable this hotplug will block boot procedure
allow-hotplug wlan0
pre-up  /etc/init.d/wpa.sh start
post-down /etc/init.d/wpa.sh stop
In this file, we define two commands, by calling wpa.sh, to run before this interface goes up (pre-up), and after it is down (post-down.) This wpa.sh script uses wpa supplicant to work, the command to install it is
sudo apt-get install wpasupplicant
Then, you need to define your network by setting SSID, password, encryption mode of your wifi router:
Open the /etc/wpa_supplicant file
sudo vi /etc/wpa_supplicant.conf
Enter or edit your file like
#
#  Please see /usr/share/doc/wpasupplicant/wpa_supplicant.conf.gz
#  for more complete configuration parameters.
#
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
 
eapol_version=2
ap_scan=1
fast_reauth=1
country=US
### Associate with any open access point
###  Scans/ESSID changes can be done with wpa_cli
network={
  ssid=""
  key_mgmt=NONE
  priority=1
}
 
#WPA/WPA2
#First Choice, with higher priority
network={
  ssid="SSID-of-the-first-choice"
  scan_ssid=1
  psk="Password-of-the-first-choice"
  priority=15
  ## The configuration items listed below do not need to be set, the defaults are
  ## pretty 'let us do it for you'.
  ## See /usr/share/doc/wpasupplicant/wpa_supplicant.conf.gz for more information.
  key_mgmt=WPA-PSK
  proto=WPA RSN
  pairwise=CCMP TKIP
  group=CCMP TKIP
}
#Second choice, with lower priority
network={
        ssid="SSID-of-the-second-choice"
        scan_ssid=1
        psk="Password-of-the-second-choice"
        priority=10
        proto=WPA RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP TKIP
        group=CCMP TKIP
}
Then, it is time to create wpa.sh, which is the shell script to start or end WPA supplicant. To create wpa.sh script, uses
sudo vi /etc/init.d/wpa.sh
Then, edit or add these lines
#!/bin/bash
### BEGIN INIT INFO
# Provides:          wpa
# Required-Start:    $network $syslog $local_fs
# Required-Stop:     $network $syslog $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop script for wpa supplicant
# Description:       Custom start/stop script for wpa_supplicant.
### END INIT INFO
 
SELF=`basename $0`
WPA=wpa_supplicant
PROGRAM=/sbin/${WPA}
CONF=/etc/${WPA}.conf
INTERFACE=wlan0
DRIVER=nl80211
#Do not use wext in DRIVER
DAEMONMODE="-B"
LOGFILE=/var/log/$WPA.log
 
function start() {
 
    # TODO: Support multiple interfaces and drivers
    OPTIONS="-c $CONF -i $INTERFACE -D $DRIVER $DAEMONMODE"
 
    ## You can remove this if you are running 8.10 and up.
    # Ubuntu 8.10 and up doesn't need the -w anymore..
    # And the logfile option is not valid on 8.04 and lower
    #local ver=$(lsb_release -sr | sed -e 's/\.//g');
    #[ $ver -lt 810 ] && OPTIONS="$OPTIONS -w" && LOGFILE=""
    ##
 
    # Log to a file
    [ -n "$LOGFILE" ] && OPTIONS="$OPTIONS -f $LOGFILE"
 
    echo " * Starting wpa supplicant"
    eval $PROGRAM $OPTIONS
}
 
function stop() {
    echo " * Stopping wpa supplicant"
    wpa_cli -i $INTERFACE terminate
    #pkill $PROGRAM ## alternative method
}
 
function debug() {
    stop
    DAEMONMODE="-ddd"
    start
}
 
function restart() {
    stop
    start
}
 
function status() {
    pgrep -lf $PROGRAM
}
 
function usage() {
    echo "Usage: $SELF <start|stop|status|debug>"
    return 2
}
case $1 in
    start|stop|debug|restart|status) $1 ;;
    *) usage ;;
esac
Save this file, then make it executable:
sudo chmod +x /etc/init.d/wpa.sh
You can now start WPA supplicant as a server or in debug mode.
To be a service:
/etc/init.d/wpa.sh start
To debug it:
/etc/init.d/wpa.sh debug
You will want to run this WPA supplicant script at boot time, and while system is shutdown by:
sudo update-rc.d wpa.sh defaults
Then, check if it does work by
sudo /etc/init.d/networking restart
or, you can just reboot the system. If something goes wrong, most possible issue could be unable to get IP address, or it could be incorrect driver setting. Please check wpa.sh, and make sure "DRIVER" is given with correct driver. You can use "wext", then check again. Following this link to check which driver your wifi uses. In case it does not get IP address, that is, by using ifconfig command, you can not read inet addr: 192.168.x.x, like
wlan0     Link encap:Ethernet  HWaddr 40:a5:ef:05:7e:df  
          inet addr:192.168.1.12  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::42a5:efff:fe05:7edf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5887 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1617 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:486576 (486.5 KB)  TX bytes:237703 (237.7 KB)
The possible reason is because DHCP client does not work well. You can try to run from terminal:
dhclient wlan0
then ifconfig again, and see if it works. If it does, then you can consider to run it after boot by editing rc.local
sudo vi /etc/rc.local
add this line to the file
dhclient wlan0
RPi has no realtime clock onboard, so it depends on NTP to get time with internet connection, or users have to give it manually. In case you experience a long delay to get date/time after boot, your ntp may experience issue with network. You can add these command in /etc/rc.local by
sudo vi /etc/rc.local
Then, add these lines
( /etc/init.d/ntp stop
until ping -nq -c3 8.8.8.8; do
echo "Waiting for network to run ntp..."
done
ntpdate -s us.pool.ntp.org
/etc/init.d/ntp start)&;
Be sure you add these lines before any "exit" command in the file. Then, reboot the system and check.

Pi Camera

All you need to do is to edit config.txt in your favorite editor (I use vi here),
sudo vi /boot/firmware/config.txt
add one line
start_x=1
Then reboot the system. You can check if camera works well with
sudo raspistill -o ~/test.jpg
which captures a still image and save to test.jpg in your home folder.

Overclock

At the very beginning, I do not plan to overclock my RPi. However, the frame rate after image processing is less than 15 fps, so that forced me to try this. It is easy to do so by editing your config.txt
sudo vi /boot/firmware/config.txt
enter following lines
#performance tweak
sdram_freq=500
core_freq=500
arm_freq=1000
over_voltage=2
temp_limit=80 # will throttle to default color speed if hit
gpu_mem=16
Save, and reboot your system. If gpu_mem is different from your previous settings and you add swap-file, it will take a while to boot the first time because it takes time to re-generate swap-file.
 
Now, you have a Raspberry Pi running Ubuntu, grab some Linux material and get yourself familiar with its commands. 
Last modified on Wednesday, 27 January 2016 19:33

© Copyright 2007- Yi Systems, Inc. All rights reserved.

5009 Asteria St, Torrance, CA, 90503, U.S.A. | +1-310-561-7237 | requestinfo@yisystems.com