Skip to content
dcyoung edited this page Jul 18, 2017 · 49 revisions

This page details how to install the software on a Raspberry Pi. We recommend you start from a pre-built image, but also highly recommend that you familiarize yourself with the code that comes pre-installed. You'll get a lot more out of the project that way.


Installing a Pre-Built image on a Raspberry Pi

Modifying a fresh raspberry pi to work with the sweep-3d-scanner code can be a lengthy process. Additionally, the sweep-3d-scanner code and its dependencies will evolve and improve rapidly. You can always ssh into the pi and update the scanner code to the latest revision, but this can be cumbersome.

As a convenient alternative, we provide pre-built downloadable raspbian images. These images include all of the modifications to the pi, pre-installed dependencies, pre-installed scanner code etc. All you have to do is flash the image to an SD card and you can experiment with the scanner.

  1. Remove the SD card from the raspberry pi. Be sure to properly shutdown beforehand using sudo halt or sudo shutdown -h now
  2. Download the latest pre-built image and unzip it. You can download pre-built images for each release here.
  3. Download Etcher.
  4. Insert the SD card into your computer. You'll likely need an adapter.
  5. Open Etcher
  6. Select the downloaded image
  7. Select the inserted SD card
  8. Hit Flash
  9. When Etcher is finished flashing the SD card, eject and remove the SD card. Then insert it into the raspberry pi.
  10. Expand the filesystem to fill the space on the SD card. First connect to the rPi (see Connecting to Raspberry Pi). From the command line, run sudo raspi-config, and select "Expand Filesystem". Alternatively, you can run the following commands directly from the command line:
sudo raspi-config --expand-rootfs
sudo shutdown -r now

Note: While the pre-built images allow one to create a functional-scanner with limited setup, the project is still in development. There are a few dependencies and codebases that all come together to produce a working application. After flashing an image, we suggest you connect (ssh) to the pi and peruse the contents. The more you understand the processes involved, the easier it will be to troubleshoot issues and create lasting solutions.

Note: It is likely that the latest pre-built image is out of date with the latest sweep-3d-scanner code, bug fixes and features. If you don't want to wait for a new image, you can install the latest image, ssh into the rPi and update the sweep-3d-scanner code. See the later section on updating existing code.


Connecting to Raspberry Pi

The pre-built image automatically launches a node webserver process every time the rPi boots up. During normal use, you'll interface with the scanner application via a web-browser. See Using the Webapp for details.

But, in order to modify, develop and update code on the Pi, you'll have to connect to it directly. Once you have installed the pre-built image, this can be accomplished in different ways. Here are two options (we recommend the first):

  1. Connect to the Pi3-AP wifi access point from another computer and ssh into the rPi. Use IP address 172.24.1.1, along with the default raspbian username pi and password raspberry. If you are using a non-windows OS, you can likely use the hostname pi-dev-raspbian instead of the IP address, but the IP address should work from any OS.
  2. Plug a keyboard and monitor into the pi. After the boot sequence finishes, you should be prompted for a login. The rPi will show something like pi-dev-raspbian login: where "pi-dev-raspbian" is the hostname. It is asking for a login username. Type the default raspbian username pi, and it should prompt you for a password. Type the default raspbian password raspberry and you should have access to the command line.

Updating Existing Code

Note: Start by re-flashing the SD card with the latest release (pre-built image). You can check the releases page for new releases.

If you want to update code in between releases, it is possible to update the existing code on a pre-built image:

  1. Plug the Pi into an ethernet port.

  2. Connect to the rPi. See Connecting to Raspberry Pi for more details. We recommend you get familiar with sshing into the rPi.

  3. Update sweep-sdk

# retrieve latest version:
cd /home/pi/code/scanse/sweep-sdk
# Pull the latest from the branch with a fix specific to the RaspberryPi
git pull origin master

# uninstall existing libsweep installations:
sudo rm /usr/local/lib/libsweep*

# re-install updated libsweep:
cd libsweep
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install
sudo ldconfig
  1. Update sweeppy
# Uninstall existing `sweeppy` installation:
sudo rm /home/pi/.local/lib/python2.7/site-packages/sweeppy*

# Reinstall updated `sweeppy`:
cd /home/pi/code/scanse/sweep-sdk/sweeppy
python setup.py install --user
  1. Update sweep-3d-scanner
cd /home/pi/code/scanse/sweep-3d-scanner
git pull origin master
npm install
  1. reboot to relaunch webserver
sudo reboot

Setting up Raspberry Pi from Scratch

Even if you are developing and modifying the code, it can be easier to start with the pre-built image. However, if you are really determined to set up the Pi from scratch, here are the general steps:

  1. Use Etcher to install the latest Raspbian image (Jessie-Lite) from https://www.raspberrypi.org/downloads/raspbian/ onto the Pi.

  2. Setup the Pi: Use a monitor and keyboard to access Raspi-config, and:

  • Enable SSH Server (Interfacing Options -> SSH)
  • Enable I2C (Interfacing Options -> I2C)
  • Disable the login shell access over serial (Interfacing Options -> Serial)
  • Enable the serial port hardware (Interfacing Options -> Serial)

Plug the pi into Ethernet and update:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get upgrade
  1. Install git, cmake and node
# install git
sudo apt-get install git
# install cmake
sudo apt-get install cmake
#install latest node
# see https://github.com/audstanley/NodeJs-Raspberry-Pi/
...
  1. Create the following directory /home/pi/code/scanse/:
mkdir -p /home/pi/code/scanse/
  1. Build and install libsweep library
cd /home/pi/code/scanse/
git clone https://github.com/scanse/sweep-sdk

# install libsweep
cd sweep-sdk/libsweep/
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install
sudo ldconfig
  1. Add pi user to dialout group (the sweep will NOT work without this change)
sudo adduser pi dialout
sudo reboot
  1. Build and test the libsweep examples
cd ~/code/scanse/sweep-sdk/libsweep/examples
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .

# Test examples to make sure everything is working
./example-c /dev/ttyUSB0
./example-c++ /dev/ttyUSB0
  1. Install and test sweeppy
cd /home/pi/code/scanse/sweep-sdk/sweeppy
python setup.py install --user
  1. Install Adafruit libraries
# prep
sudo apt-get update
sudo apt-get install build-essential python-pip python-dev python-smbus git

# install Adafruit's Python GPIO library
cd /home/pi/code/scanse/
git clone https://github.com/adafruit/Adafruit_Python_GPIO
cd Adafruit_Python_GPIO
sudo python setup.py install

# install Scanse fork (with fixes) of Adafruit's Python MotorHat library
cd /home/pi/code/scanse/
git clone https://github.com/scanse/Adafruit-Motor-HAT-Python-Library
cd Adafruit-Motor-HAT-Python-Library
sudo apt-get install python-dev
sudo python setup.py install
  1. Install numPy
sudo apt-get install python-numpy
  1. Install sweep-3d-scanner
cd /home/pi/code/scanse/
git clone https://github.com/scanse/sweep-3d-scanner
cd sweep-3d-scanner
npm install
  1. Setup the Pi to host a wireless access point, by following this tutorial. After this step, you'll connect to the pi by connecting to it's wifi access point Pi3-AP using password raspberry. Once connected to the access point, you can ssh into the pi using ip address 172.24.1.1 and password raspberry.

  2. Run webserver on startup

Modify the /etc/rc.local file to launch the node webapp on start. Add the following line before exit 0

...
su pi -c 'node /home/pi/code/scanse/sweep-3d-scanner/app.js < /dev/null >& /home/pi/scanner_ouput.log &'
exit 0