|
@@ -0,0 +1,142 @@
|
|
1
|
+/*
|
|
2
|
+ * Author: Jon Trulson <jtrulson@ics.com>
|
|
3
|
+ * Copyright (c) 2015 Intel Corporation.
|
|
4
|
+ *
|
|
5
|
+ * Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+ * a copy of this software and associated documentation files (the
|
|
7
|
+ * "Software"), to deal in the Software without restriction, including
|
|
8
|
+ * without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+ * distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+ * permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+ * the following conditions:
|
|
12
|
+ *
|
|
13
|
+ * The above copyright notice and this permission notice shall be
|
|
14
|
+ * included in all copies or substantial portions of the Software.
|
|
15
|
+ *
|
|
16
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+ */
|
|
24
|
+#pragma once
|
|
25
|
+
|
|
26
|
+#include <iostream>
|
|
27
|
+#include <string>
|
|
28
|
+#include <mraa/aio.hpp>
|
|
29
|
+
|
|
30
|
+namespace upm {
|
|
31
|
+ /**
|
|
32
|
+ * @brief DFRobot pH sensors
|
|
33
|
+ * @defgroup dfrph libupm-dfrph
|
|
34
|
+ * @ingroup dfrobot liquid analog
|
|
35
|
+ */
|
|
36
|
+
|
|
37
|
+ /**
|
|
38
|
+ * @library dfrph
|
|
39
|
+ * @sensor dfrph
|
|
40
|
+ * @comname DFRobot pH Sensors
|
|
41
|
+ * @type liquid
|
|
42
|
+ * @man dfrobot
|
|
43
|
+ * @web http://www.dfrobot.com/index.php?route=product/product&product_id=1110
|
|
44
|
+ * @con analog
|
|
45
|
+ *
|
|
46
|
+ * @brief API for the DFRobot pH Sensors
|
|
47
|
+ *
|
|
48
|
+ * This sensor family returns an analog voltage proportional to the
|
|
49
|
+ * acidity or alkalinity of a liquid -- it's pH value.
|
|
50
|
+ *
|
|
51
|
+ * This driver was developed using the DFRobot Analog pH meter and
|
|
52
|
+ * the DFRobot Analog pH Meter Pro.
|
|
53
|
+ *
|
|
54
|
+ *
|
|
55
|
+ * Calibration instructions, taken and slightly reworded from the
|
|
56
|
+ * DFRobot wiki at:
|
|
57
|
+ * http://dfrobot.com/wiki/index.php/PH_meter%28SKU:_SEN0161%29
|
|
58
|
+ *
|
|
59
|
+ * 1) Connect equipment: the pH electrode is connected to the BNC
|
|
60
|
+ * connector on the pH meter board, and then the pH meter board is
|
|
61
|
+ * connected to the analog port 0 of the controller. When the
|
|
62
|
+ * controller gets power, you will see the blue LED on board is on.
|
|
63
|
+ *
|
|
64
|
+ * 2) Put the pH electrode into the standard solution whose pH
|
|
65
|
+ * value is 7.00. Run the dfrph example and note the pH output
|
|
66
|
+ * value. Compare the value with 7.00, and calculate the
|
|
67
|
+ * difference. This is the value you should supply to the
|
|
68
|
+ * setOffset() method.
|
|
69
|
+ *
|
|
70
|
+ * 3) Put the pH electrode into the pH standard solution whose
|
|
71
|
+ * value is 4.00. Then wait about one minute, and adjust the
|
|
72
|
+ * potentiometer on the interface board. Let the value stabilise
|
|
73
|
+ * at around 4.00. At this time,the acidic calibration has been
|
|
74
|
+ * completed and you can measure the pH value of an acidic
|
|
75
|
+ * solution.
|
|
76
|
+ *
|
|
77
|
+ * 4) According to the linear characteristics of pH electrode
|
|
78
|
+ * itself, after the above calibration,you can directly measure the
|
|
79
|
+ * pH value of the alkaline solution. If you want to get better
|
|
80
|
+ * accuracy, you can recalibrate it. Alkaline calibration use the
|
|
81
|
+ * standard solution whose pH value is 9.18. Also adjust the
|
|
82
|
+ * potentiometer and let the value stabilise at around 9.18. After
|
|
83
|
+ * this calibration, you can measure the pH value of an alkaline
|
|
84
|
+ * solution.
|
|
85
|
+ *
|
|
86
|
+ * @snippet dfrph.cxx Interesting
|
|
87
|
+ */
|
|
88
|
+
|
|
89
|
+ class DFRPH {
|
|
90
|
+ public:
|
|
91
|
+
|
|
92
|
+ /**
|
|
93
|
+ * DFRPH constructor
|
|
94
|
+ *
|
|
95
|
+ * @param pin Analog pin to use
|
|
96
|
+ * @param aref Analog reference voltage; default is 5.0 V
|
|
97
|
+ */
|
|
98
|
+ DFRPH(int pin, float aref=5.0);
|
|
99
|
+
|
|
100
|
+ /**
|
|
101
|
+ * DFRPH destructor
|
|
102
|
+ */
|
|
103
|
+ ~DFRPH();
|
|
104
|
+
|
|
105
|
+ /**
|
|
106
|
+ * Returns the voltage detected on the analog pin
|
|
107
|
+ *
|
|
108
|
+ * @return The detected voltage
|
|
109
|
+ */
|
|
110
|
+ float volts();
|
|
111
|
+
|
|
112
|
+ /**
|
|
113
|
+ * Specifies the offset determined from calibration. The default
|
|
114
|
+ * is 0.0.
|
|
115
|
+ *
|
|
116
|
+ * @param offset The offset value to use
|
|
117
|
+ */
|
|
118
|
+ void setOffset(float offset);
|
|
119
|
+
|
|
120
|
+ /**
|
|
121
|
+ * Take a number of samples and return the detected pH value. The
|
|
122
|
+ * default number of samples is 15.
|
|
123
|
+ *
|
|
124
|
+ * @param samples The number of samples to average over, default 15
|
|
125
|
+ * @return The pH value detected
|
|
126
|
+ */
|
|
127
|
+ float pH(unsigned int samples=15);
|
|
128
|
+
|
|
129
|
+ protected:
|
|
130
|
+ mraa::Aio m_aio;
|
|
131
|
+
|
|
132
|
+ private:
|
|
133
|
+ float m_aref;
|
|
134
|
+ // ADC resolution
|
|
135
|
+ int m_aRes;
|
|
136
|
+
|
|
137
|
+ // voltage offset
|
|
138
|
+ float m_offset;
|
|
139
|
+ };
|
|
140
|
+}
|
|
141
|
+
|
|
142
|
+
|