Browse Source

ina132: initial implementation

This module was tested with the Grove Differential Amplifier, with a
weight sensor attached.

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
Zion Orent 10 years ago
parent
commit
925260a234

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

@@ -93,6 +93,7 @@ add_executable (groveelectromagnet-example groveelectromagnet.cxx)
93 93
 add_executable (groveemg-example groveemg.cxx)
94 94
 add_executable (groveo2-example groveo2.cxx)
95 95
 add_executable (grovegsr-example grovegsr.cxx)
96
+add_executable (ina132-example ina132.cxx)
96 97
 
97 98
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
98 99
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -168,6 +169,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/groveelectromagnet)
168 169
 include_directories (${PROJECT_SOURCE_DIR}/src/groveemg)
169 170
 include_directories (${PROJECT_SOURCE_DIR}/src/groveo2)
170 171
 include_directories (${PROJECT_SOURCE_DIR}/src/grovegsr)
172
+include_directories (${PROJECT_SOURCE_DIR}/src/ina132)
171 173
 
172 174
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
173 175
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -262,3 +264,4 @@ target_link_libraries (groveelectromagnet-example groveelectromagnet ${CMAKE_THR
262 264
 target_link_libraries (groveemg-example groveemg ${CMAKE_THREAD_LIBS_INIT})
263 265
 target_link_libraries (groveo2-example groveo2 ${CMAKE_THREAD_LIBS_INIT})
264 266
 target_link_libraries (grovegsr-example grovegsr ${CMAKE_THREAD_LIBS_INIT})
267
+target_link_libraries (ina132-example ina132 ${CMAKE_THREAD_LIBS_INIT})

+ 61
- 0
examples/c++/ina132.cxx View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * Author: Zion Orent <zorent@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
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+#include "ina132.h"
29
+
30
+using namespace std;
31
+
32
+bool shouldRun = true;
33
+
34
+void sig_handler(int signo)
35
+{
36
+  if (signo == SIGINT)
37
+    shouldRun = false;
38
+}
39
+
40
+int main()
41
+{
42
+  signal(SIGINT, sig_handler);
43
+
44
+//! [Interesting]
45
+  // The was tested with the INA132 Differential Amplifier Sensor module.
46
+
47
+  // Instantiate an INA132 on analog pin A0
48
+  upm::INA132 *amplifier = new upm::INA132(0);
49
+
50
+  while (shouldRun)
51
+  {
52
+      cout << amplifier->value() << endl;
53
+      sleep(1);
54
+  }
55
+//! [Interesting]
56
+
57
+  cout << "Exiting" << endl;
58
+
59
+  delete amplifier;
60
+  return 0;
61
+}

+ 54
- 0
examples/javascript/ina132.js View File

@@ -0,0 +1,54 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+/*
4
+* Author: Zion Orent <zorent@ics.com>
5
+* Copyright (c) 2015 Intel Corporation.
6
+*
7
+* Permission is hereby granted, free of charge, to any person obtaining
8
+* a copy of this software and associated documentation files (the
9
+* "Software"), to deal in the Software without restriction, including
10
+* without limitation the rights to use, copy, modify, merge, publish,
11
+* distribute, sublicense, and/or sell copies of the Software, and to
12
+* permit persons to whom the Software is furnished to do so, subject to
13
+* the following conditions:
14
+*
15
+* The above copyright notice and this permission notice shall be
16
+* included in all copies or substantial portions of the Software.
17
+*
18
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+*/
26
+var differential_amplifier_lib = require("jsupm_ina132");
27
+
28
+// The was tested with the INA132 Differential Amplifier Sensor module.
29
+// Instantiate an INA132 on analog pin A0
30
+var differential_amplifier_obj = new differential_amplifier_lib.INA132(0);
31
+
32
+var myInterval = setInterval(function()
33
+{
34
+	console.log(roundNum(differential_amplifier_obj.value(), 5));
35
+}, 1000);
36
+
37
+function roundNum(num, decimalPlaces)
38
+{
39
+	var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
40
+	var numerator = Math.round((num + extraNum) * (Math.pow(10, decimalPlaces)));
41
+	var denominator = Math.pow(10, decimalPlaces);
42
+	return (numerator / denominator);
43
+}
44
+
45
+// When exiting: clear interval, and print message
46
+process.on('SIGINT', function()
47
+{
48
+	clearInterval(myInterval);
49
+	differential_amplifier_obj = null;
50
+	differential_amplifier_lib.cleanUp();
51
+	differential_amplifier_lib = null;
52
+	console.log("Exiting");
53
+	process.exit(0);
54
+});

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

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

+ 60
- 0
src/ina132/ina132.cxx View File

@@ -0,0 +1,60 @@
1
+/*
2
+ * Author: Zion Orent <zorent@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
+
25
+#include <iostream>
26
+#include <unistd.h>
27
+#include "ina132.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+INA132::INA132(int pin)
33
+{
34
+    if ( !(m_aio = mraa_aio_init(pin)) )
35
+    {
36
+      cerr << __FUNCTION__ << ": mraa_aio_init() failed" << endl;
37
+      return;
38
+    }
39
+}
40
+
41
+INA132::~INA132()
42
+{
43
+  mraa_aio_close(m_aio);
44
+}
45
+
46
+float INA132::value()
47
+{
48
+	int val, i;
49
+	float v, vo;
50
+	float sum=0;
51
+	for(i=0;i<10;i++)
52
+	{
53
+		val = mraa_aio_read(m_aio);
54
+		v = val*5.00/1023;
55
+		sum += v;
56
+		usleep(10000);
57
+	}
58
+	vo = sum/10;
59
+	return vo;
60
+}

+ 71
- 0
src/ina132/ina132.h View File

@@ -0,0 +1,71 @@
1
+/*
2
+ * Author: Zion Orent <zorent@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 <string>
27
+#include <mraa/aio.h>
28
+
29
+namespace upm {
30
+  /**
31
+   * @brief UPM module for the INA132 Differential Amplifier Sensor
32
+   * @defgroup ina132 libupm-ina132
33
+   */
34
+  /**
35
+   * @brief C++ API for the INA132 Differential Amplifier Sensor
36
+   * 
37
+   * The INA132 Differential Amplifier Sensor is designed
38
+   * for precise differential-input amplification.
39
+   * 
40
+   * This sensor was tested amplifying the signal
41
+   * from a Weight Sensor (Load Cell)0-500g
42
+   *
43
+   * @ingroup analog ina132
44
+   * @snippet ina132.cxx Interesting
45
+   */
46
+  class INA132 {
47
+  public:
48
+    /**
49
+     * INA132 sensor constructor
50
+     *
51
+     * @param pin analog pin to use
52
+     */
53
+    INA132(int pin);
54
+    /**
55
+     * INA132 Destructor
56
+     */
57
+    ~INA132();
58
+
59
+    /**
60
+     * Measure precise differential-input amplification from the sensor
61
+     *
62
+     * @return precise differential-input amplification
63
+     */
64
+    float value();
65
+
66
+  private:
67
+    mraa_aio_context m_aio;
68
+  };
69
+}
70
+
71
+

+ 8
- 0
src/ina132/jsupm_ina132.i View File

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

+ 9
- 0
src/ina132/pyupm_ina132.i View File

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