Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ adafruit-circuitpython-lis3dh = "*"
adafruit-circuitpython-max31865 = "*"
gpiozero = "*"
pandas = "*"
"rpi.gpio" = "*"
click = "*"
adafruit-ads1x15 = "*"
exceptiongroup = "*"
numpy = "*"
adafruit-blinka = "*"
808 changes: 424 additions & 384 deletions Pipfile.lock

Large diffs are not rendered by default.

101 changes: 17 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,40 @@
# Alkalinity Titrator Project
# Tank Controller in Python

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

## Project motivations

As CO2 levels increase, the ocean absorbs more CO2 and becomes more acidic. There currently exists a large deficit of data on how this affects wildlife. Alkalinity Titrators are needed for ocean acidification research​. Currently, available models are expensive ($10,000-$25,000)​. Models on the lower end of the price range are not automated and are therefore time intensive.
## Project Motivations

This project aims to make ocean acidification research more widely available by lowering the cost of alkalinity titrators.
Update the `TankController` code from C++ to Python and run on a Raspberry Pico.

The problems that the alkalinity-titrator seek to fix are as follows:

- Lower the cost of ocean science equipment by using inexpensive, widely-available parts
- To automate the titration process, saving time and effort when determining total alkalinity
## Requirements

The titration process used in this project is based on SOP 3b from
The system should have Python and pipenv.
The development version also needs Tkinter which can be found in python3-tk for Ubuntu.

```Christian, James Robert, Andrew G. Dickson, and Christopher L. Sabine. Guide to Best Practices for Ocean CO2 Measurements. Sidney, B.C.: North Pacific Marine Science Organization, 2007.```
## Developer Instructions

## Current Development Note

The most recent development in this project is the implementation of a UI State Machine framework (see the titration/utils/UIState folder for UI states implemented). While the UI State Machine framework has been fully implemented, the actual titration processes and routines have not been integrated with the UI State Machine (see GitHub Issues for further specifications).

## Setup and Installation

### Setting up the Raspberry Pi

Refer to <https://desertbot.io/blog/headless-raspberry-pi-3-bplus-ssh-wifi-setup> for instructions on setting up the raspberry pi (note: headless setup is not required if a keyboard and monitor are available). Raspbian lite has everything needed, but the desktop version can be downloaded if working with a GUI is preferable.

### Installing software

Run standard updates on the pi:

``` sh
sudo apt-get update
sudo apt-get upgrade
```

This project utilizes SPI and I2C protocols, both of which often come disabled on the pi. To enable them, run:

``` sh
sudo raspi-config
```

and navigate to "Interfacing Options"; enable both SPI and I2C.

Install git:

``` sh
sudo apt-get install git
```

Clone alkalinity titrator repository to the pi

``` sh
git clone https://github.com/Open-Acidification/alkalinity-titrator.git
```
### Run in Local Environment

Run installation script
To run in a local environment with mocked devices (with the UI State Machine integrated)

``` sh
sudo ./install.sh
./run_gui.sh
```
## User Instructions

### Run on Device

To run (with the UI State Machine integrated)

``` sh
./run.sh
```
### Update Python Virtual Environment

### Run in Local Environment
Run `pipenv install` in the terminal to get the latest dependencies and update the lockfile.

To run in a local environment with mocked devices (with the UI State Machine integrated)
### Virtual Environment

``` sh
./run_mocked.sh
```sh
python3 -m venv .venv
source .venv/bin/activate
pip3 install --user pipenv
```

## Testing
Expand All @@ -89,29 +45,6 @@ To perform Pytest tests for the devices and UI states.
./test.sh
```

## Pins

### Temperature probe ([MAX31865 breakout board](https://learn.adafruit.com/adafruit-max31865-rtd-pt100-amplifier/python-circuitpython))

- PIN 1 (3.3v) to sensor VIN
- PIN 9 to sensor GND
- PIN 19/BCM 10 to sensor SDI
- PIN 21/BCM 21 to sensor SDO
- PIN 23/BCM 23 to sensor CLK
- PIN 29/BCM 5 to sensor CS (or use any other free GPIO pin)

### pH probe ([ADS1115 analog converter](https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/python-circuitpython))

- PIN 17 (3.3v) to ADS1115 VDD - Remember the maximum input voltage to any ADC channel cannot exceed this VDD 3V value!
- PIN 6 to ADS1115 GND
- PIN 5/BCM 3 SCL to ADS1115 SCL
- PIN 3/BCM 2 to ADS1115 SDA

## Libraries

1. Circuit Python - <https://github.com/adafruit/Adafruit_CircuitPython_MAX31865>
<br>
Used for communicating with the PT1000

## Contributors ✨

Expand Down
2 changes: 1 addition & 1 deletion install.sh → device_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ apt-get update # To get the latest package lists
apt-get upgrade
apt install pipenv -y # pipenv virtual environment
apt-get install rpi.gpio
pipenv install
pipenv sync
1 change: 1 addition & 0 deletions run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
pipenv sync
pipenv run python main.py
3 changes: 2 additions & 1 deletion run_gui.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
pipenv run python main.py -gui
pipenv sync -d
pipenv run python main.py -gui
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
pipenv sync -d
pipenv run pytest -vv
17 changes: 13 additions & 4 deletions titration/titrator_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ def run():
titrator = Titrator()

if mock_config.MOCK_ENABLED:
thread = threading.Thread(target=run_gui, args=[titrator], daemon=True)
# Run titrator loop in a background thread, GUI on main thread
thread = threading.Thread(target=run_loop(titrator), daemon=True)
thread.start()

while True:
titrator.loop()
run_gui(titrator)
else:
run_loop(titrator)


def run_gui(titrator):
"""
The function that drives the Alkalinity Titrator's GUI
"""
GUI(titrator)


def run_loop(titrator):
"""
The function that drives the Alkalinity Titrator's loop
"""
while True:
titrator.loop()