mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
dfrph: Initial implementation
The driver implements support for the DFRobot pH sensors. It was tested with both the standard and Pro versions, calibrated with standard buffer solutions at pH 4.01 and pH 7.0. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
db721845db
commit
255d6cbe86
@ -152,6 +152,7 @@ add_executable (urm37-example urm37.cxx)
|
||||
add_executable (urm37-uart-example urm37-uart.cxx)
|
||||
add_executable (adxrs610-example adxrs610.cxx)
|
||||
add_executable (bma220-example bma220.cxx)
|
||||
add_executable (dfrph-example dfrph.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -268,6 +269,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/xbee)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/urm37)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adxrs610)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/bma220)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/dfrph)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -421,3 +423,4 @@ target_link_libraries (urm37-example urm37 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (urm37-uart-example urm37 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (adxrs610-example adxrs610 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (bma220-example bma220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (dfrph-example dfrph ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
76
examples/c++/dfrph.cxx
Normal file
76
examples/c++/dfrph.cxx
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "dfrph.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
#define DFRPH_AREF 5.0
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
// reference voltage of DFRPH_AREF
|
||||
upm::DFRPH *sensor = new upm::DFRPH(0, DFRPH_AREF);
|
||||
|
||||
|
||||
// After calibration, set the offset (based on calibration with a pH
|
||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||
// calibrations instructions.
|
||||
sensor->setOffset(0.065);
|
||||
|
||||
// Every second, sample the pH and output it's corresponding
|
||||
// analog voltage.
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Detected volts: " << sensor->volts() << endl;
|
||||
cout << "pH value: " << sensor->pH() << endl;
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
59
examples/javascript/dfrph.js
Normal file
59
examples/javascript/dfrph.js
Normal file
@ -0,0 +1,59 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
var sensorObj = require('jsupm_dfrph');
|
||||
|
||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
// reference voltage of 5.0
|
||||
var sensor = new sensorObj.DFRPH(0, 5.0);
|
||||
|
||||
|
||||
// After calibration, set the offset (based on calibration with a pH
|
||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||
// calibrations instructions.
|
||||
sensor.setOffset(0.065);
|
||||
|
||||
// Every second, sample the pH and output it's corresponding
|
||||
// analog voltage.
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Detected volts: " + sensor.volts());
|
||||
console.log("pH value: " + sensor.pH());
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
||||
|
56
examples/python/dfrph.py
Normal file
56
examples/python/dfrph.py
Normal file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_dfrph as sensorObj
|
||||
|
||||
# Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
# reference voltage of 5.0
|
||||
sensor = sensorObj.DFRPH(0, 5.0)
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# After calibration, set the offset (based on calibration with a pH
|
||||
# 7.0 buffer solution). See the UPM sensor documentation for
|
||||
# calibrations instructions.
|
||||
sensor.setOffset(0.065);
|
||||
|
||||
# Every second, sample the pH and output it's corresponding
|
||||
# analog voltage.
|
||||
|
||||
while (1):
|
||||
print "Detected volts: ", sensor.volts()
|
||||
print "pH value: ", sensor.pH()
|
||||
time.sleep(1)
|
5
src/dfrph/CMakeLists.txt
Normal file
5
src/dfrph/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "dfrph")
|
||||
set (libdescription "upm dfrobot pH sensors")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
74
src/dfrph/dfrph.cxx
Normal file
74
src/dfrph/dfrph.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "dfrph.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
DFRPH::DFRPH(int pin, float aref) :
|
||||
m_aio(pin)
|
||||
{
|
||||
m_aRes = (1 << m_aio.getBit());
|
||||
m_aref = aref;
|
||||
|
||||
m_offset = 0.0;
|
||||
}
|
||||
|
||||
DFRPH::~DFRPH()
|
||||
{
|
||||
}
|
||||
|
||||
float DFRPH::volts()
|
||||
{
|
||||
int val = m_aio.read();
|
||||
|
||||
return(val * (m_aref / m_aRes));
|
||||
}
|
||||
|
||||
void DFRPH::setOffset(float offset)
|
||||
{
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
float DFRPH::pH(unsigned int samples)
|
||||
{
|
||||
if (!samples)
|
||||
samples = 1;
|
||||
|
||||
float sum = 0.0;
|
||||
|
||||
for (int i=0; i<samples; i++)
|
||||
{
|
||||
sum += volts();
|
||||
usleep(20000);
|
||||
}
|
||||
|
||||
sum /= samples;
|
||||
|
||||
// 3.5 is a 'magic' DFRobot number. Seems to work though :)
|
||||
return (3.5 * sum + m_offset);
|
||||
}
|
142
src/dfrph/dfrph.h
Normal file
142
src/dfrph/dfrph.h
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <mraa/aio.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief DFRobot pH sensors
|
||||
* @defgroup dfrph libupm-dfrph
|
||||
* @ingroup dfrobot liquid analog
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library dfrph
|
||||
* @sensor dfrph
|
||||
* @comname DFRobot pH Sensors
|
||||
* @type liquid
|
||||
* @man dfrobot
|
||||
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=1110
|
||||
* @con analog
|
||||
*
|
||||
* @brief API for the DFRobot pH Sensors
|
||||
*
|
||||
* This sensor family returns an analog voltage proportional to the
|
||||
* acidity or alkalinity of a liquid -- it's pH value.
|
||||
*
|
||||
* This driver was developed using the DFRobot Analog pH meter and
|
||||
* the DFRobot Analog pH Meter Pro.
|
||||
*
|
||||
*
|
||||
* Calibration instructions, taken and slightly reworded from the
|
||||
* DFRobot wiki at:
|
||||
* http://dfrobot.com/wiki/index.php/PH_meter%28SKU:_SEN0161%29
|
||||
*
|
||||
* 1) Connect equipment: the pH electrode is connected to the BNC
|
||||
* connector on the pH meter board, and then the pH meter board is
|
||||
* connected to the analog port 0 of the controller. When the
|
||||
* controller gets power, you will see the blue LED on board is on.
|
||||
*
|
||||
* 2) Put the pH electrode into the standard solution whose pH
|
||||
* value is 7.00. Run the dfrph example and note the pH output
|
||||
* value. Compare the value with 7.00, and calculate the
|
||||
* difference. This is the value you should supply to the
|
||||
* setOffset() method.
|
||||
*
|
||||
* 3) Put the pH electrode into the pH standard solution whose
|
||||
* value is 4.00. Then wait about one minute, and adjust the
|
||||
* potentiometer on the interface board. Let the value stabilise
|
||||
* at around 4.00. At this time,the acidic calibration has been
|
||||
* completed and you can measure the pH value of an acidic
|
||||
* solution.
|
||||
*
|
||||
* 4) According to the linear characteristics of pH electrode
|
||||
* itself, after the above calibration,you can directly measure the
|
||||
* pH value of the alkaline solution. If you want to get better
|
||||
* accuracy, you can recalibrate it. Alkaline calibration use the
|
||||
* standard solution whose pH value is 9.18. Also adjust the
|
||||
* potentiometer and let the value stabilise at around 9.18. After
|
||||
* this calibration, you can measure the pH value of an alkaline
|
||||
* solution.
|
||||
*
|
||||
* @snippet dfrph.cxx Interesting
|
||||
*/
|
||||
|
||||
class DFRPH {
|
||||
public:
|
||||
|
||||
/**
|
||||
* DFRPH constructor
|
||||
*
|
||||
* @param pin Analog pin to use
|
||||
* @param aref Analog reference voltage; default is 5.0 V
|
||||
*/
|
||||
DFRPH(int pin, float aref=5.0);
|
||||
|
||||
/**
|
||||
* DFRPH destructor
|
||||
*/
|
||||
~DFRPH();
|
||||
|
||||
/**
|
||||
* Returns the voltage detected on the analog pin
|
||||
*
|
||||
* @return The detected voltage
|
||||
*/
|
||||
float volts();
|
||||
|
||||
/**
|
||||
* Specifies the offset determined from calibration. The default
|
||||
* is 0.0.
|
||||
*
|
||||
* @param offset The offset value to use
|
||||
*/
|
||||
void setOffset(float offset);
|
||||
|
||||
/**
|
||||
* Take a number of samples and return the detected pH value. The
|
||||
* default number of samples is 15.
|
||||
*
|
||||
* @param samples The number of samples to average over, default 15
|
||||
* @return The pH value detected
|
||||
*/
|
||||
float pH(unsigned int samples=15);
|
||||
|
||||
protected:
|
||||
mraa::Aio m_aio;
|
||||
|
||||
private:
|
||||
float m_aref;
|
||||
// ADC resolution
|
||||
int m_aRes;
|
||||
|
||||
// voltage offset
|
||||
float m_offset;
|
||||
};
|
||||
}
|
||||
|
||||
|
8
src/dfrph/javaupm_dfrph.i
Normal file
8
src/dfrph/javaupm_dfrph.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module javaupm_dfrph
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "dfrph.h"
|
||||
%}
|
||||
|
||||
%include "dfrph.h"
|
8
src/dfrph/jsupm_dfrph.i
Normal file
8
src/dfrph/jsupm_dfrph.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_dfrph
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "dfrph.h"
|
||||
%}
|
||||
|
||||
%include "dfrph.h"
|
9
src/dfrph/pyupm_dfrph.i
Normal file
9
src/dfrph/pyupm_dfrph.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_dfrph
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "dfrph.h"
|
||||
%{
|
||||
#include "dfrph.h"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user