Clone wiki

prida_one / raspberry

Navigation
Project Plan Project Requirements Project Design README

Raspberry Pi Setup

The Raspberry Pi is a low-cost Linux single-board computer with an ARM processor. The entire computer is the about the size of a credit card and fits in the palm of your hand. It does not come with an operating system, computer monitor, keyboard or mouse; therefore, you will have procure these items on your own. The operating system is installed on a micro-SD card (also not included). The audio/video output (for a monitor) is provided by an HDMI port, so you may have to get an HDMI to VGA converter if you want to connect to a standard computer monitor (e.g., see here). There are four USB ports, enough to accommodate the peripherals of this project.


Table of Contents


Overview of System Hardware

ArchLinux ARM

Due to the limited resources of the Raspberry Pi, we selected the lightweight, yet powerful, ArchLinux operating system. This section will guide you on how to install and configure ArchLinux for ARM processors.

Follow the appropriate setup guide for your Raspberry Pi 2 or Raspberry Pi 3 to prepare the SD card for Raspberry Pi using the latest ArchLinuxARM ISO.

Power the Raspberry Pi. At the welcome screen login using the default user:

alarmpi login: alarm
password: alarm

Static IP

If you require a static IP address (such as we need in the Robert W. Holley Center), edit the file /etc/systemd/network/eth0.network using the root user (i.e., su root where the root user password is root) to look something like this (note that you should change the IP address based on what you have been assigned; for those of you who are not in the Robert Holley Center, please update all three fields as appropriate):

eth0.network

[Match]
Name=eth0

[Network]
Address=128.253.66.<###>/24
Gateway=128.253.66.1
DNS=128.253.180.2

Reboot the computer and check that the static IP address and DNS server are correctly working by typing the following two commands:

ifconfig
ping www.google.com

Desktop Environment

For simplicity, we have opted to use the MATE Desktop Environment for ArchLinux. From the terminal, run the following commands to install the required packages and their dependencies:

su root                          # password is 'root'
pacman -Syu                      # update && upgrade
pacman -S xorg-server            #   ~17.57 MiB
pacman -S xorg-server-utils      #    ~2.04 MiB
pacman -S xorg-xinit             #    ~0.07 MiB
pacman -S xorg-utils             #    ~0.72 MiB
pacman -S xorg-server-xephyr     #    ~2.28 MiB  * optional for LightDM test mode
pacman -S xf86-video-fbdev       #    ~0.06 MiB
pacman -S mate                   #  ~737.   MiB  * select ALL
pacman -S mate-extra             #  ~426.57 MiB  * select ALL
pacman -S lightdm                #    ~1.63 MiB
pacman -S lightdm-gtk-greeter    #    ~0.93 MiB
systemctl enable lightdm.service

Edit the file /ect/lightdm/lightdm.conf under the SeatDefaults section (i.e., uncomment these lines and change their values):

  • greeter-session=lightdm-gtk-greeter
  • greeter-hide-users=true
  • greeter-allow-guest=false
  • greeter-show-manual-login=true
  • user-session=lightdm-gtk-greeter.desktop

Create ~/.xinitrc file for user alarm (i.e., if still root user, type exit to go back to being user alarm):

  • Run cp /etc/X11/xinit/xinitrc ~/.xinitrc to create a default xinitrc file in alarm's home directory
  • Append exec mate-session to the end of ~/.xinitrc

Reboot to launch MATE.

Sudoer User

On the terminal, log in root user (from alarm):

  • [alarm]$ su
  • Password: root

Install the sudo package with pacman:

  • pacman -S sudo

As root, edit the sudoers list:

  • [root]$ EDITOR=nano visudo

Add the following line to the sudoers list:

  • alarm ALL=(ALL) ALL

Save and close. Make sure to exit the root user.

NTP Server

To set up an NTP server on ArchLinux, first the ntp package must be installed:

  • sudo pacman -S ntp

Then, run the following commands:

sudo systemctl enable ntpd.service
sudo systemctl enable systemd-timesyncd

Then, sudo nano /etc/ntp.conf and add the desired NTP server. For Cornell University use:

server ntp0.cornell.edu iburst

Or use another valid ntpserver at your preference. Note that in some cases the system may not correctly poll the server and the time will not update. In this case, try selecting a more reliable and secure network such as the Cornell server. Some networks, such as the one at the Robert W. Holley Center, may forbid servers without the requisite credentials from updating your local machine.

Finally, double check your timezone with the following terminal command:

  • timedatectl

If the localtime value is incorrect, look up your time Zone/SubZone with the following command:

  • timedatectl list-timezones

After locating your Zone/SubZone (e.g. America/NewYork for those at Cornell), set the correct timezone with the following command:

  • timedatectl set-timezone <Zone/SubZone>

Where <Zone/SubZone> is the timezone you identified in the previous step.

HDMI Monitor Boot Configuration

Open the file /boot/config.txt using sudo nano and set the HDMI-group, HDMI-mode and HDMI-drive parameters as follows:

HDMI-group=2
HDMI-mode=35
HDMI-drive=2

This will have the system boot in proper 720p resolution. Otherwise, the system relies on resolution auto-detection, which does not set the resolution properly without rebooting the system following the initial powering on of the pi.

Packages for Explorer Mode

To run Prida in Explorer Mode, install the following packages:

sudo pacman -Syu                 # system update && upgrade
sudo pacman -S git               # v. 2.11.0 (~26 MiB)
sudo pacman -S python            # v. 3.6.0 (~102 MiB)
sudo pacman -S python-numpy      # v. 1.11.3 (~15 MiB)
sudo pacman -S python-pyqt5      # v. 5.7.1 (~15 MiB); includes qt5-base and pyqt5-common
sudo pacman -S libxkbcommon-x11  # v. 0.7.1 (~1 MiB)
sudo pacman -S python-h5py       # v. 2.6.0 (~3 MiB)
sudo pacman -S python-pillow     # v. 4.0.0 (~2 MiB)

# Optional for analysis/calibration
sudo pacman -S python-scipy      # v. 0.18.1 (~38 MiB)

Version numbers are based on the package definitions installed in January 2017.

Packages for Hardware Mode

2D Mode

To run Prida in 2D Mode, install the following packages:

sudo pacman -S --needed base-devel  #            ~130 MiB
sudo pacman -S libgphoto2           # (v. 2.5.9)   ~7 MiB
sudo pacman -S python-pip           # (v. 9.0.1)   ~6 MiB
pip install --user gphoto2          # (v. 1.5.1)

3D Mode

To run Prida in 3D Mode using the (Arduino) Shield controller, install the following packages:

sudo pacman -S python-pyserial      # (v3.1a0)  ~0.6 MiB

To run Prida in 3D Mode using the Adafruit stepper motor HAT, the following packages are required from the ArchLinux User Repositories (AUR):

First, create a Builds directory (e.g., ~/Builds) and clone the necessary git repositories:

git clone https://aur.archlinux.org/i2c-tools-git.git     # v. r290.9726bed-2
git clone https://aur.archlinux.org/python-smbus-git.git  # v. r290.9726bed

Located within each directory is a single file (PKGBUILD). To make the packages, run the following starting with I2C Tools:

makepkg -sri

You may be requested to enter your password during installation. Following installation, with pacman you can check the installed versions (e.g., sudo pacman -Q i2c-tools-git) and perform uninstallation (e.g., sudo pacman -R python-smbus-git).

Hardware User Privileges

USB Privileges

These steps are necessary for setting up hardware privileges for a digital camera and/or the Arduino motor shield.

The user does not by default have permissions to read and write to USB devices. The sudo command allows the user to indirectly circumvent this; however, the user may address this by adding themselves to the appropriate groups.

First, in the terminal, check if the user is already in the groups plugdev (for communicating with the USB camera) and uucp (for PySerial communication with Arduino):

cat /etc/group | grep <user>

where <user> is your username.

This displays what groups the user is currently a part of. If the user is not a part of the plugdev or uucp groups, the user may grant themselves these permissions by adding themselves to the appropriate groups with the following commands:

sudo usermod -aG <group> <user>

Where again <user> is your username and <group> is the group name you want to add yourself to (e.g., plugdev and uucp).

I2C Privileges

These steps are necessary for setting up hardware privileges when using the Raspberry Pi's stepper motor HAT, which utilizes I2C communication.

Open the following file:

sudo nano /etc/modules-load.d/raspberrypi.conf

Add the following lines to the bottom of the file:

i2c-bcm2708
i2c-dev

Then, add the following lines to /boot/config.txt again using the sudo nano command:

dtparam=i2c1=on
dtparam=i2c_arm=on

Now reboot your Raspberry Pi. When it finishes booting, test that you have correct configured i2c on your pi with the following command:

sudo i2cdetect -y 1

You should see an output that looks something like the following:

With i2c now enabled on your Pi, we need to create the i2c group and add your username to this group to grant hardware usage privileges. Use the following commands:

su root
groupadd i2c
usermod -aG i2c alarm
echo 'KERNEL=="i2c-[0-9]*", GROUP="i2c"' >> /etc/udev/rules.d/10-local_i2c_group.rules
exit

With the group created and your user added to it, we now need to grant users in the group read-write privileges to i2c devices. Use the following commands:

sudo chgrp i2c /dev/i2c-1
sudo chmod 660 /dev/i2c-1

You may need to reboot to enable these changes.

Moving Root Partition to HDD

  1. Format HDD w/ primary Linux partition.
  2. Connect HDD to Pi:
    • /dev/sda1
    • mounted to <DIR>/Raspberries, where
      • <DIR> is /media/Raspberries (Raspbian)
      • <DIR> is /run/media/alarm (ArchLinux)
  3. Sync RPi root to HDD
    • sudo rsync -axzv / <DIR>/Raspberries
      • -a archive mode, recursive copying with preservation
      • -x one-file-system, don't cross filesystem boundaries
      • -z compress file data
      • -v verbose mode
  4. Back up cmdline.txt
    • sudo cp /boot/cmdline.txt /boot/cmdline.orig
  5. Edit root= in cmdline.txt to point to HDD
    • sudo nano /boot/cmdline.txt
    • root=/dev/sda1 <-- edit this part
  6. Edit fstab on HDD
    • sudo nano <DIR>/Raspberries/etc/fstab
    • Add:
      • /dev/sda1 / ext4 defaults, noatime 0 1
    • Comment out the SD card, eg:
      • #/dev/mmcblk0p2 / ext4 defaults,noatime 0 1

Raspberry Pi Motor HAT

Required parts list:

  • Adafruit Motor HAT for Raspberry Pi 2 Model B (x1)
  • 470 Ohm resistors (x2)
  • Piezo Buzzer (x1)
  • RG LED (x1)
  • 3x1 Header (x1)
  • 4x1 Header (x1)

On the top of the Motor HAT board, connect one lead of the piezo buzzer to the 0th channel of the PCA chip (labelled xtraPWM) and place the other lead through an available hole in the Motor HAT's protoboard space---make certain to leave room (about one wire's width) between the bottom of the buzzer and the top of the board.

Flipping the Motor HAT board upside down, twist a piece of single core wire about the piezo lead in the protoboard space to act as a jumper cable and connect the other end of the jumper cable to a ground pin.

Connect one lead each of the two resistors to the PWM channels 14 and 15, once again leaving some space between the resistors and the surface of the PCB.

Solder the 3x1 header along the spare ground connectors on the PCB and solder the 4x1 header along one of the empty columns of the proto-space.

  • Wrap the remaining resistor leads around the pins of the 4x1 header
  • Solder the resistors and all remaining connections into place
  • Insert the green and red LED leads into the header spaces corresponding to the PWM channels 14 and 15
  • Connect the common cathode of the LED to ground through one of the channels of the 3x1 header

Updated