Skip to content

JarvisSan22/OPC-N3_python

Repository files navigation

OPC N3 Python repository

Author: Daniel Jarvis Contacts: JarvisSan21@gmail.com

Python library for the Aplhasense OPC-N3, and OPC-N2, connected through an SPI interface to a raspberry pi.

  • Additonal support for SDS011 added 28/05/2019
  • Dashboard server added, in AQ/rpi3webserver, for live plotting using a Flask based web server (Let me know if it works) (23/10/2019)

OPC-N3

Repository details

Basic functions scripts "OPCN3_test.py" for direct control of the OPCN3 functions. Basics log scripts "OPCN3_rec.py" to log the data to a CSV and a more advanced functional library under AQ currently operation at the University of Leed and Summit site in Greenland. The AQ library designed to work for multiple OPC attached to the same RPI3 logging all the data to one CSV file.

Dashbord "AQ/AQplotter" ( see repository for further instructions). Dashboard shows diffrent varaibles, as well as options for GPS maps and static maps, what work for multiple sensors in diffrent location. (More updates coming soon) Dashboard

OPCscripts details:

  • opcn3_rec.py OPCN3 functions script
  • opcn2_rec.py OPCN2 function script
  • variables.py sensors operation varaibles, for attaced sensors names and ports, log interval time, opration type (log or GPS) and location name with latitude and longitude coardinets
  • start.py Start oprataion scripts. RUN all sensors attaced and specified in variables.py
  • status.py Checks RPI3 status, logging data on time, IP address, and update RPI time if internet is corrected
  • /DHT DHT Sensors libary by Adafuit
  • DHT.py DHT scripts to be called in start.py to log data to csv
  • GPS.py edits of python GPS scripts by Dan Mandle to be called in start.py to log data to csv
  • AQ/MulOPCData.py script to read the csv output, accounting for multiple OPC attaced to one RPI3

Bascis Function list:

  • initOPC(): , initionate SPI connection with OPCN3
  • fanOn() , turn on fan
  • fanOff(): , turns fan off
  • LazOn(): , turns lazer on
  • LazOff():, turns lazer off
  • RHcon(): , converts RH bytes into RH by RH=100*(bytes/(2^16-1))
  • Tempcon(): , converts OPC Temperature bytes to Temprature (C) by Temp=-45+175*(bytes/(2^16+1))
  • combine_bytes(LSB,MSB): combines upper and lower bytes for bin data
  • getHist(): , gest hist data from OPC
  • getdata(): , gets just PM data from OPC
  • Hisdtdata(): , get outbut from gethist and convert it into the varaible information

AQ repositroy structure:

  • /AQ
  • /AQ/OPCData Directory for log data to be stored
  • /AQ/OPCscripts Scripts to run OPCN3, OPCN2 with options for DHT11 or DHT22 Temprature and RH sensors and GPS attachment.
  • /AQ/AQPlotter Dashboard plotting scripts
  • /AQ/teamviewer-host_14.1.18533_armhf.deb RPI3 installer package for teamviewer allowing romote over a WIFI connection.

AQ set up

Once RPI3 is set up and connected to wifi
default set up packagesexample GPS Plotter scipts in "AQ/AQplotter"

'sudo apt-get update'

'sudo pip install psutil' used to check wifi in status.py

'sudo pip install ntplib' used to check time RPI3 and update it in status.py

Optional Installs

DHT install 'sudo python3 AQ/OPCscripts/DHT/setup.py install'

GPS install GPS used is G-mouse USB Gps Dongle, GPS set up on RPI3 follows those found on this youtube vid by KM4ACK, setting the GPS up as the RPI3 clock as well.

RPI3 external clock if the GPS is not attached to the Adafruit PiRTC is recommended to be attached to the RPI3 to stop the RPI3 time drifting when the internet is lost. Setup instructions

Getting the kit running

in OPCscripts 'cd/OPCscripts'

update varaibles.py 'nano variables.py'

Update the RPI3 name (RPINAME)

operation location (LOC), desired MODE: "LOG" or "GPS" or "TEST". "LOG" is for static site recording to csv, "GPS" added the lat, lon and altitude to csv allowing for mobile usage. "TEST" will create a new data file ever time "start.py" is run

RUNNING sensors (RUNSEN) (Note: multiple OPC sensors can be added) The connection ports (RUNPORTS), if your not sure what port it is 'cd /dev/' then unplug and replug the OPC cable DHT setting, if DHT is connected set "DHTON" to "ON", and insert the DHT name in (DHTNAMES) and connected RPI pin in (DHTPINS)

variables

With all variables now set up hopefully correctly by just running start.py the attached OPC sensors will start logging

'python3 start.py'

This command can be added to crontab to get the sensors running on startup. 'sudo nano crontab -e'

'@reboot python3 AQ/OPCscripts/start.py'

SDS011 support

With an plugged in SDS011, in 'variables.py' add "/dev/ttyUSB0" as the first variable in RUNPORTS and do the same for the name (i.e DSO11_1) in RUNSEN. run 'python start.py' (for some currently unknown reason python3 does not work with the SDS, will fix soon). This will add a columns for the SDSO11s; sds-pm2.5, sds-pm10 and the other unkownvalue (assumed to be TSP) reading.

SDSsetup

Error log:

  • 30/05/2019 Added failed attemt varaible for OPCN3 scripts. Found on Summit by Heather Guy, OPN3 was sending enoguh data using a 5m wire, by increasing the failed attemts in OPCN3_rec.py from 20 to 40 the OPC send the data.

To do:

  • add OPCN3 live databoard, working on the RPi3
  • add functions to change default bin weighting
  • Implement new PM10, PM2.5 and PM1 calculation

Case

Releases

No releases published

Packages

No packages published