Notifications
Clear all

BME/BMP 280  

Page 3 / 3
  RSS

ZeFerby
(@zeferby)
Reputable Member
Joined: 1 year ago
Posts: 380
2019-11-27 12:16 pm  

@pugwash

I don't understand why you need 2 modules if you know the exact altitude of 25m ?

Eric


ReplyQuote
Pugwash
(@pugwash)
Prominent Member
Joined: 1 year ago
Posts: 997
2019-11-27 12:22 pm  

@zeferby

It looks like the altitude returned from the module, where the pressure at mean sea level is 1013 hPa is the reference pressure, is varying with the actual air pressure. If you understand what I mean?

Meaning that the air pressure at 0m is constantly changing, therefore the reference pressure used to calculate altitude is constantly changing.


ReplyQuote
ZeFerby
(@zeferby)
Reputable Member
Joined: 1 year ago
Posts: 380
2019-11-27 12:29 pm  

@pugwash

Ok I get that, but is your module moving ? If it stays at 25m altitude, you may write an "auto-calibrating function" to find the right pressure reading. I'm thinking of something like

measuredAlt = sensor.getAltitude(theReferencePressure);
while (measuredAlt > 26) {
theReferencePressure -= 1;
measuredAlt = sensor.getAltitude(theReferencePressure);
}
while (measuredAlt < 24) {
theReferencePressure += 1;
measuredAlt = sensor.getAltitude(theReferencePressure);
}
//theReferencePressure should be ok now ?

 

Eric


ReplyQuote
Pugwash
(@pugwash)
Prominent Member
Joined: 1 year ago
Posts: 997
2019-11-27 12:35 pm  

@zeferby

Oh Lord, please don't let me be misunderstood (The Animals)

Actually, for me, the altitude is pretty much useless as I am not moving the module, I was only noting my findings in case anybody decided to use this module in a model aeroplane or quadcopter.

I was just trying just to put over that the sketch has to be zeroed out according to the local ambient air pressure, before deployment.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2019-11-27 12:37 pm  

@pugwash

Thanks... first day was tough after an extended period off work!

Ok, I've seen this done before, but never had the need to do it.  The term that describes what you want to do is usually called "serialization" of an object.  I've seen it done using special boost libraries (which Arduino does not support), but you could also use standard C's "malloc" and "memcopy" built in functions, which you can use under Arduino

Having said that however, could you not just put the 4 float variables in an array external to the structure, calculate their checksum, and then update the checksum variable in the structure before sending?

For example, not tested at all:

struct Message{
  float temperature;
  float pressure;
  float altitude;
  float humidity;
  byte checksum;  
  };

Message bme280data;

float structMembers[] = {
  bme280data.temperature, 
  bme280data.pressure, 
  bme280data.altitude, 
  bme280data.humidity
   };

int CalculateChecksum(float struct_members[]) {
  
  int Checksum(0);

  for(int idx(0); idx < sizeof(struct_members); idx++) {
     // Calculate checksum using your preferred method
    }

  return Checksum;
  }

// Then...
bme280data.checkSum = CalculateChecksum(structMembers);

// Then send it off across the waves...

 

Something along these lines should work, and probably easier than using malloc and memcopy.  If you don't find one in the mean time, I'll have a look at finding an C serialization example for you tomorrow, but hope this gives you some alternative ideas to work with in the mean time.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2019-11-27 12:42 pm  

@pugwash

Ok, just found one quickly:

Structure serialization

Goodnight and enjoy... I expect a working protocol by tomorrow night 🙂


ReplyQuote
Pugwash
(@pugwash)
Prominent Member
Joined: 1 year ago
Posts: 997
2019-11-27 12:42 pm  

@frogandtoad

Having said that however, could you not just put the 4 float variables in an array external to the structure, calculate their checksum, and then update the checksum variable in the structure before sending?

I suppose I could just make checksum a floating-point number, and just add the other floats together to make a crude checksum, but to use XOR, I really need the byte values!!


ReplyQuote
Lesl
 Lesl
(@lesl)
New Member
Joined: 1 month ago
Posts: 3
2020-09-14 11:08 am  

 I have been looking at the BME280 and have setup a small altimeter.  I did a number of tests. plotted the altitude at a fixed point over 2000 observations. The variance was not too bad about 30cm.  I then took another plot of 2000 obs where each observation was the average of 1000 obs.   In this case the variance dropped to around 10 cm.  I ran into a conundrum using the device altitude. The device is very sensitive to small variations in pressure (eg,. can measure the height of the desk from the floor).In my extended tests I noticed the altitude gradually drifted off. This is fairly obvious because the sea level pressure is always changing with the weather patterns. What to do?  Where I live I know the altitude so when I turn my altimeter on I calibrate to the correct altitude by adjusting the sea level pressure using a potentiometer. This works at home for a short while then needs recalibrating. If I go into the nearby mountains I will be in an area where I do not know the altitude nor do I know the sea level pressure. Hence my conundrum.

Has anyone looked at this?


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2020-09-15 8:54 am  

@lesl

I've never played around with altitudes before, but a quick search pulls up many, many pages of information.  The following page provides some good detail with example code:

How to Set Up the BMP180 Barometric Pressure Sensor on an Arduino

Cheers.


ReplyQuote
Lesl
 Lesl
(@lesl)
New Member
Joined: 1 month ago
Posts: 3
2020-09-15 10:35 am  

@frogandtoad

Interesting article., but does not solve the problem.  If you move from the site you know the altitude for then you do not know the sea level pressure or the altitude. You are calculating altitude based on an incorrect sea level pressure if you move your location or the time changes. For the device  to work correctly you must know either your current altitude or the sea level pressure at your current location and time. As far as I can see it cannot be done. Unless you can get detailed weather information for your current location. The best I can imagine is to use a weighted mean of pressure data from any surrounding weather stations to get an approximate value. Here in northern Thailand there are only a handful of stations.


ReplyQuote
Pugwash
(@pugwash)
Prominent Member
Joined: 1 year ago
Posts: 997
2020-09-15 12:04 pm  

@lesl

A rough and ready solution may be to use 2 BME280s. One to collect the actual air pressure at ground level and pass this on to the second BME280 as a zero point to work out the actual elevation above current ground level.

So if you were flying a model aeroplane this should be done just once before take-off!


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2020-09-16 5:04 am  

@lesl

Posted by: @lesl

Unless you can get detailed weather information for your current location. The best I can imagine is to use a weighted mean of pressure data from any surrounding weather stations to get an approximate value. Here in northern Thailand there are only a handful of stations.

Indeed, I did read another article which spoke about taking the mean, which sounds like reasonable solution, as long as you can obtain that information.  Another article I read also mentioned that inaccurate readings can come from variables lacking in precision, such as a 4 byte 'float' - Even using a 'double' on ATMEGA based boards uses the same number of bytes, so 'double' offers no additional precision, but an Arduino DUE for example (32 BIT ARM controller), offers 8 bytes of precision and 12 bit A/DAC's for greater resolution, which may make up for some of those inaccuracies.

I like the idea @pugwash mentioned.
I was thinking of something along the same lines but he beat me to it! 🙂

Cheers.


ReplyQuote
Page 3 / 3