mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 MS5611_SPI
This commit is contained in:
parent
5bdf8fd9c5
commit
bec3364ed5
11
libraries/MS5611_SPI/.arduino-ci.yml
Normal file
11
libraries/MS5611_SPI/.arduino-ci.yml
Normal file
@ -0,0 +1,11 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
13
libraries/MS5611_SPI/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/MS5611_SPI/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/MS5611_SPI/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/MS5611_SPI/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/MS5611_SPI/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/MS5611_SPI/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
21
libraries/MS5611_SPI/LICENSE
Normal file
21
libraries/MS5611_SPI/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
373
libraries/MS5611_SPI/MS5611_SPI.cpp
Normal file
373
libraries/MS5611_SPI/MS5611_SPI.cpp
Normal file
@ -0,0 +1,373 @@
|
||||
//
|
||||
// FILE: MS5611_SPI.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: MS5611 (SPI) Temperature & Humidity library for Arduino
|
||||
// URL: https://github.com/RobTillaart/MS5611
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2022-01-18 initial version by Rob Tillaart (15-okt-2014)
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
|
||||
// datasheet page 10
|
||||
#define MS5611_CMD_READ_ADC 0x00
|
||||
#define MS5611_CMD_READ_PROM 0xA0
|
||||
#define MS5611_CMD_RESET 0x1E
|
||||
#define MS5611_CMD_CONVERT_D1 0x40
|
||||
#define MS5611_CMD_CONVERT_D2 0x50
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
MS5611_SPI::MS5611_SPI(uint8_t select, uint8_t dataOut, uint8_t dataIn, uint8_t clock)
|
||||
{
|
||||
// _address = deviceAddress; // TODO
|
||||
_samplingRate = OSR_ULTRA_LOW;
|
||||
_temperature = MS5611_NOT_READ;
|
||||
_pressure = MS5611_NOT_READ;
|
||||
_result = MS5611_NOT_READ;
|
||||
_lastRead = 0;
|
||||
_deviceID = 0;
|
||||
_pressureOffset = 0;
|
||||
_temperatureOffset = 0;
|
||||
_compensation = true;
|
||||
|
||||
// SPI
|
||||
_select = select;
|
||||
_dataIn = dataIn;
|
||||
_dataOut = dataOut;
|
||||
_clock = clock;
|
||||
_hwSPI = (dataIn == 255) && (dataOut == 255) && (clock == 255);
|
||||
}
|
||||
|
||||
|
||||
bool MS5611_SPI::begin()
|
||||
{
|
||||
// print experimental message.
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
pinMode(_select, OUTPUT);
|
||||
digitalWrite(_select, HIGH);
|
||||
|
||||
setSPIspeed(_SPIspeed);
|
||||
|
||||
if(_hwSPI)
|
||||
{
|
||||
#if defined(ESP32)
|
||||
if (_useHSPI) // HSPI
|
||||
{
|
||||
mySPI = new SPIClass(HSPI);
|
||||
mySPI->end();
|
||||
mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13
|
||||
}
|
||||
else // VSPI
|
||||
{
|
||||
mySPI = new SPIClass(VSPI);
|
||||
mySPI->end();
|
||||
mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23
|
||||
}
|
||||
#else // generic hardware SPI
|
||||
Serial.println("HW_SPI");
|
||||
mySPI = &SPI;
|
||||
mySPI->end();
|
||||
mySPI->begin();
|
||||
#endif
|
||||
delay(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("SW_SPI");
|
||||
pinMode(_dataIn, INPUT);
|
||||
pinMode(_dataOut, OUTPUT);
|
||||
pinMode(_clock, OUTPUT);
|
||||
digitalWrite(_dataOut, LOW);
|
||||
digitalWrite(_clock, LOW);
|
||||
}
|
||||
|
||||
return reset();
|
||||
}
|
||||
|
||||
|
||||
bool MS5611_SPI::reset()
|
||||
{
|
||||
command(MS5611_CMD_RESET);
|
||||
uint32_t start = micros();
|
||||
// while loop prevents blocking RTOS
|
||||
while (micros() - start < 3000) // increased as first ROM values were missed.
|
||||
{
|
||||
yield();
|
||||
delayMicroseconds(10);
|
||||
}
|
||||
// constants that were multiplied in read()
|
||||
// do this once and you save CPU cycles
|
||||
C[0] = 1;
|
||||
C[1] = 32768L; // SENSt1 = C[1] * 2^15
|
||||
C[2] = 65536L; // OFFt1 = C[2] * 2^16
|
||||
C[3] = 3.90625E-3; // TCS = C[3] / 2^6
|
||||
C[4] = 7.8125E-3; // TCO = C[4] / 2^7
|
||||
C[5] = 256; // Tref = C[5] * 2^8
|
||||
C[6] = 1.1920928955E-7; // TEMPSENS = C[6] / 2^23
|
||||
// read factory calibrations from EEPROM.
|
||||
bool ROM_OK = true;
|
||||
for (uint8_t reg = 0; reg < 7; reg++)
|
||||
{
|
||||
// used indices match datasheet.
|
||||
// C[0] == manufacturer - read but not used;
|
||||
// C[7] == CRC - skipped.
|
||||
uint16_t tmp = readProm(reg);
|
||||
C[reg] *= tmp;
|
||||
// _deviceID is a simple SHIFT XOR merge of PROM data
|
||||
_deviceID <<= 4;
|
||||
_deviceID ^= tmp;
|
||||
// Serial.println(readProm(reg));
|
||||
if (reg > 0)
|
||||
{
|
||||
ROM_OK = ROM_OK && (tmp != 0);
|
||||
}
|
||||
}
|
||||
return ROM_OK;
|
||||
}
|
||||
|
||||
|
||||
int MS5611_SPI::read(uint8_t bits)
|
||||
{
|
||||
// VARIABLES NAMES BASED ON DATASHEET
|
||||
// ALL MAGIC NUMBERS ARE FROM DATASHEET
|
||||
convert(MS5611_CMD_CONVERT_D1, bits);
|
||||
// NOTE: D1 and D2 seem reserved in MBED (NANO BLE)
|
||||
uint32_t _D1 = readADC();
|
||||
convert(MS5611_CMD_CONVERT_D2, bits);
|
||||
uint32_t _D2 = readADC();
|
||||
|
||||
// Serial.println(_D1);
|
||||
// Serial.println(_D2);
|
||||
|
||||
// TEST VALUES - comment lines above
|
||||
// uint32_t _D1 = 9085466;
|
||||
// uint32_t _D2 = 8569150;
|
||||
|
||||
// TEMP & PRESS MATH - PAGE 7/20
|
||||
float dT = _D2 - C[5];
|
||||
_temperature = 2000 + dT * C[6];
|
||||
|
||||
float offset = C[2] + dT * C[4];
|
||||
float sens = C[1] + dT * C[3];
|
||||
|
||||
if (_compensation)
|
||||
{
|
||||
// SECOND ORDER COMPENSATION - PAGE 8/20
|
||||
// COMMENT OUT < 2000 CORRECTION IF NOT NEEDED
|
||||
// NOTE TEMPERATURE IS IN 0.01 C
|
||||
if (_compensation && _temperature < 2000)
|
||||
{
|
||||
float T2 = dT * dT * 4.6566128731E-10;
|
||||
float t = (_temperature - 2000) * (_temperature - 2000);
|
||||
float offset2 = 2.5 * t;
|
||||
float sens2 = 1.25 * t;
|
||||
// COMMENT OUT < -1500 CORRECTION IF NOT NEEDED
|
||||
if (_temperature < -1500)
|
||||
{
|
||||
t = (_temperature + 1500) * (_temperature + 1500);
|
||||
offset2 += 7 * t;
|
||||
sens2 += 5.5 * t;
|
||||
}
|
||||
_temperature -= T2;
|
||||
offset -= offset2;
|
||||
sens -= sens2;
|
||||
}
|
||||
// END SECOND ORDER COMPENSATION
|
||||
}
|
||||
|
||||
_pressure = (_D1 * sens * 4.76837158205E-7 - offset) * 3.051757813E-5;
|
||||
|
||||
_lastRead = millis();
|
||||
return MS5611_READ_OK;
|
||||
}
|
||||
|
||||
|
||||
void MS5611_SPI::setOversampling(osr_t samplingRate)
|
||||
{
|
||||
_samplingRate = (uint8_t) samplingRate;
|
||||
}
|
||||
|
||||
|
||||
float MS5611_SPI::getTemperature() const
|
||||
{
|
||||
if (_temperatureOffset == 0) return _temperature * 0.01;
|
||||
return _temperature * 0.01 + _temperatureOffset;
|
||||
};
|
||||
|
||||
|
||||
float MS5611_SPI::getPressure() const
|
||||
{
|
||||
if (_pressureOffset == 0) return _pressure * 0.01;
|
||||
return _pressure * 0.01 + _pressureOffset;
|
||||
};
|
||||
|
||||
|
||||
void MS5611_SPI::setSPIspeed(uint32_t speed)
|
||||
{
|
||||
_SPIspeed = speed;
|
||||
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
|
||||
};
|
||||
|
||||
|
||||
#if defined(ESP32)
|
||||
void MS5611_SPI::setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select)
|
||||
{
|
||||
_clock = clk;
|
||||
_dataIn = miso;
|
||||
_dataOut = mosi;
|
||||
_select = select;
|
||||
pinMode(_clock, OUTPUT);
|
||||
pinMode(_dataIn, INPUT);
|
||||
pinMode(_dataOut, OUTPUT);
|
||||
pinMode(_select, OUTPUT);
|
||||
digitalWrite(_clock, HIGH);
|
||||
digitalWrite(_dataOut, LOW);
|
||||
digitalWrite(_select, HIGH);
|
||||
|
||||
mySPI->end(); // disable SPI and restart
|
||||
mySPI->begin(clk, miso, mosi, select);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
void MS5611_SPI::convert(const uint8_t addr, uint8_t bits)
|
||||
{
|
||||
// values from page 3 datasheet - MAX column (rounded up)
|
||||
uint16_t del[5] = {600, 1200, 2300, 4600, 9100};
|
||||
|
||||
uint8_t index = bits;
|
||||
if (index < 8) index = 8;
|
||||
else if (index > 12) index = 12;
|
||||
index -= 8;
|
||||
uint8_t offset = index * 2;
|
||||
command(addr + offset);
|
||||
|
||||
uint16_t waitTime = del[index];
|
||||
uint32_t start = micros();
|
||||
// while loop prevents blocking RTOS
|
||||
while (micros() - start < waitTime)
|
||||
{
|
||||
yield();
|
||||
delayMicroseconds(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t MS5611_SPI::readProm(uint8_t reg)
|
||||
{
|
||||
// last EEPROM register is CRC - Page 13 datasheet.
|
||||
uint8_t promCRCRegister = 7;
|
||||
if (reg > promCRCRegister) return 0;
|
||||
|
||||
uint16_t value = 0;
|
||||
digitalWrite(_select, LOW);
|
||||
if (_hwSPI)
|
||||
{
|
||||
mySPI->beginTransaction(_spi_settings);
|
||||
mySPI->transfer(MS5611_CMD_READ_PROM + reg * 2);
|
||||
value += mySPI->transfer(0x00);
|
||||
value <<= 8;
|
||||
value += mySPI->transfer(0x00);
|
||||
mySPI->endTransaction();
|
||||
}
|
||||
else // Software SPI
|
||||
{
|
||||
swSPI_transfer(MS5611_CMD_READ_PROM + reg * 2);
|
||||
value += swSPI_transfer(0x00);
|
||||
value <<= 8;
|
||||
value += swSPI_transfer(0x00);
|
||||
}
|
||||
digitalWrite(_select, HIGH);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
uint32_t MS5611_SPI::readADC()
|
||||
{
|
||||
// command(MS5611_CMD_READ_ADC);
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
digitalWrite(_select, LOW);
|
||||
if (_hwSPI)
|
||||
{
|
||||
mySPI->beginTransaction(_spi_settings);
|
||||
mySPI->transfer(0x00);
|
||||
value += mySPI->transfer(0x00);
|
||||
value <<= 8;
|
||||
value += mySPI->transfer(0x00);
|
||||
value <<= 8;
|
||||
value += mySPI->transfer(0x00);
|
||||
mySPI->endTransaction();
|
||||
}
|
||||
else // Software SPI
|
||||
{
|
||||
swSPI_transfer(0x00);
|
||||
value += swSPI_transfer(0x00);
|
||||
value <<= 8;
|
||||
value += swSPI_transfer(0x00);
|
||||
value <<= 8;
|
||||
value += swSPI_transfer(0x00);
|
||||
}
|
||||
digitalWrite(_select, HIGH);
|
||||
// Serial.println(value, HEX);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
int MS5611_SPI::command(const uint8_t command)
|
||||
{
|
||||
yield();
|
||||
digitalWrite(_select, LOW);
|
||||
if (_hwSPI)
|
||||
{
|
||||
mySPI->beginTransaction(_spi_settings);
|
||||
mySPI->transfer(command);
|
||||
mySPI->endTransaction();
|
||||
}
|
||||
else // Software SPI
|
||||
{
|
||||
swSPI_transfer(command);
|
||||
}
|
||||
digitalWrite(_select, HIGH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// simple one mode version
|
||||
uint8_t MS5611_SPI::swSPI_transfer(uint8_t val)
|
||||
{
|
||||
uint8_t clk = _clock;
|
||||
uint8_t dao = _dataOut;
|
||||
uint8_t dai = _dataIn;
|
||||
uint8_t value = 0;
|
||||
for (uint8_t mask = 0x80; mask; mask >>= 1)
|
||||
{
|
||||
digitalWrite(dao,(val & mask));
|
||||
digitalWrite(clk, HIGH);
|
||||
value <<= 1;
|
||||
if (digitalRead(dai) != 0) value += 1;
|
||||
digitalWrite(clk, LOW);
|
||||
}
|
||||
digitalWrite(dao, LOW);
|
||||
// Serial.print(" # ");
|
||||
// Serial.println(value, HEX);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
157
libraries/MS5611_SPI/MS5611_SPI.h
Normal file
157
libraries/MS5611_SPI/MS5611_SPI.h
Normal file
@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: MS5611_SPI.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: MS5611 (SPI) Temperature & Humidity library for Arduino
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
#define MS5611_SPI_LIB_VERSION (F("0.1.0 EXPERIMENTAL"))
|
||||
|
||||
|
||||
#define MS5611_READ_OK 0
|
||||
#define MS5611_ERROR_2 2 // TODO ??
|
||||
#define MS5611_NOT_READ -999
|
||||
|
||||
|
||||
enum osr_t
|
||||
{
|
||||
OSR_ULTRA_HIGH = 12, // 10 millis
|
||||
OSR_HIGH = 11, // 5 millis
|
||||
OSR_STANDARD = 10, // 3 millis
|
||||
OSR_LOW = 9, // 2 millis
|
||||
OSR_ULTRA_LOW = 8 // 1 millis Default = backwards compatible
|
||||
};
|
||||
|
||||
|
||||
class MS5611_SPI
|
||||
{
|
||||
public:
|
||||
explicit MS5611_SPI(uint8_t select, uint8_t dataOut = 255, uint8_t dataIn = 255, uint8_t clock = 255);
|
||||
|
||||
bool begin();
|
||||
|
||||
// reset command + get constants
|
||||
// returns false if ROM constants == 0;
|
||||
bool reset();
|
||||
|
||||
// the actual reading of the sensor;
|
||||
// returns MS5611_READ_OK upon success
|
||||
int read(uint8_t bits);
|
||||
// wrapper, uses the preset oversampling rate.
|
||||
inline int read() { return read( (uint8_t) _samplingRate); };
|
||||
|
||||
// sets oversampling to a value between 8 and 12
|
||||
void setOversampling(osr_t samplingRate);
|
||||
|
||||
// oversampling rate is in osr_t
|
||||
osr_t getOversampling() const { return (osr_t) _samplingRate; };
|
||||
|
||||
// temperature is in ²C
|
||||
float getTemperature() const;
|
||||
|
||||
// pressure is in mBar
|
||||
float getPressure() const;
|
||||
|
||||
// OFFSET - 0.3.6
|
||||
void setPressureOffset(float offset = 0) { _pressureOffset = offset; };
|
||||
float getPressureOffset() { return _pressureOffset; };
|
||||
void setTemperatureOffset(float offset = 0) { _temperatureOffset = offset; };
|
||||
float getTemperatureOffset() { return _temperatureOffset; };
|
||||
|
||||
// to check for failure
|
||||
int getLastResult() const { return _result; };
|
||||
|
||||
// last time in millis() when the sensor has been read.
|
||||
uint32_t lastRead() const { return _lastRead; };
|
||||
|
||||
uint32_t getDeviceID() const { return _deviceID; };
|
||||
|
||||
void setCompensation(bool flag = true) { _compensation = flag; };
|
||||
bool getCompensation() { return _compensation; };
|
||||
|
||||
// develop functions.
|
||||
/*
|
||||
void setAddress(uint8_t address) { _address = address; }; // RANGE CHECK
|
||||
uint8_t getAddress() const { return _address; };
|
||||
uint8_t detectAddress() { todo }; // works with only one on the bus?
|
||||
*/
|
||||
|
||||
|
||||
// speed in Hz
|
||||
void setSPIspeed(uint32_t speed);
|
||||
uint32_t getSPIspeed() { return _SPIspeed; };
|
||||
|
||||
// debugging
|
||||
bool usesHWSPI() { return _hwSPI; };
|
||||
|
||||
// ESP32 specific
|
||||
#if defined(ESP32)
|
||||
void selectHSPI() { _useHSPI = true; };
|
||||
void selectVSPI() { _useHSPI = false; };
|
||||
bool usesHSPI() { return _useHSPI; };
|
||||
bool usesVSPI() { return !_useHSPI; };
|
||||
|
||||
// to overrule ESP32 default hardware pins
|
||||
void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select);
|
||||
#endif
|
||||
|
||||
|
||||
private:
|
||||
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;
|
||||
uint8_t _samplingRate;
|
||||
int32_t _temperature;
|
||||
int32_t _pressure;
|
||||
float _pressureOffset;
|
||||
float _temperatureOffset;
|
||||
int _result;
|
||||
float C[7];
|
||||
uint32_t _lastRead;
|
||||
uint32_t _deviceID;
|
||||
bool _compensation;
|
||||
|
||||
uint8_t _select;
|
||||
uint8_t _dataIn;
|
||||
uint8_t _dataOut;
|
||||
uint8_t _clock;
|
||||
bool _hwSPI;
|
||||
uint32_t _SPIspeed = 1000000;
|
||||
uint8_t swSPI_transfer(uint8_t value);
|
||||
SPIClass * mySPI;
|
||||
SPISettings _spi_settings;
|
||||
#if defined(ESP32)
|
||||
bool _useHSPI = true;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
218
libraries/MS5611_SPI/README.md
Normal file
218
libraries/MS5611_SPI/README.md
Normal file
@ -0,0 +1,218 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/MS5611_SPI/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/MS5611_SPI/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MS5611_SPI/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/MS5611_SPI/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MS5611_SPI/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MS5611_SPI/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MS5611_SPI.svg?maxAge=3600)](https://github.com/RobTillaart/MS5611_SPI/releases)
|
||||
|
||||
|
||||
# MS5611_SPI
|
||||
|
||||
Arduino library (SPI) for MS5611 temperature and pressure sensor.
|
||||
|
||||
|
||||
# WARNING EXPERIMENTAL
|
||||
|
||||
**Note: This library is under development and NOT stable**
|
||||
|
||||
SPI communication sec seems to work as "reasonable" values are read.
|
||||
|
||||
All SPI tests so far gave too high temperatures, some were rising slowly, others faster.
|
||||
Values are read correctly but somehow the selection of SPI as protocol seems to cause internal heating.
|
||||
|
||||
As I only have 1 sensor I cannot verify if there is something broken.
|
||||
Selecting I2C still does give stable results from the sensor.
|
||||
|
||||
|
||||
| Platform | tested | time (us)| Notes |
|
||||
|:----------------|-------:|:--------:|--------:|
|
||||
| UNO SW SPI | fail | | temperature is rising very fast (stopped)
|
||||
| UNO HW SPI | fail | | no data,
|
||||
| ESP32 SW SPI V | Y | 1299 | VSPI pins; temperature is rising slowly
|
||||
| ESP32 SW SPI H | Y | 1298 | HSPI pins; temperature too high (+3) but looks stable
|
||||
| ESP32 HSPI | Y | 1396 | temperature is rising slowly
|
||||
| ESP32 VSPI | Y | 1395 | temperature is rising slowly
|
||||
| NANO 33 SW SPI | - | - | not tested yet
|
||||
| NANO 33 HW SPI | - | - | not tested yet
|
||||
|
||||
|
||||
#### Note UNO
|
||||
|
||||
for VCC 3V3 was used as the other pins CLK and SDI have a voltage converter in the GY-63.
|
||||
Unclear why HW SPI blocks for UNO. (to investigate)
|
||||
|
||||
|
||||
#### Note ESP32
|
||||
|
||||
HSPI pins: not reliable at start, incorrect PROM reads, both HW and SW.
|
||||
adjusting the timing improves this a bit.
|
||||
+ these pins also interfere with uploading.
|
||||
|
||||
|
||||
#### Conclusion for now
|
||||
|
||||
In short a lot of open ends to investigate.
|
||||
|
||||
If you have experiences with this library please share them in the issues.
|
||||
|
||||
----
|
||||
|
||||
## Description
|
||||
|
||||
The MS5611 is a high resolution temperature and pressure sensor a.k.a GY-63.
|
||||
The high resolution is made possible by oversampling many times.
|
||||
|
||||
This library only implements the SPI interface.
|
||||
|
||||
Based upon the 0.3.6 version of the I2C library,
|
||||
see - https://github.com/RobTillaart/MS5611
|
||||
|
||||
|
||||
#### Breakout GY-63
|
||||
|
||||
```cpp
|
||||
//
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
//
|
||||
```
|
||||
|
||||
#### Related libraries
|
||||
|
||||
For pressure conversions see - https://github.com/RobTillaart/pressure
|
||||
|
||||
For temperature conversions see - https://github.com/RobTillaart/Temperature
|
||||
|
||||
|
||||
## Release Notes
|
||||
|
||||
### 0.1.0 initial release
|
||||
|
||||
Based upon 0.3.8 of the I2C MS5611 library.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
#### Base
|
||||
|
||||
- **MS5611_SPI(uint8_t select, uint8_t dataOut = 255, uint8_t dataIn = 255, uint8_t clock = 255)** constructor.
|
||||
- **bool begin()** initializes internals,
|
||||
- **reset()** resets the chip and loads constants from its ROM.
|
||||
- **int read(uint8_t bits)** the actual reading of the sensor.
|
||||
Number of bits determines the oversampling factor. Returns MS5611_READ_OK upon success.
|
||||
- **int read()** wraps the **read()** above, uses the preset oversampling (see below).
|
||||
Returns MS5611_READ_OK upon success.
|
||||
- **float getTemperature()** returns temperature in °C.
|
||||
Subsequent calls will return the same value until a new **read()** is called.
|
||||
- **float getPressure()** pressure is in mBar.
|
||||
Subsequent calls will return the same value until a new **read()** is called.
|
||||
|
||||
|
||||
#### Oversampling
|
||||
|
||||
- **void setOversampling(osr_t samplingRate)** sets the amount of oversampling.
|
||||
See table below and test example how to use.
|
||||
- **osr_t getOversampling()** returns amount of oversampling.
|
||||
|
||||
|
||||
Some numbers from datasheet, page 3 MAX column rounded up. (see #23)
|
||||
(actual read time differs - see performance sketch)
|
||||
|
||||
| definition | value | oversampling ratio | resolution (mbar) | time (us) | notes |
|
||||
|:--------------:|:-----:|:------------------:|:-----------------:|:---------:|:------:|
|
||||
| OSR_ULTRA_HIGH | 12 | 4096 | 0.012 | 9100 |
|
||||
| OSR_HIGH | 11 | 2048 | 0.018 | 4600 |
|
||||
| OSR_STANDARD | 10 | 1024 | 0.027 | 2300 |
|
||||
| OSR_LOW | 9 | 512 | 0.042 | 1200 |
|
||||
| OSR_ULTRA_LOW | 8 | 256 | 0.065 | 600 | Default = backwards compatible
|
||||
|
||||
|
||||
|
||||
#### Offset
|
||||
|
||||
The offset functions are added (0.3.6) to calibrate the sensor against e.g. a local weather station.
|
||||
This calibration can only be done runtime.
|
||||
|
||||
- **void setPressureOffset(float offset = 0)** Set an offset to calibrate the pressure.
|
||||
Can be used to get the pressure relative to e.g. 1 Atm.
|
||||
Set the offset to -1013 HPa/mBar and you get a sort of relative pressure.
|
||||
Default the offset is set to 0.
|
||||
- **float getPressureOffset()** returns the current pressure offset.
|
||||
- **void setTemperatureOffset(float offset = 0)** Set an offset to calibrate the temperature.
|
||||
Can be used to get the temperature in degrees Kelvin, just set the offset to +273.15.
|
||||
Default the offset is set to 0.
|
||||
- **float getTemperatureOffset()** returns the current temperature offset.
|
||||
|
||||
|
||||
#### Misc
|
||||
|
||||
- **int getLastResult()** checks last I2C communication. Replace with more informative error handling?
|
||||
- **uint32_t lastRead()** last time when **read()** was called in milliseconds since startup.
|
||||
|
||||
|
||||
#### DeviceID
|
||||
|
||||
- **uint32_t getDeviceID()** returns the hashed values of the calibration PROM.
|
||||
As these calibration are set in the factory and differ (enough) per sensor these can serve as an unique deviceID.
|
||||
|
||||
Having a device-ID can be used in many ways:
|
||||
- use known offsets for each sensor automatically,
|
||||
- work as an identification of that specific copy of the project (customer specific tracking).
|
||||
- ID in a mesh network
|
||||
- etc.
|
||||
|
||||
Note: this is not an official ID from the device / datasheet, it is made up from calibration data.
|
||||
|
||||
|
||||
#### 2nd order pressure compensation
|
||||
|
||||
- **setCompensation(bool flag = true)** to enable/desiable the 2nd order compensation.
|
||||
The default = true.
|
||||
Disabling the compensation will be slightly faster but you loose precision.
|
||||
- **getCompensation()** returns flag set above.
|
||||
|
||||
|
||||
#### SPI functions
|
||||
|
||||
// to be tested.
|
||||
|
||||
- **void setSPIspeed(uint32_t speed)**
|
||||
- **uint32_t getSPIspeed()**
|
||||
- **bool usesHWSPI()**
|
||||
|
||||
|
||||
#### SPI - ESP32 specific
|
||||
|
||||
// to be tested.
|
||||
|
||||
- **void selectHSPI()**
|
||||
- **void selectVSPI()**
|
||||
- **bool usesHSPI()**
|
||||
- **bool usesVSPI()**
|
||||
- **void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select)**
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- follow I2C library.
|
||||
- investigate internal heating with SPI.
|
@ -0,0 +1,61 @@
|
||||
//
|
||||
// FILE: MS5611_DETECTOR.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: detect an MS5611 on a NANO33 BLE
|
||||
// DATE: 2022-01-13
|
||||
// URL: https://github.com/RobTillaart/MS5611
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(0x76);
|
||||
Wire.write(0);
|
||||
int x = Wire.endTransmission();
|
||||
Wire.beginTransmission(0x77);
|
||||
Wire.write(0);
|
||||
int y = Wire.endTransmission();
|
||||
|
||||
Serial.println(x);
|
||||
Serial.println(y);
|
||||
delay(1000);
|
||||
|
||||
if (x == 0) Serial.println("MS5611 found at 0x76");
|
||||
else if (y == 0) Serial.println("MS5611 found at 0x77");
|
||||
else Serial.println("no MS5611 found");
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,86 @@
|
||||
//
|
||||
// FILE: MS5611_deviceID.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
// pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.print("MS5611 found: ");
|
||||
Serial.println(MS5611.getDeviceID(), HEX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1)
|
||||
{
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(1000);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.println("done");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,93 @@
|
||||
//
|
||||
// FILE: MS5611_minimal.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
//
|
||||
// MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(15, 13, 12, 14); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(15); // ESP32 HW SPI (HSPI)
|
||||
MS5611_SPI MS5611(5); // ESP32 HW SPI (VSPI)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
// ESP32 need this
|
||||
// MS5611.selectVSPI();
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.print("MS5611 found: ");
|
||||
Serial.println(MS5611.getDeviceID(), HEX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// MS5611.reset();
|
||||
uint32_t start = micros();
|
||||
MS5611.read(); // note no error checking => "optimistic".
|
||||
uint32_t stop = micros();
|
||||
Serial.print("T:\t");
|
||||
Serial.print(MS5611.getTemperature(), 2);
|
||||
Serial.print("\tP:\t");
|
||||
Serial.print(MS5611.getPressure(), 2);
|
||||
Serial.print("\tt:\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,102 @@
|
||||
//
|
||||
// FILE: MS5611_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
uint32_t start, stop, count;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.println("MS5611 found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
count = 0;
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
start = micros();
|
||||
int result = MS5611.read(); // uses default OSR_ULTRA_LOW (fastest)
|
||||
stop = micros();
|
||||
|
||||
if (count % 20 == 0)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("CNT\tDUR\tRES\tTEMP\tPRES");
|
||||
}
|
||||
|
||||
Serial.print(count);
|
||||
count++;
|
||||
Serial.print("\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print("\t");
|
||||
Serial.print(result);
|
||||
Serial.print("\t");
|
||||
Serial.print(MS5611.getTemperature(), 2);
|
||||
Serial.print("\t");
|
||||
Serial.print(MS5611.getPressure(), 2);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,130 @@
|
||||
//
|
||||
// FILE: MS5611_performance_all.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.println("MS5611 found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("OSR \t TIME");
|
||||
|
||||
|
||||
start = micros();
|
||||
MS5611.read(); // uses default OSR_ULTRA_LOW (fastest)
|
||||
stop = micros();
|
||||
Serial.print( (uint8_t) MS5611.getOversampling());
|
||||
Serial.print("\t");
|
||||
Serial.println(stop - start);
|
||||
delay(10); // to flush serial.
|
||||
|
||||
|
||||
MS5611.setOversampling(OSR_LOW);
|
||||
start = micros();
|
||||
MS5611.read();
|
||||
stop = micros();
|
||||
Serial.print( (uint8_t) MS5611.getOversampling());
|
||||
Serial.print("\t");
|
||||
Serial.println(stop - start);
|
||||
delay(10); // to flush serial.
|
||||
|
||||
|
||||
MS5611.setOversampling(OSR_STANDARD);
|
||||
start = micros();
|
||||
MS5611.read();
|
||||
stop = micros();
|
||||
Serial.print( (uint8_t) MS5611.getOversampling());
|
||||
Serial.print("\t");
|
||||
Serial.println(stop - start);
|
||||
delay(10); // to flush serial.
|
||||
|
||||
|
||||
MS5611.setOversampling(OSR_HIGH);
|
||||
start = micros();
|
||||
MS5611.read();
|
||||
stop = micros();
|
||||
Serial.print( (uint8_t) MS5611.getOversampling());
|
||||
Serial.print("\t");
|
||||
Serial.println(stop - start);
|
||||
delay(10); // to flush serial.
|
||||
|
||||
|
||||
MS5611.setOversampling(OSR_ULTRA_HIGH);
|
||||
start = micros();
|
||||
MS5611.read();
|
||||
stop = micros();
|
||||
Serial.print( (uint8_t) MS5611.getOversampling());
|
||||
Serial.print("\t");
|
||||
Serial.println(stop - start);
|
||||
delay(10); // to flush serial.
|
||||
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
148
libraries/MS5611_SPI/examples/MS5611_test/MS5611_test.ino
Normal file
148
libraries/MS5611_SPI/examples/MS5611_test/MS5611_test.ino
Normal file
@ -0,0 +1,148 @@
|
||||
//
|
||||
// FILE: MS5611_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.println("MS5611 found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
There are 5 oversampling settings, each corresponding to a different amount of milliseconds
|
||||
The higher the oversampling, the more accurate the reading will be, however the longer it will take.
|
||||
OSR_ULTRA_HIGH -> 8.22 millis
|
||||
OSR_HIGH -> 4.11 millis
|
||||
OSR_STANDARD -> 2.1 millis
|
||||
OSR_LOW -> 1.1 millis
|
||||
OSR_ULTRA_LOW -> 0.5 millis Default = backwards compatible
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_ULTRA_LOW);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_LOW);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_STANDARD);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_HIGH);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_ULTRA_HIGH);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
start = micros();
|
||||
int result = MS5611.read();
|
||||
stop = micros();
|
||||
if (result != MS5611_READ_OK)
|
||||
{
|
||||
Serial.print("Error in read: ");
|
||||
Serial.println(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("T:\t");
|
||||
Serial.print(MS5611.getTemperature(), 2);
|
||||
Serial.print("\tP:\t");
|
||||
Serial.print(MS5611.getPressure(), 2);
|
||||
Serial.print("\tt:\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,150 @@
|
||||
//
|
||||
// FILE: MS5611_test_offset.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MS5611_SPI_LIB_VERSION: ");
|
||||
Serial.println(MS5611_SPI_LIB_VERSION);
|
||||
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.println("MS5611 found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
MS5611.setTemperatureOffset(273.15); // set temp in Kelvin
|
||||
MS5611.setPressureOffset(-1013); // set pressure relative to 1 ATM
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
There are 5 oversampling settings, each corresponding to a different amount of milliseconds
|
||||
The higher the oversampling, the more accurate the reading will be, however the longer it will take.
|
||||
OSR_ULTRA_HIGH -> 8.22 millis
|
||||
OSR_HIGH -> 4.11 millis
|
||||
OSR_STANDARD -> 2.1 millis
|
||||
OSR_LOW -> 1.1 millis
|
||||
OSR_ULTRA_LOW -> 0.5 millis Default = backwards compatible
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_ULTRA_LOW);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_LOW);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_STANDARD);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_HIGH);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.setOversampling(OSR_ULTRA_HIGH);
|
||||
test();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
start = micros();
|
||||
int result = MS5611.read();
|
||||
stop = micros();
|
||||
if (result != MS5611_READ_OK)
|
||||
{
|
||||
Serial.print("Error in read: ");
|
||||
Serial.println(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("T: ");
|
||||
Serial.print(MS5611.getTemperature(), 2);
|
||||
Serial.print("\tP: ");
|
||||
Serial.print(MS5611.getPressure(), 2);
|
||||
Serial.print("\tt: ");
|
||||
Serial.print(stop - start);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,87 @@
|
||||
//
|
||||
// FILE: MS5611_test_plotter.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo application
|
||||
// URL: https://github.com/RobTillaart/MS5611_SPI
|
||||
|
||||
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
// BREAKOUT MS5611 aka GY63 - see datasheet
|
||||
//
|
||||
// SPI I2C
|
||||
// +--------+
|
||||
// VCC VCC | o |
|
||||
// GND GND | o |
|
||||
// SCL | o |
|
||||
// SDI SDA | o |
|
||||
// CSO | o |
|
||||
// SDO | o L | L = led
|
||||
// PS | o O | O = opening PS = protocol select
|
||||
// +--------+
|
||||
//
|
||||
// PS to VCC ==> I2C (GY-63 board has internal pull up, so not needed)
|
||||
// PS to GND ==> SPI
|
||||
// CS to VCC ==> 0x76
|
||||
// CS to GND ==> 0x77
|
||||
|
||||
|
||||
// SPI UNO/NANO ESP32 (V) ESP32(H)
|
||||
// SELECT 10 5 15
|
||||
// MOSI 11 23 13
|
||||
// MISO 12 19 12
|
||||
// CLOCK 13 18 14
|
||||
|
||||
|
||||
// MS5611_SPI(select, dataOut, dataIn, clock);
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
// MS5611_SPI MS5611(10, 11, 12, 13); // UNO SW SPI (5V problem?
|
||||
// MS5611_SPI MS5611(10); // UNO HW SPI
|
||||
MS5611_SPI MS5611( 5, 23, 19, 18); // ESP32 SW SPI
|
||||
// MS5611_SPI MS5611(5); // ESP32 HW SPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.println();
|
||||
if (MS5611.begin() == true)
|
||||
{
|
||||
Serial.println("MS5611 found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("MS5611 not found. halt.");
|
||||
while (1)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.println("TEMP\tPRESSURE");
|
||||
// scale T & P to same range :)
|
||||
MS5611.setPressureOffset(-1000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
MS5611.read();
|
||||
Serial.print(MS5611.getTemperature(), 2);
|
||||
Serial.print("\t");
|
||||
Serial.print(MS5611.getPressure(), 2);
|
||||
Serial.println();
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
38
libraries/MS5611_SPI/keywords.txt
Normal file
38
libraries/MS5611_SPI/keywords.txt
Normal file
@ -0,0 +1,38 @@
|
||||
# Syntax Colouring Map For MS5611
|
||||
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
MS5611 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
|
||||
reset KEYWORD2
|
||||
read KEYWORD2
|
||||
|
||||
setOversampling KEYWORD2
|
||||
getOversampling KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
getPressure KEYWORD2
|
||||
getLastResult KEYWORD2
|
||||
lastRead KEYWORD2
|
||||
|
||||
setTemperatureOffset KEYWORD2
|
||||
getTemperatureOffset KEYWORD2
|
||||
setPressureOffset KEYWORD2
|
||||
getPressureOffset KEYWORD2
|
||||
|
||||
getDeviceID KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
MS5611_LIB_VERSION LITERAL1
|
||||
|
||||
MS5611_READ_OK LITERAL1
|
||||
MS5611_ERROR_2 LITERAL1
|
||||
MS5611_NOT_READ LITERAL1
|
||||
|
23
libraries/MS5611_SPI/library.json
Normal file
23
libraries/MS5611_SPI/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "MS5611_SPI",
|
||||
"keywords": "MS5611,GY-63,GY63,temperature,pressure",
|
||||
"description": "Arduino library (SPI) for MS5611 temperature and pressure sensor",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MS5611_SPI.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "MS5611_SPI.h"
|
||||
}
|
11
libraries/MS5611_SPI/library.properties
Normal file
11
libraries/MS5611_SPI/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=MS5611_SPI
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library (SPI) for MS5611 temperature and pressure sensor
|
||||
paragraph=Experimental, GY-63, GY63.
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/MS5611_SPI
|
||||
architectures=*
|
||||
includes=MS5611_SPI.h
|
||||
depends=
|
125
libraries/MS5611_SPI/test/unit_test_001.cpp
Normal file
125
libraries/MS5611_SPI/test/unit_test_001.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-01-01
|
||||
// PURPOSE: unit tests for the MS5611 temperature and pressure library
|
||||
// https://github.com/RobTillaart/MS5611
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual); // a == b
|
||||
// assertNotEqual(unwanted, actual); // a != b
|
||||
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||
// assertLess(upperBound, actual); // a < b
|
||||
// assertMore(lowerBound, actual); // a > b
|
||||
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||
// assertTrue(actual);
|
||||
// assertFalse(actual);
|
||||
// assertNull(actual);
|
||||
|
||||
// // special cases for floats
|
||||
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||
// assertInfinity(actual); // isinf(a)
|
||||
// assertNotInfinity(actual); // !isinf(a)
|
||||
// assertNAN(arg); // isnan(a)
|
||||
// assertNotNAN(arg); // !isnan(a)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "MS5611_SPI.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "MS5611_SPI_LIB_VERSION: %s\n", (char *) MS5611_SPI_LIB_VERSION );
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
unittest(test_new_operator)
|
||||
{
|
||||
assertEqualINF(exp(800));
|
||||
assertEqualINF(0.0/0.0);
|
||||
assertEqualINF(42);
|
||||
|
||||
assertEqualNAN(INFINITY - INFINITY);
|
||||
assertEqualNAN(0.0/0.0);
|
||||
assertEqualNAN(42);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqual(MS5611_READ_OK , 0);
|
||||
assertEqual(MS5611_ERROR_2 , 2);
|
||||
assertEqual(MS5611_NOT_READ, -999);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
unittest(test_constructor)
|
||||
{
|
||||
MS5611 sensor(0x77);
|
||||
assertTrue(sensor.begin());
|
||||
|
||||
assertEqualFloat(-9.99, sensor.getTemperature(), 0.01);
|
||||
assertEqualFloat(-9.99, sensor.getPressure(), 0.01);
|
||||
assertEqual(0, sensor.getLastResult());
|
||||
assertEqual(0, sensor.lastRead());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_read_sensor)
|
||||
{
|
||||
MS5611 sensor(0x77);
|
||||
|
||||
assertTrue(sensor.begin());
|
||||
|
||||
assureEqual(MS5611_READ_OK, sensor.read());
|
||||
|
||||
// as Wire not implemented in tests
|
||||
// assertEqual(MS5611_NOT_READ, sensor.getTemperature());
|
||||
// assertEqual(MS5611_NOT_READ, sensor.getPressure());
|
||||
// assertEqual(MS5611_NOT_READ, sensor.getLastResult());
|
||||
// assertEqual(0, sensor.lastRead());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_overSampling)
|
||||
{
|
||||
MS5611 sensor(0x77);
|
||||
|
||||
assertTrue(sensor.begin());
|
||||
|
||||
// default
|
||||
assureEqual(OSR_ULTRA_LOW, sensor.getOversampling());
|
||||
|
||||
sensor.setOversampling(OSR_ULTRA_LOW);
|
||||
assureEqual(OSR_ULTRA_LOW, sensor.getOversampling());
|
||||
sensor.setOversampling(OSR_LOW);
|
||||
assureEqual(OSR_LOW, sensor.getOversampling());
|
||||
sensor.setOversampling(OSR_STANDARD);
|
||||
assureEqual(OSR_STANDARD, sensor.getOversampling());
|
||||
sensor.setOversampling(OSR_HIGH);
|
||||
assureEqual(OSR_HIGH, sensor.getOversampling());
|
||||
sensor.setOversampling(OSR_ULTRA_HIGH);
|
||||
assureEqual(OSR_ULTRA_HIGH, sensor.getOversampling());
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
Loading…
Reference in New Issue
Block a user