GY-63_MS5611/libraries/MS5611/examples/MS5611_test/MS5611_test.ino

133 lines
2.7 KiB
Arduino
Raw Normal View History

//
2020-11-27 05:20:37 -05:00
// FILE: MS5611_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo application
// DATE: 2014-okt-16
2020-11-27 05:20:37 -05:00
// URL: https://github.com/RobTillaart/MS5611
2021-01-29 06:31:58 -05:00
#include "MS5611.h"
2022-01-14 07:34:56 -05:00
// 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
// +--------+
//
// PS to VCC ==> I2C
// PS to GND ==> SPI
// CS to VCC ==> 0x76
// CS to GND ==> 0x77
MS5611 MS5611(0x76); // 0x76 = CSB to VCC; 0x77 = CSB to GND
2021-01-29 06:31:58 -05:00
2022-01-14 07:34:56 -05:00
uint32_t start, stop;
2021-12-22 04:13:21 -05:00
void setup()
{
2020-11-27 05:20:37 -05:00
Serial.begin(115200);
2022-01-14 07:34:56 -05:00
while (!Serial);
Serial.println();
Serial.println(__FILE__);
2021-12-22 04:13:21 -05:00
Serial.print("MS5611_LIB_VERSION: ");
2020-11-27 05:20:37 -05:00
Serial.println(MS5611_LIB_VERSION);
2021-01-29 06:31:58 -05:00
2021-12-22 04:13:21 -05:00
if (MS5611.begin() == true)
{
Serial.println("MS5611 found.");
}
else
{
Serial.println("MS5611 not found. halt.");
2022-01-14 07:34:56 -05:00
while (1)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
2021-12-22 04:13:21 -05:00
}
2022-01-14 07:34:56 -05:00
Serial.println();
}
/*
2021-12-24 06:14:45 -05:00
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.
2021-12-27 14:39:07 -05:00
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
2022-01-14 07:34:56 -05:00
*/
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);
2021-12-24 06:14:45 -05:00
MS5611.setOversampling(OSR_ULTRA_HIGH);
2022-01-14 07:34:56 -05:00
test();
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
Serial.println();
}
2021-12-22 04:13:21 -05:00
2022-01-14 07:34:56 -05:00
void test()
{
2022-01-14 07:34:56 -05:00
start = micros();
2020-11-27 05:20:37 -05:00
int result = MS5611.read();
2022-01-14 07:34:56 -05:00
stop = micros();
2020-11-27 05:20:37 -05:00
if (result != MS5611_READ_OK)
{
Serial.print("Error in read: ");
Serial.println(result);
}
else
{
2022-01-14 07:34:56 -05:00
Serial.print("T:\t");
2021-01-29 06:31:58 -05:00
Serial.print(MS5611.getTemperature(), 2);
2020-11-27 05:20:37 -05:00
Serial.print("\tP:\t");
2021-01-29 06:31:58 -05:00
Serial.print(MS5611.getPressure(), 2);
2022-01-14 07:34:56 -05:00
Serial.print("\tt:\t");
Serial.print(stop - start);
Serial.println();
2020-11-27 05:20:37 -05:00
}
}
2021-01-29 06:31:58 -05:00
2021-12-22 04:13:21 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-22 04:13:21 -05:00