Skip to content

Thymio II RaspberryPi Configuration

Tiago Rodrigues edited this page Apr 1, 2015 · 3 revisions

#Thymio II Raspberry Configuration Instructions

This wiki page aggregrates the configurations need to be made on a standard Raspbian OS image, in order to get the raspberry operative system usable on our project (considering the use of a Raspberry B 512Mb or Raspberry 2).


##Initial Configurations

1 - Launch raspberry configuration tool using sudo raspi-config (in case it is the first boot of the OS, the configuration tool will be shown automatically) and make the following configurations:

  • Expand filesystem
  • Internationalization Options
  • Locale en_US.UTF-8 UTF-8
  • Time zone: Europe > Lisbon
  • Keyboard Layout: choose Generic 105-keys (intl) PC>Other>Portuguese>Portuguese (or change GB to PT in /etc/default/keyboard file, using vi, nano, vim or any other kind of editor - do not forget sudo!)
  • Overclock set to High (950MHz ARM option) or Pi2 on Raspberry 2
  • Advanced Options
  • Set the desired hostname (biomachinesthymio in our case)
  • Enable SSH server
  • Disable the login shell accessibility over serial (by other words, select option "No" on the serial menu)

2 - Reboot Raspberry Pi (sudo reboot). If any error appears related to a non-set LOCALE, LANGUAGE or LC_ALL, add the following to /etc/default/locale (using nano,vi or other editor):

LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8

3 - Delete unnecessary files:

cd ~ && rm -rf python_games

4 - Install needed applications:

sudo apt-get update && sudo apt-get install -y screen isc-dhcp-server deborphan sysv-rc-conf i2c-tools hostapd

5 - Update System

sudo apt-get -y dist-upgrade && sudo apt-get -y autoremove && sudo apt-get -y autoclean

6 - You can also limit the log's quantity and size by making some slightly modifications to /etc/logrotate.conf file, so the first lines become something like:

# see "man logrotate" for details
# rotate log files weekly
daily

# keep 4 weeks worth of backlogs
rotate 7

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}

# system-specific logs may be configured here

7 - You can also change the /etc/rsyslog.conf in order to produce less quantity of logs (probabily is better to make a backup of the original file using sudo cp /etc/rsyslog.conf /etc/rsyslog.conf.backup). The final content can be something like:

#  /etc/rsyslog.conf	Configuration file for rsyslog.
#
#			For more information see
#			/usr/share/doc/rsyslog-doc/html/rsyslog_conf.html


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog   # provides kernel logging support
#$ModLoad immark  # provides --MARK-- message capability

# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514


###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf


###############
#### RULES ####
###############

#
# First some standard log files.  Log by facility.
#
*.*;auth,authpriv.none		-/var/log/syslog
daemon.*			-/var/log/daemon.log
kern.*				-/var/log/kern.log

#
# Some "catch-all" log files.
#
*.=debug;\
	auth,authpriv.none;\
	news.none;mail.none	-/var/log/debug
#*.=info;*.=notice;*.=warn;\
#	auth,authpriv.none;\
#	cron,daemon.none;\
#	mail,news.none		-/var/log/messages

#
# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,
# you must invoke `xconsole' with the `-file' option:
# 
#    $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
#      busy site..
#
daemon.*;mail.*;\
	news.err;\
	*.=debug;*.=info;\
	*.=notice;*.=warn	|/dev/xconsole

8 - The file /etc/logrotate.d/rsyslog can also suffer some changes, ending up like shown bellow (probabily is better to make a backup of the original file using sudo cp /etc/logrotate.d/rsyslog /etc/logrotate.d/rsyslog.backup) :

/var/log/syslog
{
	rotate 7
	daily
	missingok
	notifempty
	delaycompress
	compress
	postrotate
		invoke-rc.d rsyslog rotate > /dev/null
	endscript
}

/var/log/daemon.log
/var/log/kern.log
/var/log/debug
/var/log/isc-dhcpd-server.log
/var/log/messages
{
	rotate 4
	weekly
	missingok
	notifempty
	compress
	delaycompress
	sharedscripts
	postrotate
		invoke-rc.d rsyslog rotate > /dev/null
	endscript
}

9 - In order to decrease log growth and increase boot velocity, change the system loglevel to 4 (KERN_WARNING) by addind loglevel=4 on /boot/cmdline.txt, after rootfstype=ext4.

Reference


SSH Server Configurations

1 - On file /etc/ssh/sshd_config make the following changes (using an editor like nano or vim. Do not forget to edit as super user - using sudo):

  • Uncomment line regarding the use of public keys (AuthorizedKeysFile %h/.ssh/authorized_keys)
  • Uncomment line regarding GSSAPI Authentication (GSSAPIAuthentication no) in order to remove lag from ssh login
  • Add UseDNS no on the end of the file

2 - Create the authorized_keys file (using mkdir ~/.ssh/ && touch ~/.ssh/authorized_keys) and put your SSH public key in the file.

Reference


Network Configurations

Basic Network Configurations

1 - Disable IPv6 (Run sudo -i command first or you won't be able to run the following commands successfully. Run exit command at the end):

echo "blacklist ipv6" >> /etc/modprobe.d/raspi-blacklist.conf
sed -i "/::/s%^%#%g" /etc/hosts

You can test if IPv6 is enabled by runing netstat -tunlp |grep p6 |wc -l command after reboot. If the output is other than 0, then IPv6 is enable.

2 - Configure network interfaces by putting the following content in /etc/network/interfaces file (replacing the existent content):

auto lo

iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
        address 10.40.50.243
        netmask 255.255.255.0
        gateway 10.40.50.1

allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.3.1
        netmask 255.255.255.0

iface default inet dhcp

3 - Replace the content of /etc/hosts with the following:

127.0.0.1       localhost

10.40.50.243    biomachinesthymio
192.168.3.1     biomachinesthymio

4 - Add the following server name's IP to /etc/resolv.conf file (the last three entries are ISCTE-IUL DNS servers that we use on eth0 connection, so external user do not need to add them):

domain biomachineswlan
search biomachineswlan
nameserver 192.168.3.1
nameserver 10.10.20.4
nameserver 10.19.90.11
nameserver 193.136.188.249

5 - As wisely suggested by Adafruit in [https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software#extra-removing-wpa-supplicant here], run the following command:

sudo mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/

rc.local configuration (create an ad-hoc network)

1 - Add the following to /etc/rc.local:

echo "\nReconfiguring WLAN0 & DHCP Server"

ifconfig wlan0 192.168.3.3 netmask 255.255.255.0
service isc-dhcp-server start
ifconfig wlan0 down;iwconfig wlan0 essid biomachines-02 mode ad-hoc;ifconfig wlan0 up
ifconfig wlan0 down;iwconfig wlan0 essid biomachines-02 mode ad-hoc;ifconfig wlan0 up
ifconfig wlan0 192.168.3.3 netmask 255.255.255.0

Pay atention that the IP address should be changed, in case you have multiple drones connected to the same ad-hoc.

2 - Change the /etc/network/interfaces content to match the following:

auto lo

iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
	address 10.40.50.243
        netmask 255.255.255.0
        gateway 10.40.50.1
	
allow-hotplug wlan0
iface wlan0 inet manual

iface default inet dhcp

DHCP Server Configuration

1 - Considering that you already installed the isc-dhcp-server, backup the /etc/dhcp/dhcpd.conf file (using the sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.backup) and replace the /etc/dhcp/dhcpd.conf content with the following:

ddns-update-style none;
deny declines;
deny bootp;

# option definitions common to all supported networks...
option domain-name "biomachineswlan";

default-lease-time 86400;
max-lease-time 604800;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

subnet 192.168.3.0 netmask 255.255.255.0 {
        range 192.168.3.100 192.168.3.200;
}

2 - On /etc/default/isc-dhcp-server file, change the configurations regarding DHCP interfaces, by uncommenting (if commented) the last line of the file and change it to INTERFACES=“wlan0"

3 - In order to create a special log, only to DHCP server, add the following line to /etc/rsyslog.conf:

# Logging for DHCP server
local7.*                        /var/log/isc-dhcpd-server.log

4 - To include the DHCP server file on the logrotate, on the bottom of /etc/logrotate.d/rsyslog add /var/log/isc-dhcpd-server.log.

5 - Remove DHCP from system startup by running the following command (we will start it from rc.local after the network has been initialized):

sudo update-rc.d -f isc-dhcp-server remove

6 - Finally make the DCHP server initialization permanent on boot, adding service isc-dhcp-server start to /etc/rc.local file (after the command regardind hostapd). The file should end up like this:

hostapd -B /etc/hostapd/hostapd.conf
service isc-dhcp-server start

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "\nMy IP address is %s\n" "$_IP"
fi

exit 0

Reference


Hardware Interfaces, Buses, Initialization Scrips Configurations

Installing WiringPi

In order to install WiringPi, you need to run first clone the project from GitHub and then build it:

cd ~/scripts/c
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
./build

Installing Java and Pi4J

Installation and configuration of Java is as simple as:

echo "export JAVA_HOME=\"/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt"" >> ~/.bashrc
echo "export PATH=$PATH:$JAVA_HOME/bin" >> ~/.bashrc
echo "export CLASSPATH=/home/pi/RaspberryController/bin:/home/pi/CommonInterface/bin:/home/pi/Behaviors/bin:.:/home/pi/RaspberryController/lib/joda-time-2.4.jar:/opt/pi4j/lib/pi4j-core.jar:/opt/pi4j/lib/pi4j-device.jar:/opt/pi4j/lib/pi4j-gpio-extension.jar:/opt/pi4j/lib/pi4j-service.jar:/home/pi/CommonInterface/jcoord-1.0.jar:/home/pi/RaspberryController/lib/libdbus-java-2.7.jar:/home/pi/RaspberryController/lib/cgi-0.6.jar:/home/pi/RaspberryController/lib/dbus-java-bin-2.7.jar:/home/pi/RaspberryController/lib/dbus-java-viewer-2.7.jar:/home/pi/RaspberryController/lib/debug-disable-1.1.jar:/home/pi/RaspberryController/lib/debug-enable-1.1.jar:/home/pi/RaspberryController/lib/hexdump-0.2.jar:/home/pi/RaspberryController/lib/io-0.1.jar:/home/pi/RaspberryController/lib/unix-0.5.jar" >> ~/.bashrc

Installation of Pi4J is as simple as:

curl -s get.pi4j.com | sudo bash

Installing D-Bus

In order to install D-Bus run the following command:

sudo apt-get install dbus-*dev

##Installing Aseba

1 - Download Aseba program, by running the following command:

wget https://aseba.wikidot.com/local--files/en:linuxinstall/aseba_1.3.3_armhf.deb

2 - Install Aseba with the command:

sudo dpkg -i aseba_1.3.1_armhf.deb

3 - Some packages may be missing, they have to be installed with the following command:

sudo apt-get -f install

##Installing Libmatthew libraries

1 - Download Libmatthew libraries, by running the following command:

wget http://pkgs.fedoraproject.org/repo/pkgs/libmatthew-java/libmatthew-java-0.8.tar.gz/8455b8751083ce25c99c2840609271f5/libmatthew-java-0.8.tar.gz

2 - Extract the .tar file content, with the command:

tar -xvf libmatthew-java-0.8.tar.gz

3 - Install the Libmatthew libraries, by running the following commands:

cd libmatthew-java-0.8
make
sudo make install

Reference

Other Configurations

In order to increase the User-Machine interface quality, there are some "hacks" to be made:

  • To display system information on login, replace the ~/.profile content by:
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

echo ""
echo -e '\E[33;40m'"\033[1mSystem Uptime Information and Who is logged in:\033[0m
"
w # uptime information and who is logged in

#echo ""
#echo -e '\E[33;40m'"\033[1mDisk Usage:\033[0m"
#df -h -x tmpfs -x udev # disk usage, minus def and swap

echo ""

You can also remove the Message of The Day (that present information about Debian GNU license) by deleting the content of /etc/motd. Finally, you can add extra information on the local console editing the content of /etc/issue file (this website contains more information about this).

  • To display colors on bash when using root user account, add the following lines to the bottom of /root/.bashrc:
force_color_prompt=yes
PS1='\[\e[0;31m\]\u@\h \[\e[m\]\e[1;34m\]\w\e[m\]\[\e[0;31m\] $ \[\e[m\]\[\e[0;37m\]'
  • Remove unwanted programs from startup using sudo sysv-rc-conf command (considering that you already installed the application)

  • You can enable CGroups by adding cgroup_enable=memory before elevator=deadline, in /boot/cmdline.txt file.

Reference

##Controlling Thymio II robot

1 - At this point you should be able to control the thymio through raspberry. In order to be able to start D-Bus on raspberry with X11 you have to access the Raspberry with the following command:

ssh -X pi@PI_ADDRESS

2 - To start aseba in order to communicate with the thymio II you need to run the command:

asebamedulla "ser:name=Thymio-II" &
export DISPLAY=localhost:10.0

3 - Transfer the code that you want to run to the Raspberry and run it. If you decide to use Java code for controlling the thymio II don't forget to use the command:

java -Djava.library.path=/usr/local/lib/jni/ -jar FILE_NAME.jar