GY-63_MS5611/libraries/MS5611/MS5611.h

74 lines
1.6 KiB
C
Raw Normal View History

2020-11-27 05:20:37 -05:00
#pragma once
2014-10-19 06:54:35 -04:00
//
// FILE: MS5611.h
// AUTHOR: Rob Tillaart
// Erni - testing/fixes
2021-01-29 06:31:58 -05:00
// VERSION: 0.3.0
2020-11-27 05:20:37 -05:00
// PURPOSE: Arduino library for MS5611 temperature and pressure sensor
// URL: https://github.com/RobTillaart/MS5611
2014-10-19 06:54:35 -04:00
//
// HISTORY:
// see MS5611.cpp file
//
2021-01-29 06:31:58 -05:00
2020-11-27 05:20:37 -05:00
#include "Arduino.h"
#include "Wire.h"
2014-10-19 06:54:35 -04:00
2021-01-29 06:31:58 -05:00
#define MS5611_LIB_VERSION (F("0.3.0"))
#define MS5611_READ_OK 0
#define MS5611_ERROR_2 2 // low level I2C error
#define MS5611_NOT_READ -999
2014-10-19 06:54:35 -04:00
class MS5611
{
public:
2021-01-29 06:31:58 -05:00
explicit MS5611(uint8_t deviceAddress);
#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl, TwoWire *wire = &Wire);
#endif
bool begin(TwoWire *wire = &Wire);
bool isConnected();
2020-11-27 05:20:37 -05:00
2021-01-29 06:31:58 -05:00
// reset command + get constants
void reset();
2020-11-27 05:20:37 -05:00
// the actual reading of the sensor;
// returns MS5611_READ_OK upon success
2021-01-29 06:31:58 -05:00
int read(uint8_t bits = 8);
2020-11-27 05:20:37 -05:00
2021-01-29 06:31:58 -05:00
// temperature is in ²C
float getTemperature() const { return _temperature * 0.01; };
2020-11-27 05:20:37 -05:00
2021-01-29 06:31:58 -05:00
// pressure is in mBar
float getPressure() const { return _pressure * 0.01; };
2020-11-27 05:20:37 -05:00
// to check for failure
2021-01-29 06:31:58 -05:00
int getLastResult() const { return _result; };
2014-10-19 06:54:35 -04:00
2020-11-27 05:20:37 -05:00
// last time in millis() that the sensor has been read.
2021-01-29 06:31:58 -05:00
uint32_t lastRead() { return _lastRead; };
2014-10-19 06:54:35 -04:00
private:
2021-01-29 06:31:58 -05:00
void convert(const uint8_t addr, uint8_t bits);
uint32_t readADC();
uint16_t readProm(uint8_t reg);
int command(const uint8_t command);
uint8_t _address;
int32_t _temperature;
int32_t _pressure;
int _result;
float C[7];
2020-11-27 05:20:37 -05:00
uint32_t _lastRead;
2021-01-29 06:31:58 -05:00
TwoWire * _wire;
2014-10-19 06:54:35 -04:00
};
2020-11-27 05:20:37 -05:00
// -- END OF FILE --