Browse Source

ad8232: Initial Implementation

This driver implements support for the Sparkfun Single Lead Heart Rate
Monitor, based on the AD8232 chip.

It simply outputs ADC data that needs to be sent somewhere for
plotting.  The Sparkfun page has some suggestions.

Alternatively, if you have an oscilliscope that supports a 'Roll'
mode, you can get an EKG-like display by measuring the OUT pin.

https://www.sparkfun.com/products/12650

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Jon Trulson 9 years ago
parent
commit
517f6c1e88

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

@@ -120,6 +120,7 @@ add_executable (maxsonarez-example maxsonarez.cxx)
120 120
 add_executable (hm11-example hm11.cxx)
121 121
 add_executable (ht9170-example ht9170.cxx)
122 122
 add_executable (h3lis331dl-example h3lis331dl.cxx)
123
+add_executable (ad8232-example ad8232.cxx)
123 124
 
124 125
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
125 126
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -218,6 +219,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/maxsonarez)
218 219
 include_directories (${PROJECT_SOURCE_DIR}/src/hm11)
219 220
 include_directories (${PROJECT_SOURCE_DIR}/src/ht9170)
220 221
 include_directories (${PROJECT_SOURCE_DIR}/src/h3lis331dl)
222
+include_directories (${PROJECT_SOURCE_DIR}/src/ad8232)
221 223
 
222 224
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
223 225
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -339,3 +341,4 @@ target_link_libraries (maxsonarez-example maxsonarez ${CMAKE_THREAD_LIBS_INIT})
339 341
 target_link_libraries (hm11-example hm11 ${CMAKE_THREAD_LIBS_INIT})
340 342
 target_link_libraries (ht9170-example ht9170 ${CMAKE_THREAD_LIBS_INIT})
341 343
 target_link_libraries (h3lis331dl-example h3lis331dl ${CMAKE_THREAD_LIBS_INIT})
344
+target_link_libraries (ad8232-example ad8232 ${CMAKE_THREAD_LIBS_INIT})

+ 65
- 0
examples/c++/ad8232.cxx View File

@@ -0,0 +1,65 @@
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
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+#include "ad8232.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
+  // Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
46
+  // and an analog pin, 0 (OUTPUT)
47
+  upm::AD8232 *ad8232 = new upm::AD8232(10, 11, 0);
48
+  
49
+  // Output the raw numbers from the ADC, for plotting elsewhere.
50
+  // A return of 0 indicates a Lead Off (LO) condition.
51
+  // In theory, this data could be fed to software like Processing 
52
+  // (https://www.processing.org/) to plot the data just like an 
53
+  // EKG you would see in a hospital.
54
+  while (shouldRun)
55
+    {
56
+      cout << ad8232->value() << endl;      
57
+      usleep(1000);
58
+    }
59
+//! [Interesting]
60
+
61
+  cout << "Exiting" << endl;
62
+
63
+  delete ad8232;
64
+  return 0;
65
+}

+ 51
- 0
examples/javascript/ad8232.js View File

@@ -0,0 +1,51 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+/*
4
+* Author: Jon Trulson <jtrulson@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 ad8232Sensor_lib = require('jsupm_ad8232');
27
+
28
+// Instantiate a AD8232 sensor on digital pins 10 (LO+), 11 (LO-)
29
+// and an analog pin, 0 (OUTPUT)
30
+var myAd8232Sensor_obj = new ad8232Sensor_lib.AD8232(10, 11, 0);
31
+
32
+// Output the raw numbers from the ADC, for plotting elsewhere.
33
+// A return of 0 indicates a Lead Off (LO) condition.
34
+// In theory, this data could be fed to software like Processing 
35
+// (https://www.processing.org/) to plot the data just like an 
36
+// EKG you would see in a hospital.
37
+var myInterval = setInterval(function()
38
+{
39
+	console.log(myAd8232Sensor_obj.value());
40
+}, 1);
41
+
42
+// Print message when exiting
43
+process.on('SIGINT', function()
44
+{
45
+	clearInterval(myInterval);
46
+	myAd8232Sensor_obj = null;
47
+	ad8232Sensor_lib.cleanUp();
48
+	ad8232Sensor_lib = null;
49
+	console.log("Exiting");
50
+	process.exit(0);
51
+});

+ 54
- 0
examples/python/ad8232.py View File

@@ -0,0 +1,54 @@
1
+#!/usr/bin/python
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
+import time, sys, signal, atexit
25
+import pyupm_ad8232 as upmAD8232
26
+
27
+# Instantiate a AD8232 sensor on digital pins 10 (LO+), 11 (LO-)
28
+# and an analog pin, 0 (OUTPUT)
29
+myAD8232 = upmAD8232.AD8232(10, 11, 0)
30
+
31
+
32
+## Exit handlers ##
33
+# This function stops python from printing a stacktrace when you hit control-C
34
+def SIGINTHandler(signum, frame):
35
+	raise SystemExit
36
+
37
+# This function lets you run code on exit, including functions from myAD8232
38
+def exitHandler():
39
+	print "Exiting"
40
+	sys.exit(0)
41
+
42
+# Register exit handlers
43
+atexit.register(exitHandler)
44
+signal.signal(signal.SIGINT, SIGINTHandler)
45
+
46
+
47
+# Output the raw numbers from the ADC, for plotting elsewhere.
48
+# A return of 0 indicates a Lead Off (LO) condition.
49
+# In theory, this data could be fed to software like Processing 
50
+# (https://www.processing.org/) to plot the data just like an 
51
+# EKG you would see in a hospital.
52
+while(1):
53
+	print myAD8232.value()
54
+	time.sleep(.001)

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

@@ -0,0 +1,5 @@
1
+set (libname "ad8232")
2
+set (libdescription "upm ad8232 heart rate monitor")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 52
- 0
src/ad8232/ad8232.cxx View File

@@ -0,0 +1,52 @@
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
+
25
+#include <iostream>
26
+
27
+#include "ad8232.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+AD8232::AD8232(int loPlus, int loMinus, int output, float aref) :
33
+  m_gpioLOPlus(loPlus), m_gpioLOMinus(loMinus), m_aioOUT(output)
34
+{
35
+  m_gpioLOPlus.dir(mraa::DIR_IN);
36
+  m_gpioLOMinus.dir(mraa::DIR_IN);
37
+  
38
+  m_aref = aref;
39
+  m_ares = (1 << m_aioOUT.getBit());
40
+}
41
+
42
+AD8232::~AD8232()
43
+{
44
+}
45
+
46
+int AD8232::value()
47
+{
48
+  if (m_gpioLOPlus.read() || m_gpioLOMinus.read())
49
+    return 0;
50
+  else
51
+    return m_aioOUT.read();
52
+}

+ 104
- 0
src/ad8232/ad8232.h View File

@@ -0,0 +1,104 @@
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 <stdint.h>
27
+#include <sys/time.h>
28
+
29
+#include <mraa/gpio.hpp>
30
+#include <mraa/aio.hpp>
31
+
32
+#define AD8232_DEFAULT_AREF  3.3
33
+
34
+namespace upm {
35
+
36
+  /**
37
+   * @brief UPM support for the AD8232 Heart Rate Monitor
38
+   * @defgroup ad8232 libupm-ad8232
39
+   * @ingroup sparkfun gpio medical
40
+   */
41
+
42
+  /**
43
+   * @library ad8232
44
+   * @sensor ad8232
45
+   * @comname AD8232 Heart Rate Monitor
46
+   * @type medical
47
+   * @man sparkfun
48
+   * @web https://www.sparkfun.com/products/12650
49
+   * @con gpio aio
50
+   *
51
+   * @brief UPM module for the AD8232 Heart Rate Monitor
52
+   *
53
+   * Note, this sensor must be driven at 3.3v only.
54
+   *
55
+   * This module will simply spit out the ADC values reported by the
56
+   * sensor, with the intent being to send that data somewhere (via
57
+   * serial or network port) to another piece of software running on a
58
+   * computer that will plot the data for you, like an EKG.
59
+   * 
60
+   * Processing (https://www.processing.org/), is a piece of software
61
+   * that should work, using information from the Sparkfun website.
62
+   *
63
+   * This example just dumps the raw data.
64
+   * @snippet ad8232.cxx Interesting
65
+   */
66
+
67
+
68
+  class AD8232 {
69
+  public:
70
+
71
+    /**
72
+     * AD8232 constructor
73
+     *
74
+     * @param loPlus digital pin to use for LO+
75
+     * @param loMinus digital pin to use LO-
76
+     * @param output analog pin to use for reading the data
77
+     */
78
+    AD8232(int loPlus, int loMinus, int output, float aref=AD8232_DEFAULT_AREF);
79
+
80
+    /**
81
+     * AD8232 Destructor
82
+     */
83
+    ~AD8232();
84
+
85
+    /**
86
+     * return the current ADC value for the device output pin.  If an
87
+     * LO (Leads Off) event is detected, 0 will be returned.
88
+     *
89
+     * @return ADC value
90
+     */
91
+    int value();
92
+
93
+  private:
94
+    mraa::Aio m_aioOUT;
95
+    mraa::Gpio m_gpioLOPlus;
96
+    mraa::Gpio m_gpioLOMinus;
97
+
98
+    float m_aref;
99
+    int m_ares;
100
+
101
+  };
102
+}
103
+
104
+

+ 8
- 0
src/ad8232/jsupm_ad8232.i View File

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

+ 9
- 0
src/ad8232/pyupm_ad8232.i View File

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