How to create a new CrunchCam module image from scratch (Pi 4) - 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 4.

Connect the Raspberry Pi 4to your local network with a USB Ethernet adapter. Power on the Raspberry Pi 4.

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 4 IP Address]" into a terminal (this command should work unmodified on most operating systems). The default password is 'raspberry'.

Configure Raspberry Pi 4 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 4 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=disable-wifi

dtoverlay=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
  • matplotlib

(Note: these packages can be installed with the single command: "pip3 install PiCamera matplotlib")

Use the command "sudo apt install [package name]" to install all of the following packages:

  • python3-scipy
  • python3-dev
  • libatlas-base-dev
  • libjasper-dev
  • libilmbase-dev
  • libopenexr-dev
  • libgstreamer1.0-dev
  • libqtgui4
  • libqt4-test
  • libopencv-dev

(Note: these packages can be installed with the single command: "sudo apt install python3-scipy python-dev libatlas-base-dev libjasper-dev libilmbase-dev libopenexr-dev libgstreamer1.0-dev libqtgui4 libqt4-test libopencv-dev")

Installing OpenCV 4.1 for Python3/C++

Enter the command: 'pip3 install opencv-python==4.1.0.25'.

Test OpenCV Installation

To test the OpenCV installation with Python3, type the following commands (again, without the double quotes):

Open a python3 shell

  1. "python3"

Attempt to import OpenCV

  1. "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'.

Make sure this rc.local file is executable by typing the command 'sudo chmod +x /etc/rc.local'.

Local NTP Client Setup

Install ntpdate with the command: 'sudo apt-get install ntpdate'.

Disable the systemd time sync service with the command: 'sudo systemctl disable systemd-timesyncd'.

Install the NTP service with the command: 'sudo apt-get install ntp'.

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.100) 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!). The time/date can be viewed with the 'date' command.

Install Samba

Install Samba with the command 'sudo apt-get install samba'.

This will allow the Beam Cruncher client to resolve the hostname of the CrunchCam.

Install Basler Drivers (can skip if this camera module will not have Basler support)

Download files

Download pylon ("pylon 6.1.0 Camera Software Suite Linux ARM 32 bit hardfloat") package for Linux: https://www.baslerweb.com/en/sales-support/downloads/software-downloads/#os=linuxarm;version=all;type=pylonsoftware;language=all

Download latest stable pypylon wheel (for Python 3.7 - "cp37"): https://github.com/basler/pypylon/releases

Install pylon

Place the pylon .deb package in the home directory (/pi/home/) of the CrunchCam.

Run the following command to install pylon: sudo dpkg -i [name of pylon .deb package]

Install pypylon

After the pylon install completes, run the following command to install the pypylon python package: pip3 install [name of pypylon .whl installer]