alpahsense
Dependents: Example_DS3231_test
Revision 0:ed1f58bf0dc3, committed 2019-03-06
- Comitter:
- etiene32
- Date:
- Wed Mar 06 14:01:39 2019 +0000
- Commit message:
- sd
Changed in this revision
| Alphasense.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Alphasense.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Alphasense.cpp Wed Mar 06 14:01:39 2019 +0000
@@ -0,0 +1,35 @@
+#include "Alphasense.h"
+#include "Adafruit_ADS1015.h"
+
+ALPHASENSE::ALPHASENSE(I2C* i2c, int num_chan_op1, int num_chan_op2, int we0, int ae0, int sensitivity, int n_sample) : _i2c(i2c), _num_chan_op1(num_chan_op1), _num_chan_op2(num_chan_op2), _we0(we0), _ae0(ae0), _sensitivity(sensitivity), _n_sample(n_sample) {
+}
+
+float ALPHASENSE::measure() {
+ double we_result, ae_result;
+ float result;
+ int we, ae, we_integral, ae_integral;
+
+ Adafruit_ADS1115 ads(_i2c); //init ads1115
+ ads.setGain(GAIN_TWO); //set range to 2.048 V
+
+ for (int i=0; i<_n_sample; i++)
+ {
+ we = ads.readADC_SingleEnded(_num_chan_op1); // read channel
+ ae = ads.readADC_SingleEnded(_num_chan_op2);
+ we_integral += we;
+ ae_integral += ae;
+ }
+
+ we_result = we_integral / _n_sample; //smoothing result
+ ae_result = ae_integral / _n_sample;
+
+ we_result = we_result * 0.0625; //conversion to mV (2048 / 65536)
+ ae_result = ae_result * 0.0625;
+
+ we_integral = 0; //reset integral
+ ae_integral = 0;
+
+ result = (((we_result - _we0) - (ae_result - _ae0)) / _sensitivity) * 1000; //conversion to ppb
+
+ return result;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Alphasense.h Wed Mar 06 14:01:39 2019 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+
+class ALPHASENSE {
+ public:
+ ALPHASENSE(I2C* i2c, int num_chan_op1, int num_chan_op2, int we0, int ae0, int sensitivity, int n_sample);
+ float measure();
+
+ protected:
+ I2C* _i2c;
+
+ private:
+ int _num_chan_op1;
+ int _num_chan_op2;
+ int _we0;
+ int _ae0;
+ int _sensitivity;
+ int _n_sample;
+};
\ No newline at end of file