Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 7a1e0eefee3339e1af18a5da3a02e731567fd299 @snatchev committed Dec 5, 2012
Showing with 177 additions and 0 deletions.
  1. +118 −0 Omega_PHH37.cpp
  2. +33 −0 Omega_PHH37.h
  3. 0 README.md
  4. +21 −0 examples/Omega_PHH37_Example/Omega_PHH37_Example.ino
  5. +5 −0 keywords.txt
@@ -0,0 +1,118 @@
+/*
+ * Omega_PHH37
+ * Library for communicating with the Omega PHH37
+ * pH/mV Temperature meter over RS232
+ *
+ * Stefan Natchev - 2013
+ */
+
+
+#include "Arduino.h"
+#include "Omega_PHH37.h"
+
+Omega_PHH37::Omega_PHH37()
+{
+ memset(_input, '\0', 64);
+ memset(_range_code, '\0', 3);
+ memset(_value_1, '\0', 7);
+ memset(_value_2, '\0', 7);
+}
+
+void Omega_PHH37::begin()
+{
+ Serial.begin(9600, SERIAL_8E2);
+ //Serial.print("Omega PHH37");
+}
+
+bool Omega_PHH37::read()
+{
+ char *p = &_input[0];
+ memset(_input, '\0', 64);
+
+ Serial.write("#001N\n");
+ Serial.flush();
+
+ while(Serial.available() > 0 && p != 0) {
+ *p++ = Serial.read();
+ }
+
+ strncpy(_range_code, _input+5, 2);
+ strncpy(_value_1, _input+7, 6);
+ strncpy(_value_2, _input+13, 6);
+
+ return validInput();
+}
+
+float Omega_PHH37::mV()
+{
+ float value = 0.0;
+
+ switch(rangeCode()) {
+ case 0:
+ case 4:
+ case 8:
+ value = atof(_value_1) / 10.0;
+ break;
+ case 1:
+ case 5:
+ case 9:
+ value = atof(_value_1);
+ break;
+ }
+
+ return value;
+}
+
+float Omega_PHH37::temp()
+{
+ return 0.0;
+}
+
+char Omega_PHH37::tempUnits()
+{
+ int rc = rangeCode();
+
+ if(rc > 0 && rc <= 3)
+ return 'C';
+
+ if(rc > 3 && rc <= 11)
+ return 'F';
+
+ return '\0';
+}
+
+float Omega_PHH37::pH()
+{
+ float value = 0.0;
+
+ switch(rangeCode()) {
+ //pH_A
+ case 2:
+ case 6:
+ case 11:
+ //pH_M
+ case 3:
+ case 7:
+ case 10:
+ value = atof(_value_1) / 100.0;
+ break;
+ }
+
+ return value;
+}
+
+int Omega_PHH37::rangeCode()
+{
+ return atoi(_range_code);
+}
+
+bool Omega_PHH37::validInput()
+{
+ //Serial.println(_input);
+ if(strlen(_input) != 21)
+ return false;
+
+ if(strncmp(_input, ">001N", 5) != 0)
+ return false;
+ return true;
+}
@@ -0,0 +1,33 @@
+/*
+ * Omega_PHH37
+ * Library for communicating with the Omega PHH37
+ * pH/mV Temperature meter over RS232
+ *
+ * Stefan Natchev - 2013
+ */
+
+#ifndef Omega_PHH37_h
+#define Omega_PHH37_h
+
+#include "Arduino.h"
+
+class Omega_PHH37
+{
+ public:
+ Omega_PHH37();
+ void begin();
+ bool read();
+ float mV();
+ float temp();
+ char tempUnits();
+ float pH();
+ int rangeCode();
+ private:
+ char _input[64];
+ char _range_code[3];
+ char _value_1[7];
+ char _value_2[7];
+ bool validInput();
+};
+
+#endif
No changes.
@@ -0,0 +1,21 @@
+
+#include <Omega_PHH37.h>
+
+Omega_PHH37 Meter = Omega_PHH37();
+
+void setup()
+{
+ Meter.begin();
+}
+
+void loop()
+{
+ delay(2000);
+ if(Meter.read()) {
+ Serial.print("mV: ");
+ Serial.println(Meter.mV());
+ }
+ else {
+ Serial.println("could not get data");
+ }
+}
@@ -0,0 +1,5 @@
+Omega_PHH37 KEYWORD1
+mV KEYWORD2
+temp KEYWORD2
+pH KEYWORD2
+rangeCode KEYWORD2

0 comments on commit 7a1e0ee

Please sign in to comment.