2020-05-29 23:05:41 +02:00
# PlanktoScop Main Repository
The PlanktoScop is an open and affordable modular imaging platform for citizen oceanography.
2020-07-19 17:42:43 +02:00
This GitHub is part of a community that you can find on [its website ](https://www.planktonscope.org/ ).
2020-05-29 23:05:41 +02:00
2020-07-19 17:42:43 +02:00
# Fast Setup
2020-05-29 23:05:41 +02:00
2020-07-06 17:10:32 +02:00
Before going further, notice that you can download the image disk already setup without having to deal with all these command lines.
Jump here : http://planktonscope.su.domains/Images_raspberry/Raspbian_Buster_Morphocut_WiFi.img
2020-05-29 23:05:41 +02:00
2020-07-19 17:42:43 +02:00
# Expert Setup
After getting your kit and finding the necessary components, but before assembling your kit, you should take the time to do a mockup build and setup your Raspberry.
2019-12-17 04:08:11 +01:00
2020-05-29 20:00:59 +02:00
## Install and setup Raspbian on your Raspberry Pi
2020-04-15 22:17:18 +02:00
2020-07-19 19:21:33 +02:00
### Computer setup
In order to make it easy to connect to the PlanktoScop, you may want to install [avahi ](https://en.wikipedia.org/wiki/Avahi_%28software%29 ) or the [Bonjour ](https://en.wikipedia.org/wiki/Bonjour_%28software%29 ) service on any computer you will use to access the PlanktoScop interface. This will allow you to connect to the PlantoScop using an address similar such as http://planktoscope.local instead of an IP address.
2020-05-29 20:00:59 +02:00
### Download the image
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
The latest Raspbian version can always be downloaded from [the Raspberry Pi Downloads page ](https://www.raspberrypi.org/downloads/raspbian/ ).
For a first build, it's recommende to download an image of Raspbian Buster with desktop.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
#### Writing an image to the SD card
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Download the latest version of [balenaEtcher ](https://www.balena.io/etcher/ ) and install it.
2020-04-15 22:17:18 +02:00
Connect an SD card reader with the micro SD card inside.
2020-05-29 23:05:41 +02:00
Open balenaEtcher and select from your hard drive the image zip file you just downloaded.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Select the SD card you want to write your image to.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Review your selections and click `Flash!` to begin writing data to the SD card.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
#### Prepare your Raspberry Pi
2020-05-29 20:00:59 +02:00
[Getting Started with your Raspberry Pi ](https://projects.raspberrypi.org/en/projects/raspberry-pi-getting-started/ )
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Plug the SD Card in your Raspberry Pi and connect your Pi to a screen, mouse and a keyboard. Check the connection twice before plugging the power.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
The first boot to the desktop may take up to 120 seconds. This is normal and is caused by the image expanding the filesystem to the whole SD card. DO NOT REBOOT before you reach the desktop.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
#### Finish the setup
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Make sure you have access to internet and update/upgrade your fresh Raspbian install.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Update your Pi first. Open up a terminal, and do the following:
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo apt-get update -y
sudo apt-get upgrade -y
```
2020-05-29 23:05:41 +02:00
You can now reboot your Pi safely.
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo reboot now
```
2020-04-15 22:17:18 +02:00
2020-07-19 19:22:42 +02:00
## Raspberry Pi configuration
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
### Enable Camera/SSH/I2C in raspi-config
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Open up a terminal once again, and access the configuration tool:
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo raspi-config
```
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
While you're here, a wise thing to do would be to change the default password for the `pi` user. This is very warmly recommended if your PlanktoScop is connected to a shared network you do not control. Just select the first option `1 Change User Password` .
2020-07-19 19:23:10 +02:00
You may also want to change the default hostname of your Raspberry. To do so, choose option `2 Network Options` then `N1 Hostname` . Choose a new hostname. We recommend using `planktoscope` .
We need to activate a few things for the PlanktoScop to work properly.
First, we need to activate the camera interface. Choose `5 Interfacing Options` , then `P1 Camera` and `Yes` .
2020-05-29 23:05:41 +02:00
Now, you can go to `5 Interfacing Options` , then `P2 SSH` . Choose `Yes` to activate the SSH access.
Again, select `5 Interfacing Options` , then `P4 SPI` . Choose `Yes` to enable the SPI interface.
One more, select `5 Interfacing Options` , then `P5 I2C` . Choose `Yes` to enable the ARM I2C interface of the Raspberry.
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
Finally, select `5 Interfacing Options` , then `P6 Serial` .
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
This time, choose `No` to deactivate the login shell on the serial connection, but then choose `Yes` to keep the Serial port hardware enabled.
2020-04-15 22:17:18 +02:00
2020-07-19 17:38:17 +02:00
These steps can also be done from the Raspberry Pi Configuration GUI tool that you can find in `Main Menu > Preferences` . Go to the `Interfaces` tab. Pay attention, here the Serial Port must be enabled, but the Serial Port Console must be disabled.
2020-05-29 23:05:41 +02:00
Reboot your Pi safely.
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo reboot now
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:02:55 +02:00
## Install the needed libraries for the PlanktoScop
2020-04-15 22:17:18 +02:00
2020-07-19 19:23:22 +02:00
Most of the following happens in a command line environment. If you are using the desktop, please start a terminal emulator.
You can also connect to your PlanktoScop by using ssh using `ssh pi@planktoscope.local` .
You can then run the following to make sure your Raspberry has the necessary components to install and build everything it needs:
```sh
sudo apt-get install build-essential python3 python3-pip git
```
2020-05-29 20:00:59 +02:00
### Install CircuitPython
2020-05-29 23:05:41 +02:00
Start by following [Adafruit's guide ](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi ). You can start at the chapter `Install Python Libraries` .
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
For the record, the command are as following, however, Adafruit's page might have been updated, so please make sure this is still needed:
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 23:05:41 +02:00
pip3 install RPI.GPIO
2020-05-29 20:00:59 +02:00
pip3 install adafruit-blinka
sudo pip3 install adafruit-circuitpython-motorkit
```
2020-04-15 22:17:18 +02:00
2020-07-19 19:23:37 +02:00
It is recommended to test this setup by creating this small script under the name `blinkatest.py` and running it:
```python
#!/usr/bin/python3
import board
import digitalio
import busio
print("Hello blinka!")
# Try to great a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")
# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")
# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")
print("done!")
```
To run the script, just run the following:
```sh
chmod +x blinkatest.py
./blinkatest.py
```
The output should be similar to this:
```
pi@planktoscope:~ $ ./test/blinkatest.py
Hello blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!
```
2020-05-29 20:00:59 +02:00
### Install RPi Cam Web Interface
2020-04-15 22:17:18 +02:00
2020-07-19 17:38:17 +02:00
You can find more information about the RPi Cam Web Interface on [eLinux' website ](https://elinux.org/RPi-Cam-Web-Interface ).
2020-04-15 22:17:18 +02:00
2020-05-29 23:05:41 +02:00
To set it up, clone the code from Github and enable and run the install script with the following commands
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
./install.sh
```
2020-04-15 22:17:18 +02:00
2020-07-19 19:28:20 +02:00
Press Enter to allow default setting of the installation. Once everything is installed, press Enter to start the RPi Cam Web Interface now.
To test the interface locally, try accessing this url from the browser in the Raspberry: http://localhost/html
You can also try to access this page from another computer connected to the same network.
If your computer has `avahi` or the `Bonjour` service installed and running, you can directly use this url: http://raspberrypi.local/html/ .
If this is not the case, you first need to find the IP address of your Raspberry Pi by running the following:
```sh
2020-05-29 20:00:59 +02:00
sudo ip addr show | grep 'inet 1'
```
2020-04-15 22:17:18 +02:00
2020-07-19 19:28:20 +02:00
The web page can then be accessed at `http://[IP_ADDRESS]/html/` .
If the interface is loading and a picture is displayed, you can stop this interface for now by simply running `./stop.sh` .
2020-07-19 17:38:17 +02:00
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Install Ultimate GPS HAT
2020-07-19 19:28:33 +02:00
You can start by testing that the GPS module is working. Either install your PlanktoScop with a view of the sky, or connect the external antenna.
2020-04-15 22:17:18 +02:00
2020-07-19 19:28:33 +02:00
Now you need to run the following:
```sh
sudo apt-get install gpsd gpsd-clients
stty -F /dev/serial0 raw 9600 cs8 clocal -cstopb
cat /dev/serial0
```
If the GPS works, you should now see NMEA sentences scrolling:
2020-05-29 20:00:59 +02:00
```
2020-07-19 19:28:33 +02:00
$GPGGA,000908.799,,,,,0,00,,,M,,M,,*7E
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,000908.799,V,,,,,0.00,0.00,060180,,,N*44
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,000909.799,,,,,0,00,,,M,,M,,*7F
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,000909.799,V,,,,,0.00,0.00,060180,,,N*45
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,000910.799,,,,,0,00,,,M,,M,,*77
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,000910.799,V,,,,,0.00,0.00,060180,,,N*4D
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
2020-05-29 20:00:59 +02:00
```
2020-07-19 19:28:55 +02:00
Until you get a GPS fix, most of the sentences are empty (see the lines starting with GPGSA and with lot of commas).
2020-04-15 22:17:18 +02:00
2020-07-19 19:28:55 +02:00
You can find more information in this hardware module in Adafruit documentation at [Installing Adafruit GPS HAT ](https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi/overview ) or on this page to [use Python Thread with GPS HAT ](http://www.danmandle.com/blog/getting-gpsd-to-work-with-python/ )
### Install RGB Cooling HAT
To setup the RGB Cooling HAT, you just need to clone and build the WiringPi library:
```sh
2020-05-29 20:00:59 +02:00
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
sudo ./build
2020-07-19 19:28:55 +02:00
gpio -v
2020-05-29 20:00:59 +02:00
```
2020-07-19 19:29:55 +02:00
The last command should output something similar to the following:
2020-05-29 20:00:59 +02:00
```
2020-07-19 19:29:55 +02:00
gpio version: 2.60
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
Raspberry Pi Details:
Type: Pi 4B, Revision: 01, Memory: 4096MB, Maker: Sony
* Device tree is enabled.
*--> Raspberry Pi 4 Model B Rev 1.1
* This Raspberry Pi supports user-level GPIO access.
2020-05-29 20:00:59 +02:00
```
2020-07-19 19:29:55 +02:00
More information can be found on Yahboom website, on the page [Installing RGB Cooling HAT ](https://www.yahboom.net/study/RGB_Cooling_HAT ).
### Install Node-RED
2020-05-29 20:00:59 +02:00
#### Download and installation
2020-07-19 19:29:55 +02:00
To install Node.js, npm and Node-RED onto a Raspberry Pi, you just need to run the following command. You can review the content of this script [here ](https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered ).
```sh
2020-05-29 20:00:59 +02:00
bash < (curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
```
2020-07-19 19:29:55 +02:00
Type `y` at both prompts to accept the installation and its settings.
2020-04-15 22:17:18 +02:00
2020-07-19 19:29:55 +02:00
#### Enable start on boot and launch Node-RED
To run Node-RED when the Pi is turned on or restarted, you need to enable the systemd service by running this command:
2020-07-19 19:22:32 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo systemctl enable nodered.service
```
2020-04-15 22:17:18 +02:00
2020-07-19 19:29:55 +02:00
You can now start Node-RED by running the following:
```sh
sudo systemctl start nodered.service
```
2020-05-29 20:00:59 +02:00
#### Check the installation
2020-07-19 19:29:55 +02:00
Make sure Node-RED is correctly installed by reaching the following page from the browser of your pi http://localhost:1880 or http://planktoscope.local:1880 from another computer on the same network.
2020-04-15 22:17:18 +02:00
2020-07-19 19:29:55 +02:00
#### Install the necessary nodes
These nodes will be used by the PlanktoScop software and needs to be installed:
```sh
cd ~/.node-red/
npm install node-red-dashboard node-red-contrib-python3-function node-red-contrib-camerapi node-red-contrib-gpsd node-red-contrib-web-worldmap node-red-contrib-interval
sudo systemctl restart nodered.service
2020-05-29 20:00:59 +02:00
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
#### Import the last GUI
2020-04-15 22:17:18 +02:00
2020-07-19 19:29:55 +02:00
From Node-RED gui in your browser, choose the Hamburger menu top right, and then Import. You can paste the code directly from the lastest version of the GUI available [here ](https://raw.githubusercontent.com/tpollina/PlanktonScope/blob/master/flows/main.json ).
2020-07-19 19:47:48 +02:00
You can also download it directly:
```sh
wget -N -P ~/.node-red/lib/flows https://raw.githubusercontent.com/tpollina/PlanktonScope/master/flows/main.json
sudo systemctl restart nodered.service
```
2020-07-19 19:29:55 +02:00
#### More information
[Installing Node-RED on Raspberry Pi ](https://nodered.org/docs/getting-started/raspberrypi )
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Install Mosquitto MQTT
2020-04-15 22:17:18 +02:00
2020-07-19 19:30:16 +02:00
In order to send and receive data from Node-RED, you need to install this. Run the following:
2020-05-29 20:00:59 +02:00
```
sudo apt-get install mosquitto mosquitto-clients
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Install mqtt-paho
2020-04-15 22:17:18 +02:00
2020-07-19 19:30:16 +02:00
In order to send and receive data from python, you need this library. Run the following:
2020-05-29 20:00:59 +02:00
```
pip3 install paho-mqtt
```
2020-07-20 22:06:23 +02:00
2020-05-29 20:00:59 +02:00
### Install OpenCV
2020-04-15 22:17:18 +02:00
2020-07-20 22:06:23 +02:00
We need to install the latest OpenCV version. Unfortunately, it is not available in the repositories. We are going to install it directly by using pip.
First, we need to install the needed dependencies, then we will directly install opencv:
```sh
sudo apt install libgtk-3-0 libavformat58 libtiff5 libcairo2 libqt4-test libpango-1.0-0 libopenexr23 libavcodec58 libilmbase23 libatk1.0-0 libpangocairo-1.0-0 libwebp6 libqtgui4 libavutil56 libjasper1 libqtcore4 libcairo-gobject2 libswscale5 libgdk-pixbuf2.0-0 libhdf5-dev libilmbase-dev libopenexr-dev libgstreamer1.0-dev libavcodec-dev libavformat-dev libswscale-dev libwebp-dev libatlas-base-dev
sudo pip3 install opencv-contrib-python==4.1.0.25
```
You can now check that opencv is properly installed by running a python interpreter and importing the cv2 module.
```sh
pi@planktoscope:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.0'
>>> quit()
```
If all goes well, the displayed version number should be `4.1.0` .
More detailed information can be found on this [website ](https://www.pyimagesearch.com/2019/09/16/install-opencv-4-on-raspberry-pi-4-and-raspbian-buster/ ).
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Install MorphoCut
2020-06-16 21:30:47 +02:00
[Installing MorphoCut ](https://morphocut.readthedocs.io/en/stable/installation.html )
2020-04-15 22:17:18 +02:00
MorphoCut is packaged on PyPI and can be installed with pip:
2020-06-16 21:30:47 +02:00
```sh
2020-05-29 20:00:59 +02:00
sudo apt-get install python3-scipy
2020-06-16 21:30:47 +02:00
pip3 install -U git+https://github.com/morphocut/morphocut.git
2020-05-29 20:00:59 +02:00
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
## Finishing the install
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
Make sure to update your Pi
```
sudo apt-get update -y
sudo apt-get full-upgrade -y
```
2020-04-15 22:17:18 +02:00
Reboot your Pi safely
2020-05-29 20:00:59 +02:00
```
sudo reboot now
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
## Useful later maybe
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Download the GitHub repo
2020-04-15 22:17:18 +02:00
At this link : https://github.com/tpollina/PlanktonScope/archive/master.zip
Unzip to a specific location:
2020-05-29 20:00:59 +02:00
```
unzip /home/pi/Downloads/PlanktonScope-master.zip -d /home/pi/
mv /home/pi/PlanktonScope-master /home/pi/PlanktonScope
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Update node-RED interface
2020-04-15 22:17:18 +02:00
To update the interface, you can just download the lastest .json file:
2020-05-29 20:00:59 +02:00
```
wget -P $HOME/.node-red https://raw.githubusercontent.com/tpollina/PlanktonScope/master/scripts/flows_planktonscope.json
```
2020-04-15 22:17:18 +02:00
2020-05-29 20:00:59 +02:00
### Share WiFi via Ethernet
2020-04-15 22:17:18 +02:00
At this link : https://www.instructables.com/id/Share-WiFi-With-Ethernet-Port-on-a-Raspberry-Pi/