Giter Club home page Giter Club logo

bluerobotics_ms5837_library's Introduction

BlueRobotics MS5837 Library Test

Arduino library for the MS5837 pressure sensor. The MS5837 is a tiny SMT pressures sensor from Measurement Specialties that can measure pressure of up to 30 Bar (300m depth) with resolution of 0.2 mbar.

This library also supports the MS5837-02BA which has a much smaller measurement range and is better suited for altitude measurement in air.

Documentation

Please see the examples for normal operation. Below are the available functions used in the library.

MS5837();

/** Must be called before attempting to operate the sensor.
 * Returns true if the sensor was initialized successfully.
 * wirePort is optional and defaults to Wire.
 * You can select a different port by calling (e.g.) init(Wire1)
 */
bool init(TwoWire &wirePort);

/** Calls init.
 * Returns true if the sensor was initialized successfully.
 */
bool begin(TwoWire &wirePort);

/** Set model of MS5837 sensor. Valid options are MS5837::MS5837_30BA (default)
 * and MS5837::MS5837_02BA.
 */
void setModel(uint8_t model);

/** Provide the density of the working fluid in kg/m^3. Default is for
 * seawater. Should be 997 for freshwater.
 */
void setFluidDensity(float density);

/** The read from I2C takes up for 40 ms, so use sparingly if possible.
 */
void read();

/** Pressure returned in mbar or mbar*conversion rate.
 */
float pressure(float conversion = 1.0f);

/** Temperature returned in deg C.
 */
float temperature();

/** Depth returned in meters (valid for operation in incompressible
 *  liquids only. Uses density that is set for fresh or seawater.
 */
float depth();

/** Altitude returned in meters (valid for operation in air only).
 */
float altitude();

Versions

1.0.0 - First release, included in Arduino Library Manager

Reference

You can find the MS5837-30BA datasheet here.

bluerobotics_ms5837_library's People

Contributors

adambluer avatar dwblair avatar jaxxzer avatar patrickelectric avatar paulzc avatar rjehangir avatar thorleifjacobsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluerobotics_ms5837_library's Issues

Library does not compile for certain newer Arduino targets

When I include the library in Arduino IDE, and compile for the Arduino Nano 33 BLE/BLE Sense boards, I get some errors due to D1 and D2 being #define-d in pins_arduino.h, from the built-in Arduino libraries, causing a conflict with the D1 and D2 variables declared in the library.

The exact error is as follows:

In file included from C:\Users\neilbaner\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.0\cores\arduino/Arduino.h:90:0,
                 from sketch\MS5837_Example.ino.cpp:1:
C:\Users\neilbaner\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.0\variants\ARDUINO_NANO33BLE/pins_arduino.h:82:14: error: expected unqualified-id before numeric constant
 #define D1   1
              ^
C:\Users\neilbaner\Documents\Arduino\libraries\BlueRobotics_MS5837_Library/MS5837.h:88:11: note: in expansion of macro 'D1'
  uint32_t D1, D2;
           ^
exit status 1
Error compiling for board Arduino Nano 33 BLE.

Newest commit is not reflected in the arduino library manager

Hi, this took a day of my life trying to debug. Basically I was trying to get the full resolution of the Bar 02, but it wasn't working. Turns out that the newest commit (to get the full resolution of the Bar02) is not reflected when you automatically download from the arduino manger! I guess because the tag 1.1.0 refers to the Jun 2017 build? Anyways, download the library from here directly and put it in your Arduino library path so you can get the full resolution for the Bar 02.

Perhaps other people are getting this issue and not noticing, since it is subtle and we only noticed it because we were using it as an altitude sensor. Underwater the reduced resolution would not be immediately apparent, its 16mm versus the true 0.16mm, since noise is still an issue to overcome.

Also, hopefully the developer might fix the tag in the arduino library to point to the updated version.

Not getting valid data.

Hi,

first, I am not sure if this is the right place to post this. But I'll give it a try anyway.

I have been using this sensor with this library for quite some time and all of the sudden we started getting really weird data back from our device. I uploaded a picture of the serial data we are receiving from the example sketch.

Pressure: -20053014.00 mbar
Temperature: -389.20 deg C
Depth: -198730.95 m
Altitude: nan m above mean sea level

If we dunk it under water, heat it up or cool it down, this is the numbers we get.

Any Idea of what went wrong? and way I can try and reset the device?

Thanks!
Ryan

Arduino Due - MS5837 help

Hello All,

This isn't quite an issue but am seeking a little help. I am trying to use the Softwire library for bit-banging and trying to read the pressure data from the MS5837 using the digital pins on the Arduino Due. Has anyone tried using this library for bitbanging ?
The problem that I am facing right now is failure of CRC .. My read CRC is 15 and calculated is 11. So the init method fails and does not give me any values. Any help with this is appreciated.
Thanks

I2C doesnt work

Hi,

I have tried 12C to my bar02. Connected to an Arduino via a logic level converter as recommended by Blue Robotics.
I still could not get a reading and the error still says "Init Fail".
However when I did a code to check on the ping, it works fine. I could ping x076.
https://forum.arduino.cc/t/i2c-ping-check-connected-devices/116200/7
If that the case, is there something wrong with your libraries or code?

Library compiling error. constexpr does not name a type

Hello,

I'm a basic user and wanted to try this library, but when I try compiling it along with my sketch it shows the error at the end of the post.

I also get the error when I use the example so I'm sure the problem is in the library itself.

Thank for sharing it and hope you find the bug as I could really take advantage of it!


In file included from MS5837_Example.ino:39:0:
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:44:9: error: 'constexpr' does not name a type
static constexpr float Pa = 100.0f;
^
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:44:9: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:45:9: error: 'constexpr' does not name a type
static constexpr float bar = 0.001f;
^
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:45:9: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:46:9: error: 'constexpr' does not name a type
static constexpr float mbar = 1.0f;
^
C:\Users\cgiron\Documents\Arduino\libraries\BlueRobotics_MS5837_Library-master/MS5837.h:46:9: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
Error compiling.

expected ')' before numeric constant

When i run the example, i met following issues. I looked through the code but have no clue.

/MS5837.h:87:11: error: expected unqualified-id before numeric constant
/MS5837.h:87:11: error: expected ')' before numeric constant

Printing 'here'

In your MS5837.cpp you have a print statement that send 'here' when below a certain temperature. This is was a pain to track down as all I wanted was the data and not any extraneous print statements.

Same sensor with two different ESP32's gives different result. ESP32-WROOM vs ESP32-C3

I am having some trouble using the MS5837 on my new ESP32-C3 project. Using some very basic code, the sensor on the EPS32-WROOM dev board works fine and reads about 1000 mbar. On the ESP32-C3 the number is around -100 mbar which is all wrong. Also when I add some pressure to the line, ESP32-C3 goes positive to a point and then reverts back to negative with increased pressure while the ESP32-WROOM works as expected. I thought it might be a bad sensor but I've transplanted twice both new and from a working ESP32-WROOM project board to the ESP32-C3 board. I'm aware these two different chips use different architectures and I'm wondering if that's the issue. Is there something I can do when compiling under Arduino IDE, other than using the correct board selection, to solve this problem?

Thanks!

Bug: MS5837_30BA26 300 bar sensor detected as 2 bar sensor

I switched from using the current Arduino library version 1.1.1 of MS58357.h/.cpp to head of master (I forked the project) and found that depth was being reported as zero despite being several metres under water. This is for the 300 bar sensor, bought just under a year ago.

It turns out that the model detection code in the init() function is assigning model = MS5837_02BA (value 1) instead of = MS5837_30BA (value 0). I am not calling setModel() anywhere in the client code. It seems that something in the "Read calibration values and CRC" is not working.

The current Arduino library version doesn't have this model check and _model defaults to MS5837_30BA. As a separate issue none of the private member variables are being initialised in the constructor so their values are officially undefined (and fortunately the compiler is setting them to zero automatically). They should be initialised in the constructor to 0, including the C[8] array contents.

Is altitude dependent on barometric pressure

Thanks for this library, it's easy to implement and seems to work well. I've read the data sheet and I don't see any information if altitude is dependent on barometric pressure.

Reason I ask is

a) day 1 altitude is 700 feet above sea level--clear day, but I did not check the pressure
b) day 2 altitude was 505 feet above sea level (tested in the same spot), cloudy, near rain

I can only guess that the unit computes altitude based on barometric pressure.

Thoughts?

Kris

Mbar resolution

Hi,

Thanks for writing this awesome library!

One thing I noticed is that the sensor datasheet claims .2 mbar accuracy, but I'm only seeing whole number mbar numbers coming out of pressure(). Any thoughts on this?

Setup is pretty standard - using a Moteino (standard Arduino clone, ATMega328p, 3.3v) and running the unmodified sketch. Application is water depth sensing.

Anyways, it would be awesome if it's possible to get more resolution out of the sensor and get 2mm resolution.

Thanks!
Jeff

Allow setting the ground level atmospheric pressure

We currently offset by mean sea level pressure when estimating depth or altitude, but most applications get more useful data by using an explicit measured pressure value to offset by. Library users currently need to do that offsetting manually, which is inconvenient and somewhat unintuitive.

It would be preferable if we provided a suitable method for setting the current pressure as the basis to measure depth/altitude from, and simply use MSL as the default offset value.

Issue mentioned in this forum post, along with a variety of others previously (e.g. this comment from 2017).

This kind of offsetting / calibration is already done in ArduPilot vehicle firmwares, and used regularly to set the zero-point for ArduSub vehicle depth, and the launch altitude for aerial vehicles.

CRC Calculation Function

Line 174 in MS5837.cpp is as follows:

n_rem ^= (uint16_t)((n_prom[i>>1]) & 0x00FF0);

However, this differs from the MS5837 manual which give the CRC function for that line as

n_rem ^= (uint16_t)((n_prom[i>>1]) & 0x00FF);

I don't know if this causes a problem on Arduino, but when I copied the code for use in a Linux Beaglebone project I was getting checksum errors until I noticed the extra zero in that hex value from the Github repository code. I know this is an Arduino library, but it seems to me that the CRC function won't provide the correct answer using an Arduino either without removing that extra 0 from the hex value on that line. Again, I might be wrong and it might work as expected on Arduino, just pointing out a discrepancy between the manual and the Github code.

Cheers!

Only 7 prom registers

We have an array of size 8 to hold the internal prom, but the device only has 7 prom registers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.