This instrucatbale is used to document the development of an automated river water monitoring system. The monitored parameters are the water level and water temperature. The goal of this project was to develop a low-cost and independent Logger that is connected to a database. The water level is monitored with a special QR-level. A camera in the Pi is taking a picture every 15 min. The QR-codes in this picture get decoded by software and are indicative to the actual water level. Water temperature is measured with a DS18B20 sensor.
- Raspberry Zero WH
- WittyPi Mini
- Raspberry Pi Camera Module v2.1
- Huawei E3531 SurfStick
- SIM Card (ThingsMobile)
- DC DC Step Down Buck Converter
- DS18B20 Digital Thermometer
- OTG micro USB cable
- A micro USB cable end
- Window glas
- Sealed enclosure (G258)
- Cable fitting
- Srew Terminal Block 3-pin
- 4,7kOhm resistor
- Blank circuit board 65x30mm
- 40-pin staking-header
- 4 x M3x20 srews
- 8 xM3 screws
- Telephone cable
- Speaker cable
Step 1: Soldering the Temperature Module
In this step we create a temperature module from scratch. It has the size of a pHAT and can be connectet to the 40-pin GPIO of the Pi. This method allows us to securly mount the DS18B20 sensor to the Raspberry Pi.
- First we need to solder the 40-pin staking-header to the the 60x35 mm blank circuit board.
- Put the screw terminal block and the resistor in place as shown in the picture
- Connect the resistor to the outer pins of the terminal block
- Solder the resistor and pins together
- Solder the cables (black, red an yellow) to the exact pins of the staking header and to the pins of the terminal block
- To drill the mounting holes, first mount the module to your raspberry pi zero, then drill with a 3mm drill bit thru the existing holes from your raspberry pi into your new module.
- Finally you can connect your DS18B20 sensor to your module by attaching the the cables of your sensor to the corresponding colours on your board.
Step 2: Building Our DCDC Converter Cable
To power our Raspberry Pi we need to convert the 12V we get from our battery to 5V. Here for we use a DC DC buck converter to reduce the voltage.
- Solder the black wire form you speaker cable to the port labeled GND
- Solder the red wire to the port labeled IN+
- Solder the black wire from your micro-USB cable to the port labeled GND
- solder the red wire from your micro-USB cable to the port labeled OUT+
- cut of the circuit marked with the red arrow in the image
- weld the bonding pads togehter to get a 5V fixed output (blue arrow)
Step 3: Installing Your Surfstick
Step 4: Create a PostgreSQL Database
In this step we set up our Database. We make use of the free tier offer from Amazon Web Services.
- First create a free account on AWS: https://aws.amazon.com
- Follow this Tutorial to create your PostgreSQL Database and learn how to conect to it: https://aws.amazon.com/getting-started/tutorials/create-connect-postgresql-db/?nc1=h_ls
Step 5: Preparing the SD Card
First you need to download the Raspian Stretch Lite image:
Now we need to flash the image on an empty SD card (at least 16 GB). Insert the SD card into your SD-card reader. Download balenaetcher and install it on your computer:
Open Balena Etcher, select the .zip file of your Raspian image you previously downloaded. Select your SD card in Select Drive. Click Flash!
Step 6: Installing the Raspberry and Connecting to It Via SSH
Before we can use our Raspberry Pi we need to make some inital setups.
- Insert your SD card into your Raspberry Pi an connect it to a monitor, keyboard and mouse.
(If you dont have an extra monitor, keyboard and mouse you can make a headless installation. Look it up it has been done befor)
- Follow the setup steps of your raspberry pi [wifi, language, timezone]
- Enable SSH via Terminal on you PI:
got to: 5 Interfacing Options
- On your computer download Termius. This programm makes it easy to connect to our Raspberry Pi via SSH.
2.Make an account
3.Create NEW HOST
4.Give your Raspberry a label (choose a Name)
5.Enter your PI's IP-ADRESSE from the NETWORK it is logged in (if you don't know the IP-ADRESSE you can look for it with a programm called "ADVANCED IP SCANNER")
7.Enter your username (pi by default if not changed)
8.Enter your password (raspberry by default if not changed)
10.Double click on your new created host
11.A message pops up -> click yes
Your Raspberry should be conected to your computer via SSH
Step 7: Installing the Logger
- Enable the camera in the interfacing Options:
go to: 5 Interfacing Options
- Create a new directory in your /home/pi directory
sudo mkdir Desktop
- Create a new Python file in the Desktop directory
call the file qrbooftemp.py
- Install packages pyboof (numpy and py4j are automatically installed) this can take up to 40 min.
sudo pip3 install pyboof==0.33.1
- Run an update( if you dont do this you might get problems while installing packages later on)
sudo apt-get update
sudo apt-get install libpq-dev
- Install postgreSQL and psycopg2 to interact with the postgreSQL database via Python
sudo apt-get install postgresql
sudo pip3 install psycopg2
Step 8: Installing the Logger (Temperature Module)
To install the Temperature Module you need to mount the Module on your Raspberry Pi with a DS18B20 sensor attached to it. The module gets mounted via the 40-pin header.
- enable 1-wire in the interfacing options
go to: 5 Interfacing Options
- set 1-Wire pin to pin 23 and gpu_mem=256
sudo nano /boot/config.txt append dtoverlay=w1-gpio, gpiopin=23, pullup=on to the end of the file
change gpu_mem=128 to gpu_mem=256
- activate 1-Wire
sudo modprobe w1-gpio
sudo modprobe w1-therm
- find out your adresse of your DS18B20, it should start with 28- ...
write the adress down, it's later needed in the Python script
Step 9: Download and Adjust Pyhton Script
- Download the Python script on your computer and open it in a texteditor
- Copy the complete script to your clip board (ctrl+a , ctrl+c)
- Go to your previously created python file
sudo nano qrbooftemp.py
- make a right click to insert the script
- change the temperature sensor adresse to the one you previously wrote down
- change the postgresql connection setup to your specific information, as indicated in the script
- save and exit
Step 10: Installing the WittyPi Module
- Download the installation file from Wittypi
- Run the installation script
sudo sh installWittyPi.sh
Step 11: Make Some Changes in the Java Virtual Machine Setup
This step is necessary to make sure that the JVM will start when the Python script is executed.
- Go to the py4j directory and open jawa_gateway.py
sudo nano jawa_gateway.py
set DEFAULT_CALLBACK_SERVER_ACCEPT_TIMEOUT = 20
- Go to the pyboof directory and open __init__.py
sudo nano __init__.py
set while time.time() - start_time < 20.0
Step 12: Set Cron Job
In this step we set a cron job when the Raspberry boots. This way every time the Pi wakes our python script gets executed.
- Set cron job and write it to a log file. This makes troubleshooting more efficent.
@reboot sleep 20 && sudo python3 /home/pi/Desktop/qrbooftemp.py >> /home/pi/Desktop/log.txt
- Append an other line to crontab. This line makes sure, that when WittyPi failes the Raspberry Pi reboots anyway.
@reboot sleep 1500 && sudo reboot
Step 13: Putting It All Together
- Make sure you Pi is turned down if not shut it down
sudo shutdown -h now
- Stack your WittyPi on your Raspberry Pi and the temperature module on top of it.
- Screw the 3 modules together
- Attach the camera module to the CSI port of the raspberry pi zero
- Attache your surfstick to your Raspberry Pi via the USB OTG cable
- Attache the powercable to the the WittyPi (not to the Raspberry Pi!)
- Put it all in the casing and screw the lid down
Step 14: Final Installation
These pictures show the mounted logger with the QR-code water level installed.