Raspberry Pi Guide - dlx-designlab/Attune GitHub Wiki

Setup:

Requirements

  1. Raspberry Pi3 or above
  2. SD Card (min 16gb)
  3. Raspberry Pi Power Supply. 2 Amps (10W) Min
  4. Good quality USB cable
  5. Genie Tech G-Scope
  6. For the full assembly instructions and BOM see Scan-Stations Page

Pre-configured SD card Image

  1. Download the latest Zip from here and Extract the IMG file inside
  2. Write The IMG file to an SD card (16GB or bigger)
  3. Insert the card into a RaspberryPi
  4. Upon 1st boot make sure to expand the file-system. The Pi should do it automatically, so keep attention to the terminal log)
  5. Check the file-system was expanded to accommodate all the space available on the SD card:
    df -h
  6. Update the WiFi-AP SSID to correspond with Attached the GScope number:
    sudo nano /etc/hostapd/hostapd.conf
    update the ssid=scoPi_## line and save the file
  7. Reboot the pi
  8. Check everything works as expected:
    • The scope_control_app starts upon boot - GScope Light goes on and the screen says "Capillary"
    • WiFi-AP "scoPi_##" is Available
    • Connection to http://192.168.4.1:8000 works from another device (phone or laptop)

Fresh Install Step by Step

  1. Install the latest version of the OS (Bookworm version) for the Raspberry pi 5 by using this installer. If the latest version of the OS is not a Bookworm one, find the latest version of Bookworm by using the history of releases and the files to download

  2. Follow this tutorial to assemble the Pi + CNC Shield

  3. Configure all Raspbian OS Settings:

    • Change username by "attunePi5"
    • Configure Wifi connection, Timezone and Language Settings.
    • Change default password to "attunePi5"
    • Check filesystem was properly expanded and is matching the SD card size: df -h
    • Install latest RaspbianOS updates
      sudo apt-get update && sudo apt-get upgrade
  4. Install the bCNC:

    pip config set global.break-system-packages true
    pip3 install bCNC
    

Then launch bCNC to initialize the home coordinates (HOME the motors, then set the coordinates of X, Y and Z to 0). Type this to launch bCNC : bCNC

  1. Attach a Motor Driver + Stepper Motor and test GRBL motor control Works as expected using bCNC.

  2. Install CMake, our custom version of libuvc and pyuvc

    sudo apt-get install build-essential cmake unzip pkg-config
    sudo apt-get install libusb-1.0-0-dev
    sudo apt-get install libjpeg-dev
    sudo apt-get install libturbojpeg0-dev
    pip install -vvv pupil-labs-uvc --timeout=60 --retries=10
    

    Install our custom version of libuvc modified for the G-Scope:

    cd ~/Downloads
    git clone https://github.com/yurikleb/libuvc
    cd libuvc/  
    mkdir build  
    cd build  
    cmake ..  
    make && sudo make install  
    sudo ldconfig  
    

    Set UDEV rules:

    echo 'SUBSYSTEM=="usb",  ENV{DEVTYPE}=="usb_device", GROUP="plugdev", MODE="0664"' | sudo tee /etc/udev/rules.d/10-libuvc.rules > /dev/null  
    sudo udevadm trigger
    

    Tip: If you run into problems, try this thread

  3. Install OpenCV :

    sudo apt-get install build-essential cmake pkg-config
    sudo apt-get install libjpeg-dev libtiff5-dev libpng-dev
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    sudo apt-get install libxvidcore-dev libx264-dev
    sudo apt-get install libfontconfig1-dev libcairo2-dev
    sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
    sudo apt-get install libgtk2.0-dev libgtk-3-dev
    sudo apt-get install libatlas-base-dev gfortran
    sudo apt-get install python3-dev   
    

You can have more information in step #2 from this tutorial.
Then install openCV via this command:
pip install opencv-contrib-python

  1. Install a few more required dependencies:
    For file management:

    pip install pyfolder pyzip pyexiv2 icecream
    sudo apt-get install build-essential libexiv2-dev libboost-python-dev  
    pip3 install py3exiv2
    

    For communication with the TMP and TOF sensors:

    pip3 install adafruit-circuitpython-neopixel
    pip3 install adafruit-circuitpython-vl6180x
    pip3 install adafruit-circuitpython-mlx90614
    

    For Image Processing:

    pip install ultralytics
    pip install scikit-image
    
  2. Check SPI, Remote GPIO and I2C are enabled
    IMPORTANT: Protoneer CNC Shield - the SDA and SCL pins of the I2C/GROVE connector are flipped. Make sure to cross solder the cables connected to those pins. more info here and here.

  3. Attach a G-Scope to the Pi

  4. Clone the "scope_pi_app_RPI5" branch of this repo :
    mkdir ~/Projects
    cd ~/Projects/
    git clone --single-branch --branch scope_pi_app_RPI5 https://github.com/dlx-designlab/Attune.git

  5. Create a new folder for the pictures captured :
    cd Projects/Attune/scope_control_app/static
    mkdir captured_pics

  6. Try running the scope control app:
    cd ~/Projects/Attune/scope_control_app
    flask run
    Open a browser and navigate to: http://localhost:5000/
    If everything was installed correctly you should see the video feed from the scope (G-Scope light should turn on) and be able to adjust the scope controls.

IMPORTANT: If the scope does not work, put the firmware on version 1.4.2

  1. Grab a coffee

  2. In Pi Preferences > Raspberry Pi Configuration:

    • Change Pi boot settings to "Boot to CLI"
    • Enable the SSH interface
  3. Configure the Pi as an Access Point
    (only step 1) with the SSID set to attune-## and the IPV4 address set to 192.168.4.1

    Then change some settings to access this hotspot :

    sudo nmcli connection modify "attune-##" 802-11-wireless.band bg
    sudo nmcli connection modify "attune-##" 802-11-wireless.channel 6
    

    Make sure to delete or remove the prority on the others WIFI you have used.

    Another option is to update the hotspot .nmconnection config file in /etc/NetworkManager/system-connections/
    Sample config:

    [connection]
    id=attune-###
    uuid=###-###-###-###-###
    type=wifi
    interface-name=wlan0
    timestamp=###
    
    [wifi]
    band=bg
    channel=6
    mode=ap
    ssid=attune-###
    
    [ipv4]
    address1=192.168.4.1/24
    method=shared
    
    [ipv6]
    addr-gen-mode=stable-privacy
    method=shared
    
  4. Setup a server and make the "scope_control_app" run automatically when the Pi boots up:

    sudo apt-get install supervisor
    pip3 install gunicorn
    sudo reboot now
    

    create a new config file for the "scope_control_app":
    sudo nano /etc/supervisor/conf.d/scope_app.conf

    Input the following settings and save the file:

    [program:scope_app]
    command=/home/attunePi5/.local/bin/gunicorn -b 0.0.0.0:8000 --workers=1 --threads=4 app:APP
    directory=/home/attunePi5/Projects/Attune/scope_control_app
    user=attunePi5
    autostart=true
    autorestart=true
    stopasgroup=true
    killasgroup=true
    

    Reboot the Pi:
    sudo reboot now

    Upon reboot the "scope_control_app" should be launched, the GScope Light should turn on and the GScope screen should read "Capillary".
    Connect to the WiFi Access Point "scoPi_##" from any device, open google chrome and navigate to http://192.168.4.1:8000
    On a Mobile phone, you can select to Add to Home Screen so it works like any other App on your device.

    More details in this tutorial

  5. Save your current setup in an IMG file: Cloning the SD Card
    The backup IMG will be quite big (same size as the SD card), shrink it using this handy script

Maintenance

Access the Pi via SSH

Please note: If you are trying to connect to several different scoPi stations from the same computer you might get an SSH Key Warning or Error!
In such case remove the cached keys for the address you are trying to connect to:
ssh-keygen -R 192.168.4.1 or ssh-keygen -R raspberrypi.local

Downloading Captured Image files from the Pi

  • Connect to the Pi WiFi Hotspot (default ssid: scopPi)
  • Open a terminal window and CD to the directory you want to download the files to (for example cd ~/Downloads)
  • To download all the captured images stored on the Pi, Type in:
    scp -r [email protected]:~/Projects/Attune/scope_control_app/static/captured_pics local-copy-of-folder-name
  • If you want to download the images of a specific user add his UUID to the Path:
    scp -r [email protected]:~/Projects/Attune/scope_control_app/static/captured_pics/ABCD1234 local-copy-of-folder-name

Update Default Scope Settings

  1. Connect to the Pi via SSH
  2. The default capture settings are saved inside the "scope_settings.json" file:
    sudo nano ~/Projects/Attune/scope_control_app/scope_settings.json
  3. Update the settings and save the file
  4. Reboot the Pi

Updating

In order to update the Scope-Control app to the latest version you will need to:

  1. Disable the "scoPi_##" hotspot
  2. Connect the Pi to your home/work wifi network which has access to the internet
  3. Download the update from this Github repo
  4. Re-enable the #scoPi_##" hotspot

Step by step

  1. Turn on the scope and connect to the "scoPi_##" hotspot

  2. Connect to the Pi via SSH:

    • On MacOS/Linux open terminal and type: ssh [email protected]
    • On Windows use PuTTY and open a new SSH connection to: "raspberrypi.local"
      You might need to install Bonjour to be able to connect to "hostname.local" address instead of an IP address
      putty-screenshot

    If it's the 1st time you are connecting to this Pi, type in: 'yes'
    Input username (Windows only): pi
    Input password: attune2020
    If successful, your command line should say: pi@raspberrypi:~ $

  3. Turn off the scope-control app: sudo supervisorctl stop scope_app

  4. Configure your WiFi settings (skip this step if you configured this before):
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

    Go to the bottom of the file and add the following:

    network={
        ssid="testing"
        psk="testingPassword"
    }
    

    Update the ssid and the psk values to match your WiFi network Name and Password
    Press CTL + X to save and close the file
    Press 'Y' to confirm saving changes

  5. Disable the "scopi_##" Network:
    sudo nano /etc/dhcpcd.conf

    Go to the bottom of the file and comment the last 3 lines (add '#' before each line) so it looks like this:

    #interface wlan0
    #    static ip_address=192.168.4.1/24
    #    nohook wpa_supplicant
    

    Press CTL + X to save and close the file
    Press 'Y' to confirm saving changes

  6. Reboot the pi (the SSH connection to the pi will close):
    sudo reboot now

  7. The Pi Should reboot and connect to your local WiFi network configured in step 4

  8. Connect your computer to the same local WiFi network and SSH into the Pi gain (as described in step 2)

  9. Turn off the scope-control app:
    sudo supervisorctl stop scope_app

  10. Goto the App Directory:
    cd Projects/Attune/

  11. Get the latest version of the app from Github:
    git pull
    Input your Github username and password.
    If successful, you should see the list of the updated files (something similar to this):
    git pull screenshot

  12. Activate the "scopi_##" Network:
    sudo nano /etc/dhcpcd.conf
    Go to the bottom of the file and un-comment the last 3 lines, (remove '#' before each line) so it looks like this:

    interface wlan0
        static ip_address=192.168.4.1/24
        nohook wpa_supplicant
    

    Press CTL + X to save and close the file
    Press 'Y' to confirm saving changes

  13. Reboot the pi (the SSH connection to the pi will close):
    sudo reboot now

  14. Wait for the Pi to reboot.
    Connect to the "scopi_##" network from your laptop or phone.
    Check the app works and the new features are available!