forked from DFRobot/GravityTDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGravityTDS.h
65 lines (53 loc) · 2.15 KB
/
GravityTDS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/***************************************************
DFRobot Gravity: Analog TDS Sensor/Meter
<https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244>
***************************************************
This sample code shows how to read the tds value and calibrate it with the standard buffer solution.
707ppm(1413us/cm)@25^c standard buffer solution is recommended.
Created 2018-1-3
By Jason <[email protected]@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution.
****************************************************/
#ifndef GRAVITY_TDS_H
#define GRAVITY_TDS_H
#include "Arduino.h"
#define ReceivedBufferLength 15
#define TdsFactor 0.5 // tds = ec / 2
class GravityTDS
{
public:
GravityTDS();
~GravityTDS();
void begin(); //initialization
void update(); //read and calculate
void setPin(int pin);
void setTemperature(float temp); //set the temperature and execute temperature compensation
void setAref(float value); //reference voltage on ADC, default 5.0V on Arduino UNO
void setAdcRange(float range); //1024 for 10bit ADC;4096 for 12bit ADC
void setKvalueAddress(int address); //set the EEPROM address to store the k value,default address:0x08
float getKvalue();
float getTdsValue();
float getEcValue();
float getVoltage();
private:
int pin;
float aref; // default 5.0V on Arduino UNO
float adcRange;
float temperature;
int kValueAddress; //the address of the K value stored in the EEPROM
char cmdReceivedBuffer[ReceivedBufferLength+1]; // store the serial cmd from the serial monitor
byte cmdReceivedBufferIndex;
float kValue; // k value of the probe,you can calibrate in buffer solution ,such as 706.5ppm(1413us/cm)@25^C
float analogValue;
float voltage;
float ecValue; //before temperature compensation
float ecValue25; //after temperature compensation
float tdsValue;
void readKValues();
boolean cmdSerialDataAvailable();
byte cmdParse();
void ecCalibration(byte mode);
};
#endif