0.2.3 I2C_ASDX

This commit is contained in:
rob tillaart 2021-06-06 19:59:53 +02:00
parent 905cc407a7
commit 39d928a98a
6 changed files with 125 additions and 26 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: I2C_ASDX.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: I2C_asdx library for Arduino.
// URL: https://github.com/RobTillaart/I2C_ASDX
//
@ -10,6 +10,7 @@
// 0.2.0 2020-03-18 refactor
// 0.2.1 2020-07-04 add getBar(), getMilliBar(), getPSI()
// 0.2.2 2020-12-29 add arduiino-ci + unit test (minimal), keywords update.
// 0.2.3 2021-06-06 add different units to read pressure
#include "I2C_ASDX.h"
@ -47,7 +48,7 @@ void I2C_ASDX::reset()
_pressure = 0;
}
bool I2C_ASDX::available()
bool I2C_ASDX::isConnected()
{
Wire.beginTransmission(_address);
return (Wire.endTransmission() == 0);

View File

@ -2,7 +2,7 @@
//
// FILE: I2C_ASDX.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: Arduino library for I2C ASDX pressure sensor
// URL: https://github.com/RobTillaart/I2C_ASDX
//
@ -30,35 +30,66 @@
#define PSI2BAR 0.0689475729
#define BAR2PSI 14.503773773
// factors to convert from mBar to different units
// note: different sources give slightly different values
#define MILLIBAR2BAR 0.001
#define MILLIBAR2ATM 9.872e-4
#define MILLIBAR2DYNES 1000
#define MILLIBAR2INHG 2.9539e-2
#define MILLIBAR2INH2O 0.4018
#define MILLIBAR2PASCAL 100
#define MILLIBAR2TORR 0.75028
#define MILLIBAR2CMHG 0.075028
#define MILLIBAR2CMH2O 1.02056
#define MILLIBAR2MSW 100
#define I2C_ASDX_VERSION "0.2.2"
#define I2C_ASDX_VERSION (F("0.2.3"))
#define I2C_ASDX_OK 1
#define I2C_ASDX_INIT 0
#define I2C_ASDX_READ_ERROR -1
#define I2C_ASDX_C000_ERROR -2
class I2C_ASDX
{
public:
// psi: 100, 60, 30, 15
I2C_ASDX(uint8_t address, uint8_t psi);
#if defined (ESP8266) || defined(ESP32)
void begin(uint8_t sda, uint8_t scl);
#endif
void begin();
void reset();
bool available(); // isConnected()
bool isConnected();
bool available() { return isConnected(); }; // obsolete in future
// returns status OK (0) or ERROR ( not 0 )
int read();
// returns the pressure of last succesfull read in mbar
int getPressure() { return round(_pressure); };
float getMilliBar() { return _pressure; };
float getBar() { return _pressure * 1000; };
float getPSI() { return _pressure * MILLIBAR2PSI; };
float getBar() { return _pressure * MILLIBAR2BAR; };
float getPSI() { return _pressure * MILLIBAR2PSI; };
// conversions added 0.2.3
float getATM() { return _pressure * MILLIBAR2ATM; }
float getDynes() { return _pressure * MILLIBAR2DYNES; }
float getInchHg() { return _pressure * MILLIBAR2INHG; }
float getInchH2O() { return _pressure * MILLIBAR2INH2O; }
float getPascal() { return _pressure * MILLIBAR2PASCAL; }
float getTORR() { return _pressure * MILLIBAR2TORR; }
float getCmHg() { return _pressure * MILLIBAR2CMHG; }
float getCmH2O() { return _pressure * MILLIBAR2CMH2O; }
float getMSW() { return _pressure * MILLIBAR2MSW; }
// # errors since last good read
uint16_t errorCount() { return _errorCount; };
@ -67,15 +98,19 @@ public:
// get the last state
int state() { return _state; };
private:
uint8_t _address;
float _maxPressure;
float _pressure;
uint8_t _state;
uint32_t _errorCount;
float _pressure;
uint32_t _lastRead;
};
// Convertors
/*
static float MilliBar2PSI( float mbar ) { return mbar * MILLIBAR2PSI; };

View File

@ -11,30 +11,55 @@ Arduino library for I2C ASDX pressure sensor
## Description
The ASDX sensor of Honeywell exist in many variations.
Check the datasheet for all the details.
Check the datasheet of your type for all the details.
The I2C_ASDX library can read the sensor and give the pressure in millibar, bar or PSI.
The I2C_ASDX library can read the sensor and give the pressure in millibar, bar or PSI or many other units. See below.
The interface consists of the following:
The interface:
- **I2C_ASDX(address, psi)** COnstructor, I2C address and maximum pressure.
- **begin(sda, scl)** I2C parameters for ESP32
- **begin()** for UNO and other boards supporting Wire.
- **reset()** resets internal variables,
- **available()** tests if ASDX sensor is available (just address check)
- **read()** reads the sensor, checks for errors, calculates the pressure and set lastRead
- **getPressure()** retuns an int in milliBar, will return 0 after reset() and no read done.
- **getMilliBar()** returns a float in milliBar
- **getBar()** returns a float in bar
- **getPSI()** returns a float in PSI = Pounds per Square Inch.
- **errorCount()** total counter for
- **lastRead()** time in millis since last succesful reading the sensor
- **state()** last known state of read, also returned by read()
#### Constructor
- **I2C_ASDX(address, psi)** Constructor, I2C address and maximum pressure.
- **void begin(sda, scl)** I2C parameters for ESP32 a.o.
- **void begin()** for UNO and other boards supporting Wire.
- **void reset()** resets internal variables, incl pressure.
- **bool isConnected()** tests if address can be found on I2C bus.
- **bool available()** wrapper around isConnected. Obsolete in the future.
#### Read
Before any call to **getPressure()** one need to call **read()** unless one wants the last value read.
- **int read()** actually reads the sensor, checks for errors, calculates the pressure and set lastRead, Returns **I2C_ASDX_OK** or error code.
#### Units
- **int getPressure()** retuns pressure (integer format) in milliBar, will return 0 after reset() and no read done.
- **float getMilliBar()** returns pressure in milliBar.
- **float getBar()** returns presure in bar.
- **float getPSI()** returns pressure in PSI = Pounds per Square Inch.
- **float getATM()** returns pressure in Atmosphere.
- **float getDynes()** returns pressure in Dynes.
- **float getInchHg()** returns pressure in inches mercury.
- **float getInchH2O()** returns pressure in inches water.
- **float getPascal()** returns pressure in Pascal. Note this is the SI unit.
- **float getTORR()** returns pressure in TORR.
- **float getCmHg()** returns pressure in centimeter mercury.
- **float getCmH2O()** returns pressure in centimeter water.
- **float getMSW()** returns pressure in Meters of Sea Water. (under water pressure unit).
#### State
- **uint16_t errorCount()** total counter for the number of errors occured.
- **uint32_t lastRead()** time in millis of last succesful read of the sensor.
- **int state()** last known state of read, also returned by **read()**
## Testing
The library is tested with only 3 different sensors, all of the PG type.
Code is prepared but not tested for 15, 5 and 1 PSI too.
```
@ -72,6 +97,16 @@ more as long as they have the following raw read values.
TESTED TYPES - type A 10% - 90% only
## Future
#### Must
- multiple Wire interface (breaks interface)
- test isCOnnected in bool begin(). (breaks interface?)
- find a good reference for conversion formula constants.
-
## Operation

View File

@ -1,26 +1,54 @@
# Syntax Coloring Map For I2C_ASDX
# Datatypes (KEYWORD1)
I2C_ASDX KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
reset KEYWORD2
isConnected KEYWORD2
available KEYWORD2
read KEYWORD2
getPressure KEYWORD2
getMilliBar KEYWORD2
getBar KEYWORD2
gePSI KEYWORD2
getATM KEYWORD2
getDynes KEYWORD2
getInchHg KEYWORD2
getInchH2O KEYWORD2
getPascal KEYWORD2
getTORR KEYWORD2
getCmHg KEYWORD2
getCmH2O KEYWORD2
getMSW KEYWORD2
errorCount KEYWORD2
lastRead KEYWORD2
state KEYWORD2
# Constants (LITERAL1)
PSI2MILLIBAR LITERAL1
MILLIBAR2PSI LITERAL1
PSI2BAR LITERAL1
BAR2PSI LITERAL1
MILLIBAR2BAR LITERAL1
MILLIBAR2ATM LITERAL1
MILLIBAR2DYNES LITERAL1
MILLIBAR2INHG LITERAL1
MILLIBAR2INH2O LITERAL1
MILLIBAR2PASCAL LITERAL1
MILLIBAR2TORR LITERAL1
MILLIBAR2CMHG LITERAL1
MILLIBAR2CMH2O LITERAL1
MILLIBAR2MSW LITERAL1
I2C_ASDX_VERSION LITERAL1
I2C_ASDX_OK LITERAL1
I2C_ASDX_INIT LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/I2C_ASDX.git"
},
"version": "0.2.2",
"version": "0.2.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"

View File

@ -1,5 +1,5 @@
name=I2C_ASDX
version=0.2.2
version=0.2.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C ASDX pressure sensor