How to create a new CrunchCam module image from scratch (Pi Zero) - crunchtec/Beam-Cruncher-Wiki GitHub Wiki
Obtain and Install Raspbian Operating System
Download the latest Raspbian Lite image and flash SD card with image
Download the latest Raspbian Lite image from https://www.raspberrypi.org/downloads/raspbian/.
Extract the image file from it's .zip folder.
Flash an SD card with Raspbian image
Use your favorite program to flash the Raspbian image to an SD card (at least 8 GB in size - but 16 GB is recommended). On Windows, I use "Win32DiskImager".
Configure the Raspbian Operating System
After the Raspbian image has been successfully flashed to the SD card, create an empty text file named "ssh.txt" and place it on the 'boot' partition of the SD card. Then, eject the SD card and insert it into the Raspberry Pi Zero.
Connect the Raspberry Pi Zero to your local network with a USB Ethernet adapter. Power on the Raspberry Pi Zero.
In your router's configuration page, determine the IP address of your Pi. With this address, ssh into the Pi by typing "ssh pi@[Pi Zero IP Address]" into a terminal (this command should work unmodified on most operating systems). The default password is 'raspberry'.
Configure Raspberry Pi Zero with raspi-config
After ssh-ing into the Pi, type the command 'sudo raspi-config'.
Change Password
Select menu item 1 (Change User Password) to change the password. Set it to 'Crunch!'.
Set Hostname
Select menu item 2 (Network Options), then select the N1 (Hostname) submenu item. Set the hostname as 'crunchcam'.
Select Boot Option
Select menu item 3 (Boot Options), then select B1 (Desktop/CLI), finally, select option B2 (Console Autologin).
Interfacing Options
Select menu item 5 (Interfacing Options), then set the Interfacing options as follows:
- P1 (Camera) --> Enable
- P2 (SSH) --> Enable
- P3 (VNC) --> Disable
Note: The VNC server may be impossible to disable in the "Lite" version of Raspbian, because there is no GUI to begin with - it is a non-issue.
- P4 (SPI) --> Disable
- P5 (I2C) --> Disable
- P6 (Serial) --> Enable
- P7 (1-Wire) --> Disable
- P8 (Remote GPIO) --> Disable
Run Update
Select menu item 8 (Update) and allow the Raspbian OS to update itself.
Select Finish. Enter the command 'sudo reboot' to reboot the Pi.
After the Pi finishes rebooting, retype the command "ssh pi@[Pi Zero IP Address]" into a terminal to ssh back into the Pi (remember that pi's password is now 'Crunch!').
Disable Bluetooth and Wifi
To disable Bluetooth and Wifi, enter the command 'sudo nano /boot/config.txt' and add the following 2 lines:
dtoverlay=pi3-disable-wifi
dtoverlay=pi3-disable-bt
Save the modified config.txt file. After the next reboot, the Bluetooth and Wifi adapters will be disabled.
Setup CrunchCam Module Software
Install git
Install git by typing the command "sudo apt install git"
Clone the CrunchCam repository
Navigate to the home directory by typing the command "cd ~". Clone the CrunchCam repository with the command "git clone https://github.com/crunchtec/CrunchCam". Type the command 'rm -rf ~/CrunchCam/.git' to remove the hidden git directory, which will turn the CrunchCam folder into a normal directory, rather than one associated with a git repository.
Install pip3
Install pip3 (to install Python packages) by typing the command "sudo apt install python3-pip".
Install all CrunchCam dependencies
Use the command "pip3 install [package name]" to install all of the following packages:
- PiCamera
- scipy
- matplotlib
(Note: these packages can be installed with the single command: "pip3 install PiCamera scipy matplotlib")
Use the command "sudo apt install [package name]" to install all of the following packages:
- python3-dev
- libatlas-base-dev
(Note: these packages can be installed with the single command: "sudo apt install python-dev libatlas-base-dev")
Installing OpenCV 4.1 for Python3/C++
Installing OpenCV 4.1 on Raspbian is more involved because, as of this writing (September 4th, 2019), there are no pip wheels for python 3.7 on Linux OSes with ARM architecture.
Enter the commands that follow (without the double quotes) in order to install OpenCV 4.1 for Python3/C++ (sans GUI):
Download the PiZero OpenCV 4.1 release from GitHub
Extract the release files
- "tar xfv opencv-4.1.0-pizero-no-gui.tar.bz2"
Move the extracted release folder to /opt and delete downloaded tar file
- "sudo mv opencv-4.1.0 /opt"
- "rm opencv-4.1.0-pizero-no-gui.tar.bz2"
Install OpenCV 4.1 dependencies
- "sudo apt install libgtk-3-dev libcanberra-gtk3-dev"
- "sudo apt install libtiff-dev zlib1g-dev"
- "sudo apt install libjpeg-dev libpng-dev"
- "sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev"
- "sudo apt install libxvidcore-dev libx264-dev"
- "sudo apt install python-numpy python3-numpy"
Add OpenCV 4.1 Library Path to .bashrc
This step is necessary to allow the Python interpreter to find the location of the OpenCV library we just installed. Enter the following commands (without the double quotes) to add the OpenCV 4.1 library path to .bashrc:
- "echo 'export LD_LIBRARY_PATH=/opt/opencv-4.1.0/lib:$LD_LIBRARY_PATH' >> .bashrc"
- ". .bashrc"
- "sudo ln -s /opt/opencv-4.1.0/lib/python2.7/dist-packages/cv2 /usr/lib/python2.7/dist-packages/cv2"
- "sudo ln -s /opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2 /usr/lib/python3/dist-packages/cv2"
Test OpenCV Installation
To test the OpenCV installation with Python3, type the following commands (again, without the double quotes):
Open a python3 shell
- "python3"
Attempt to import OpenCV
- "import cv2" If no error is displayed, the python interpreter has successfully found our OpenCV installation!
Replace default rc.local with CrunchCam rc.local
Navigate to the inner CrunchCam directory in the cloned repository by typing 'cd ~/CrunchCam/CrunchCam'.
Replace the default rc.local file (which tells the Pi to launch the CrunchCam.py script at startup) with the CrunchCam rc.local file by typing the command 'sudo cp rc.local /etc/rc.local'.
Local NTP Client Setup
Install ntpdate with the command: 'apt-get install ntpdate'.
Disable the systemd time sync service with the command: 'sudo systemctl disable systemd-timesyncd'.
Replace the default ntp.conf file (which tells the Pi to sync its time with a local NTP server - the Beam Cruncher computer @ 192.168.1.10) with the ntp.conf file in the CrunchCam repo. This file can be copied into place with the command: 'sudo cp ntp.conf /etc/ntp.conf'.
Enable the NTP service with the command: 'sudo systemctl enable ntp.service'.
Restart the CrunchCam and check that the time is synchronized with the Beam Cruncher client after ~10 minutes (when the Beam Cruncher client is fully setup + running!).