Browse Source

micsv89: Initial support for MICSV89

Signed off by: Marc Graham <marc@m2ag.net>

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Marc Graham 9 years ago
parent
commit
bf856c5fca

BIN
docs/images/micsv89.jpg View File


+ 3
- 0
examples/c++/CMakeLists.txt View File

@@ -146,6 +146,7 @@ add_executable (wheelencoder-example wheelencoder.cxx)
146 146
 add_executable (sm130-example sm130.cxx)
147 147
 add_executable (grovegprs-example grovegprs.cxx)
148 148
 add_executable (lm35-example lm35.cxx)
149
+add_executable (micsv89-example micsv89.cxx)
149 150
 
150 151
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
151 152
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -257,6 +258,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/wheelencoder)
257 258
 include_directories (${PROJECT_SOURCE_DIR}/src/sm130)
258 259
 include_directories (${PROJECT_SOURCE_DIR}/src/grovegprs)
259 260
 include_directories (${PROJECT_SOURCE_DIR}/src/lm35)
261
+include_directories (${PROJECT_SOURCE_DIR}/src/micsv89)
260 262
 
261 263
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
262 264
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -404,3 +406,4 @@ target_link_libraries (wheelencoder-example wheelencoder ${CMAKE_THREAD_LIBS_INI
404 406
 target_link_libraries (sm130-example sm130 ${CMAKE_THREAD_LIBS_INIT})
405 407
 target_link_libraries (grovegprs-example grovegprs ${CMAKE_THREAD_LIBS_INIT})
406 408
 target_link_libraries (lm35-example lm35 ${CMAKE_THREAD_LIBS_INIT})
409
+target_link_libraries (micsv89-example micsv89 ${CMAKE_THREAD_LIBS_INIT})

+ 78
- 0
examples/c++/micsv89.cxx View File

@@ -0,0 +1,78 @@
1
+/*
2
+ * Author: Marc Graham <marc@m2ag.net>
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
+
25
+#include "mraa.hpp"
26
+
27
+
28
+#include <iostream>
29
+#include <unistd.h>
30
+#include "micsv89.h"
31
+
32
+
33
+
34
+/*
35
+ * An example for using the MICSV89 sensor library.
36
+ * The MICSV89 comes in 4 variants, PWM and I2c
37
+ * in 3.3 volts and 5 volts. This library only implements
38
+ * the I2c version of the device.
39
+ *
40
+ * Device output is not valid until a warm up of 15 minutes
41
+ * of operation.
42
+ *
43
+ * Additional linker flags: none
44
+ */
45
+
46
+using namespace std;
47
+
48
+upm::MICSV89 *sensor = NULL;
49
+
50
+
51
+int main()
52
+{
53
+
54
+
55
+	sensor = new upm::MICSV89(6);
56
+
57
+
58
+
59
+	while(true)
60
+	{
61
+		sensor->start();
62
+		while(!sensor->valid());
63
+		cout << "co2: " << sensor->co2equ() << endl;
64
+		cout << "short: " << sensor->vocshort() << endl;
65
+		cout << "tvoc: " << sensor->tvoc() << endl;
66
+		cout << "resistor: " << sensor->resistor() << endl;
67
+		cout << "****************************" << endl;
68
+		sleep(5);
69
+
70
+	}
71
+
72
+
73
+
74
+	delete sensor;
75
+
76
+
77
+	return MRAA_SUCCESS;
78
+}

+ 26
- 0
examples/javascript/micsv89.js View File

@@ -0,0 +1,26 @@
1
+// Drive the Grive RGB LCD (a JHD1313m1)
2
+//
3
+// The way to drive the LCD directly from
4
+// Javascript code using the i2c interface directly
5
+// This approach is useful for learning about using
6
+// the i2c bus. The i2c file is an implementation
7
+// in Javascript for some of the common LCD functions
8
+
9
+// configure jshint
10
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
11
+/*jshint unused:true */
12
+
13
+var upmMICSV89 = require("jsupm_micsv89"); 
14
+
15
+var mics = new upmMICSV89.MICSV89(6); 
16
+
17
+while(1)
18
+{
19
+    mics.start(); 
20
+    while(!mics.valid());
21
+    console.log("co2: " + mics.co2equ()); 
22
+    console.log("short: " + mics.vocshort()); 
23
+    console.log("tvoc: " + mics.tvoc());   
24
+    console.log("resistor: " + mics.resistor()); 
25
+    console.log("***********************");
26
+}

+ 5
- 0
src/micsv89/CMakeLists.txt View File

@@ -0,0 +1,5 @@
1
+set (libname "micsv89")
2
+set (libdescription "upm micsv89 environmental sensor module")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 8
- 0
src/micsv89/javaupm_micsv89.i View File

@@ -0,0 +1,8 @@
1
+%module javaupm_micsv89
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "micsv89.h"
6
+%}
7
+
8
+%include "micsv89.h"

+ 8
- 0
src/micsv89/jsupm_micsv89.i View File

@@ -0,0 +1,8 @@
1
+%module jsupm_micsv89
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "micsv89.h"
6
+%}
7
+
8
+%include "micsv89.h"

+ 80
- 0
src/micsv89/micsv89.cxx View File

@@ -0,0 +1,80 @@
1
+/*
2
+ * Author: Marc Graham <marc@m2ag.net>
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
+
25
+
26
+
27
+#include "micsv89.h"
28
+
29
+
30
+using namespace upm;
31
+
32
+MICSV89::MICSV89 (int bus, uint8_t address) {
33
+	m_name = "micsv89";
34
+	m_valid = false;
35
+	m_address = address;
36
+	i2c = new mraa::I2c(bus);
37
+	tx_buf[0] = 0x09;
38
+	tx_buf[1] = 0x00;
39
+	tx_buf[2] = 0x00;
40
+}
41
+
42
+
43
+void MICSV89::start()
44
+{
45
+	m_valid = false;
46
+	i2c->address(m_address);
47
+	i2c->frequency(MRAA_I2C_STD);
48
+	i2c->write(tx_buf, 3);
49
+	sleep(1); //Give the device time to make the measurement.
50
+	i2c->address(m_address);
51
+	i2c->frequency(MRAA_I2C_STD);
52
+	i2c->read(rx_buf, 6);
53
+	m_valid = true;
54
+}
55
+
56
+float MICSV89::co2equ()
57
+{
58
+	return ((rx_buf[0] - 13) * (1600/229) + 400);
59
+}
60
+
61
+int MICSV89::vocshort()
62
+{
63
+	return rx_buf[1];
64
+}
65
+
66
+float MICSV89::tvoc()
67
+{
68
+	return rx_buf[2] * (1000/229);
69
+}
70
+
71
+float MICSV89::resistor()
72
+{
73
+	return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
74
+}
75
+
76
+MICSV89::~MICSV89 () {
77
+	delete i2c;
78
+}
79
+
80
+

+ 133
- 0
src/micsv89/micsv89.h View File

@@ -0,0 +1,133 @@
1
+/*
2
+ * Author: Marc Graham <marc@m2ag.net>
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
+
25
+
26
+
27
+#pragma once
28
+
29
+#include <iostream>
30
+#include <string>
31
+#include "mraa.hpp"
32
+#include "mraa/i2c.hpp"
33
+
34
+
35
+
36
+namespace upm {
37
+  /**
38
+   * @library gas
39
+   * @sensor  MICS-V89
40
+   * @comname MICS-V89
41
+   * @type Environmental. VOC and CO2
42
+   * @man http://sgx.cdistore.com/datasheets/e2v/MiCS-VZ-86%20and%20VZ-89%20rev%204.pdf
43
+   * @man http://www.sgxsensortech.com/content/uploads/2015/01/MICS-VZ-89-I2C-specs-rev-A.pdf
44
+   * @con i2c
45
+   *
46
+   * @brief API for the MICS-VZ89 Gas Sensor
47
+   * The MiCS-VZ-86/89 combines state-of-the-art MOS
48
+   * sensor technology with intelligent detection algorithms
49
+   * to monitor VOCs and CO2 equivalent variations in
50
+   * confined spaces.
51
+   *
52
+   * The MICSV89 comes in 4 variants, PWM and I2c
53
+   * in 3.3 volts and 5 volts. This library only implements
54
+   * the I2c version of the device.
55
+   *
56
+   * Device output is not valid until a warm up of 15 minutes
57
+   * of operation.
58
+   *
59
+   *
60
+   * @image html micsv89.jpg 
61
+   * @snippet micsv89.cxx Interesting
62
+   */
63
+    class MICSV89 {
64
+        public:
65
+            /**
66
+             * MICSV89 constructor
67
+             *
68
+             * @param bus i2c bus the sensor is attached to.
69
+             * @param address. Device address. Default is 0x70.
70
+             */
71
+            MICSV89 (int bus, uint8_t address = 0x70);
72
+
73
+            /**
74
+             * MICSV89 destructor
75
+             */
76
+            ~MICSV89 ();
77
+
78
+            /**
79
+             * Returns the name of the sensor
80
+             */
81
+            std::string name()
82
+            {
83
+                return m_name;
84
+            }
85
+
86
+            /**
87
+             *	Returns the  CO2 equivalent value.
88
+             */
89
+            float co2equ();
90
+
91
+            /**
92
+             * Returns VOC Short value.
93
+             */
94
+            int vocshort();
95
+
96
+            /**
97
+             * Returns Total VOC.
98
+             */
99
+            float tvoc();
100
+
101
+            /**
102
+             * Returns resistor value.
103
+             */
104
+            float resistor();
105
+
106
+            /**
107
+             * Performs a write/read cycle.
108
+             */
109
+            void start();
110
+
111
+            /**
112
+             * Returns true if a valid write/read cycle has been completed.
113
+             * At startup and during write/read cycle will be false.
114
+             */
115
+            bool valid()
116
+            {
117
+            	return m_valid;
118
+            }
119
+
120
+
121
+
122
+
123
+        private:
124
+            std::string m_name;
125
+            bool m_valid;
126
+            uint8_t m_address;
127
+            uint8_t rx_buf[6];
128
+           	uint8_t tx_buf[3];
129
+           	mraa::I2c* i2c;
130
+
131
+
132
+    };
133
+}

+ 9
- 0
src/micsv89/pyupm_micsv89.i View File

@@ -0,0 +1,9 @@
1
+%module pyupm_micsv89
2
+%include "../upm.i"
3
+
4
+%feature("autodoc", "3");
5
+
6
+%include "micsv89.h"
7
+%{
8
+    #include "micsv89.h"
9
+%}

BIN
src/mlx90614/.DS_Store View File