Skip to content

[DRIVER] bmp180 sensor driver implementation#5078

Merged
LudwigKnuepfer merged 1 commit intoRIOT-OS:masterfrom
aabadie:bmp180_driver
Mar 22, 2016
Merged

[DRIVER] bmp180 sensor driver implementation#5078
LudwigKnuepfer merged 1 commit intoRIOT-OS:masterfrom
aabadie:bmp180_driver

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Mar 15, 2016

Hi,
I have a bmp180 and noticed that there's no driver implementation for it.
I tested this implementation using a Samr21-xpro (SDA is pin PA16, SCL is PA17). It works well !

@kYc0o kYc0o added the Area: drivers Area: Device drivers label Mar 15, 2016
@kYc0o kYc0o added this to the Release 2016.04 milestone Mar 15, 2016
@kYc0o kYc0o self-assigned this Mar 15, 2016
printf("MB: %i\n", (int)dev->calibration.mb);
printf("MC: %i\n", (int)dev->calibration.mc);
printf("MD: %i\n", (int)dev->calibration.md);
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the DEBUG() function available on debug.h?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kYc0o : done !

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 15, 2016

Just a side note about potential improvements: sections 3.6 and 3.7 of the bmp180 datasheet explain how to compute respectively the absolute altitude and pressure at see level.

Maybe I can add the 2 missing functions to compute those values ?

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 15, 2016

Is up to you! the driver can offer basic functionality but if you want to implement all the features it's always better

DEBUG("MB: %i\n", (int)dev->calibration.mb);
DEBUG("MC: %i\n", (int)dev->calibration.mc);
DEBUG("MD: %i\n", (int)dev->calibration.md);
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then the #if ENABLE_DEBUG becomes unnecessary don't you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I removed them.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 15, 2016

Is up to you! the driver can offer basic functionality but if you want to implement all the features it's always better

I added the missing functions.
Just one side question: is it possible to display float values using printffunction ? I tried %f but nothing is displayed. Maybe you have an idea.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 15, 2016

Maybe you have an idea.

Answering to myself: apparently using float_t type is the way to go.

@jnohlgard
Copy link
Copy Markdown
Member

%f requires support in newlib, you're likely building with newlib-nano. Float printf support can be added with some linker flags though I can't remember which right now.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 15, 2016

%f requires support in newlib, you're likely building with newlib-nano

Indeed, but I don't know how to enable this either.

@aabadie aabadie force-pushed the bmp180_driver branch 2 times, most recently from a00fe87 to 42e657d Compare March 15, 2016 14:21
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 15, 2016

Indeed, but I don't know how to enable this either.

It seems that I have to apply RIOT patches on newlib sources, rebuild them and re-install them, using the available scripts.
Is there any documentation somewhere ?

@jnohlgard
Copy link
Copy Markdown
Member

@aabadie I don't think you need to rebuild newlib. I did this in Contiki before to get float printf support:
eistec/contiki@b5d6b25

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 16, 2016

Thanks @gebart, I tried to add LDFLAGS += -specs=nano.specs -lc -lnosys -u _printf_float in the Makefile for the test application but still no float values displayed.

@jnohlgard
Copy link
Copy Markdown
Member

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 16, 2016

Thanks @gebart, this time it works !
I pushed an updated version of the test application.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 16, 2016

Maybe we need to take care about the platforms that can support it, since not all can handle floats in this way. Let's run the CI and if everything goes ok we can merge it ;)

@kYc0o kYc0o added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 16, 2016
@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 16, 2016

Oh! it is already complaining about the white spaces. Can you take care of this?

@aabadie aabadie force-pushed the bmp180_driver branch 3 times, most recently from b872573 to 69c3d3f Compare March 16, 2016 17:01
# use the nano-specs of Newlib when available
ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
export LINKFLAGS += -specs=nano.specs -lc -lnosys
export LINKFLAGS += -specs=nano.specs -lc -lnosys -u _printf_float
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to split this out into a separate pull request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added #5094 for this.

@LudwigKnuepfer
Copy link
Copy Markdown
Member

tests/driver_bmp180/Readme.md is empty

#include "xtimer.h"
#include "board.h"

#define SLEEP (2 * 1000 * 1000u)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to SLEEP_2S or document..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(2S or whatever this is ;)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 17, 2016

@LudwigKnuepfer, I addressed most of your comments.

@aabadie aabadie force-pushed the bmp180_driver branch 4 times, most recently from e5ca2b8 to 0536e92 Compare March 17, 2016 16:03
* @return 0 on success
* @return -1 if device's I2C is not enabled in board config
*/
int bmp180_altitude(bmp180_t *dev, double *pressure_0, double *altitude);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if double is a good idea here - I would strongly vote for something more ressource friendly - why not altitute in cm as int32_t? I doubt you get a better precision anyway... Same for the pressure...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, altitude precision can be 1m, under I think it doesn't really make sense. I changed the returned type from double to int32_t.

* @return 0 on success
* @return -1 if device's I2C is not enabled in board config
*/
int bmp180_altitude(bmp180_t *dev, int32_t *pressure_0, int32_t *altitude);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pressure_0 is an input, right? So why pass it as a pointer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason (seems to be a bad practice ;) ). I changed that.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 19, 2016

Murdock is complaining about nhdp tests... otherwise all other tests passed successfully. @kaspar030 is this related to the move of uhdp out of the examples?

@jnohlgard
Copy link
Copy Markdown
Member

@kYc0o no, it's because of #5107

* reads pressure (hPa) ; and prints them to the STDOUT;
* computes the pressure at sea level (assuming the current pressure is computed
based on Polytechnique School Campus altitude, 158m);
* computes the altitude (given the pressure at sea level).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the pressure at sea level => based on the pressure at sea level calculated above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the pressure at sea level => based on the pressure at sea level calculated above

branch updated including this change.

@kYc0o kYc0o added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 20, 2016
@aabadie aabadie force-pushed the bmp180_driver branch 2 times, most recently from 543c243 to 0814e2f Compare March 21, 2016 13:35
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 21, 2016

Just pushed a commit activating printf_float module in test application (see #5094).

* @brief Read pressure value from the given BMP180 device, returned in Pa
*
* @param[in] dev Device descriptor of BMP180 device to read from
* @param[out] pressure Pressure in Pa
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing the output range to use 10^-1000 Pa (mPa) is probably more precise and feasible. If I am correct, the pressure is somewhere between 10 and 150 from sea-level to very high up (https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Atmospheric_Pressure_vs._Altitude.png/300px-Atmospheric_Pressure_vs._Altitude.png), so using mPa here would be more precise...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing the output range to use 10^-1000 Pa (mPa) is probably more
precise and feasible. If I am correct, the pressure is somewhere between 10
and 150 from sea-level to very high up
(https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Atmospheric_Pressure_vs._Altitude.png/300px-Atmospheric_Pressure_vs._Altitude.png),
so using mPa here would be more precise...

I'm not sure to understand your comment, maybe you mean kPa ? the results here are already returned in Pa, which is 1000x more precise and corresponds to SI. Displaying the results in hPa is common in meteorology.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, my bad, I was way of here... Don't know what I was thinking - never mind...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.
Thanks to your comment I had to look again at the datasheet and this pointed me to the possibility of writing a unittest for the temperature/pressure computations: the datasheet gives ground truth values that could be used to test internal implementations of formulas in the driver.
Do you think it make sense ?

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 21, 2016

All the checks are successful, someone with the hardware can ACK? @LudwigKnuepfer ?

@LudwigKnuepfer
Copy link
Copy Markdown
Member

it would be great if you could rewrite your commit messages to fit the module: change pattern (and still fit within the 70 character limitation for the first line of the commit message).

@LudwigKnuepfer
Copy link
Copy Markdown
Member

Example: drivers/bmp180: initial import

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 22, 2016

@LudwigKnuepfer, I edited the commit message following your suggestion.

@LudwigKnuepfer
Copy link
Copy Markdown
Member

ACK

LudwigKnuepfer added a commit that referenced this pull request Mar 22, 2016
[DRIVER] bmp180 sensor driver implementation
@LudwigKnuepfer LudwigKnuepfer merged commit 9dcde95 into RIOT-OS:master Mar 22, 2016
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 22, 2016

Merged #5078.

Thanks :)Merged #5078.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#5078 (comment)

@LudwigKnuepfer
Copy link
Copy Markdown
Member

No, thank you for your contribution and endurance with all the review comments =)

@aabadie aabadie deleted the bmp180_driver branch October 3, 2016 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants