Arduino Read More Than One Pressure Sensor
How to utilise the BMP280 Barometric Force per unit area Chip
The BMP280 is an insanely small SMD device (ii.0mm x 2.5mm) so y'all'll need to get hold of a breakout board to use it on the bench. It is a small enough that it can exist used inside a mobile phone. That may seem a bit unusual as yous would probably think of this device used only in a atmospheric condition station environs until you realise that pressure can exist used to measure altitude.
In fact the applications that are suggested by Bosch Sensortech (articles the BMP280) are:
- Enhancement of GPS navigation (e.g. fourth dimension-to-first-fix comeback, dead-reckoning, slope detection).
- Indoor navigation (floor detection, elevator detection).
- Outdoor navigation, leisure and sports applications.
- Weather forecast.
- Health care applications (e.g. spirometry).
- Vertical velocity indication (e.yard. rise/sink speed).
It is also ideally suited and for use as a highly accurate Arduino barometric pressure sensor since it employs an SPI interface.
[Source: https://world wide web.bosch-sensortec.com/bst/products/all_products/bmp280]
Source: datasheet Figure 1
Initially it would seem that measuring height using a BMP280 scrap is a little redundant since a GPS system is far more accurate and too gives you lot height information equally well. Now, I did a little research on Google and that last statement may not be then accurate!
We all tend to assume that any system we have is admittedly accurate and I thought GPS was in that category (based on the fact that my satnav shows me exactly where I am - but how authentic is that?). It turns out to be about ±10m!
Despite the fact that GPS satellites have atomic clocks on board and fifty-fifty after adjustment for relativistic changes due to speed of travel and distance above the globe - at that place are other factors that influence GPS accuracy including the atmosphere, satellite position inaccuracy and other factors besides - and these tin can add up to quite a big error.
Garmin GPS receivers are typically authentic to 10m [horizontal measurement]
[Source: Garmin.com/aboutGPS] .
Did y'all know that the military did non believe that Einstein'due south theory of relativity would employ and built in a software switch to inside the satellite lawmaking to cease adjustment for that science (they had to plow it on when they found Enistein's relativity theorem did use even to their satellites!).
Why a GPS height Measurement is not that accurate
Another website (meet link below|) discusses the problem more fully. In summary, it is a comparison of GPS vs Barometric Pressure measurement. In that article it discusses how hang gliders and paragliders must wing inside a specific defined volumetric infinite and then that they are not eliminated from the competition. To practise that it is important that they tin can measure height accurately using their own instruments and y'all would accept thought that the GPS system is platonic for that; Maybe not!
The thing about GPS is that the GPS receiver knows where the satellites are and then it knows its position relative to iv or more satellites with extreme accurateness (more satellites requite increasing positional accuracy). The problem is that the orbit of the satellites does not hateful that the satellite or GPS receiver knows where the footing is located!
""Your GPS unit has multiple models (datums) of the Earth in its memory."
[source http://www.xcmag.com/2011/07/gps-versus-barometric-distance-the-definitive-answer/]
In fact, each GPS unit has multiple models of the world's surface e.g. WGS 84 (World Geodetic Arrangement - created in 1984). Other datums can be more than accurate for specific countries eastward.chiliad. in the United kingdom of great britain and northern ireland OSGB36 (ordinance survey data). There are quite a few other datum sets but WGS 84 is normally used for GPS systems.
The WGS 84 system defines an oblate spheroid that approximates the shape of the World and this is where errors can occur depending on where y'all are located. In the Uk you would exist 70m above the true height, and in India 100m below! (See the link to a higher place for a heatmap of height variation around the globe). Depending on your GPS the fault may exist calculated and compensated out (geoid correction).
Additionally there are other horizontal fault sources due to:
- Ionospheric effect (±5m)
- Satellite position error (±2.v)
- Satellite clock mistake (±2m)
- Multipath interference (±1m)
- Tropospheric issue (±0.5m)
- Maths and rounding errors (±1m)
Total horizontal fault: ±15m. Information technology is estimated that the vertical error is 3 times this: ±45m.
Another error source is from averaging the information over time e.g. over a few seconds so at that place volition be a delay in output reading while climbing or falling.
The department higher up is a summary from this link:
http://world wide web.xcmag.com/2011/07/gps-versus-barometric-altitude-the-definitive-answer/
Using Barometric Pressure for Top Measurement
In fact all aviation uses a Barometric pressure measurement converted to show a summit measurement, since pressure decreases with tiptop. Factors that impact the reading are temperature and so altimeters are temperature compensated. Another factor is the ground level force per unit area measurement (defines zero pinnacle) which varies with the weather so altimeters permit setting of the ground level pressure reading (obtained from weather condition services for aviation) to eliminate local pressure changes. lookup QNH and QNE
With the Bosch 280 chip the pressure level range is from 300 to 1100 hPa which ways top can be measured from +9000m to -500m. It also has an relative accuracy of ±0.12 hPa. This equates to a relative accuracy of ±1m.
Annotation: This is probably the maximum inaccuracy - run across afterward for actual measurements that show the sensor (the specific ane I am using) is far more sensitive to relative acme alter.
Even if this inaccuracy is correct across the range of batches of all BMP280'south then it nevertheless represents a hugely more accurate reading than using a GPS for height measurement.
The accented accuracy is ±1hPa equivalent to 11.9m [ 9500.0/(1100-300) ] - this is still quite a bit better than GPS vertical readings. To get a more accurate elevation reading the unit would have to exist calibrated i.e. fix the output reading to zero on the ground (or get the current ground level pressure reading for the expanse from an aviation service and input it to the microcontroller).
The BMP280 (all electronic barometers probably) can react very quickly to pressure changes - there is no waiting around. The datasheet indicates that you tin read the device 157 times a second (for the BMP180 it is 120Hz). This means variations in acme tin can be rapidly detected. This is a bit too fast for height measurements - yous won't need that many data points - although they can be used when employing the IIR filter i.e. oversampling and so filtering to go a stable output. The rapid measurement charge per unit would be more appropriate for spirometry (measurement of breathing) or for rapid meridian modify measurement such equally in a hang glider competition..
Divergence between BMP180 and BMP280
The following tabular array shows the difference between the older BMP180 and the replacement function BMP280. Note how the BMP280 has far meliorate specifications and has multiple interfaces including high speed SPI, whereas the BMP180 but has I2C (you could have ordered a separate role with SPI). The other major divergence is that the BMP280 has a selectable filter functioning with 5 different bandwidths resulting in measurements with college accuracy.
Note: Temperature accuracy information is (cached in the information canvass):
- ±0.5°C (at 25°C) and
- ±1.0°C (over the full temperature range 0°C ~ 65°C).
Pressure Measurement Units
Unit | Symbol | No. Pascals |
---|---|---|
bar | bar | i x 105 Pa (exactly) |
millibar | mbar | 100 Pa (exactly) |
hectopascal | hPa | 100 Pa (exactly) |
conventional millimetre or mercury | mmHg | 133.322... Pa |
convetional inch of mercury | inHg | 3386.39... Pa |
pound-force per square inch | lbf/in2 | 6894.76... Pa |
[ Source: http://world wide web.npl.co.uk/reference/faqs/pressure-units ]
Note: hPa is numerically identical to mbar (millibar).
Measuring Altitude
To measure altitude you have to know the pressure reading at sea level. The normally used value is 101325 Pa or 1013.25mb - this was intended to represent the mean atmospheric force per unit area at ocean level. Unfortunately the value is not representative of the force per unit area at bounding main level in many unlike countries.
Really, the just fashion for authentic summit measurement, is to obtain the pressure value for body of water level on the day from a reliable forecast.
Notation: Fifty-fifty the ground level value will change through out the day anyway, so y'all really need a radio link transmitting the current pressure on the ground to your measuring device. This would make the altitude measurement every bit accurate as possible fifty-fifty with local pressure variations.
Schematic diagram
Employ the level translator parts if your breakout doesn't have them on-board (some boards come with level translator components). If it does have them then connect from the (5V) uno to the breakout lath straight. Alternatively use a 3V3 arduino for directly connection.
Arduino Uno BMP280 wiring
The two level converter circuits to a higher place convert voltage levels to and from 5V and 3V3. You tin find out ore almost it hither.
Note: The I2C connections are the 2 top left ones on an Arduino Uno if the usb connector is at the left of the lath. They are not marked. The left one is SCL and the right ane is SDA. They are the ii shielded pins opposite the vi pin connector the next labelled pin is AREF.
Typical force per unit area Results through the twenty-four hours
These reading are taken from the serial monitor output from the Arduino serial port for both Adafruti BMP280 library and I2C library (I2C library 1st). Pinnacle is not calibrated = wrong (except where noted).
x.15 3/8/17 avg 3-4th aug 1007mbar sea level pressure forecast Probe BMP280: Sensor establish HeightPT1: vii.41 grand; Height: 81.49 Force per unit area: 100350.00 Pa; T: 22.97 C HeightPT1: fourteen.10 m; Height: lxxx.99 Pressure level: 100356.00 Pa; T: 23.03 C HeightPT1: 80.79 m; Elevation: 80.74 Pressure: 100359.00 Pa; T: 23.fourteen C xvi:37 3/viii/17 Probe BMP280: Sensor found HeightPT1: 6.81 m; Tiptop: 74.95 Pressure: 100428.00 Pa; T: 23.43 C HeightPT1: 13.01 g; Height: 74.95 Pressure: 100428.00 Pa; T: 23.fifty C HeightPT1: eighteen.62 m; Height: 74.78 Pressure: 100430.00 Pa; T: 23.55 C 17.06 3/eight/17 HeightPT1: 73.82 m; Height: 73.61 Pressure level: 100444.00 Pa; T: 24.29 C HeightPT1: 73.82 m; Height: 73.86 Pressure: 100441.00 Pa; T: 24.29 C HeightPT1: 73.fourscore thousand; Height: 73.61 Pressure: 100444.00 Pa; T: 24.29 C 17:13 3/viii/17 HeightPT1: 72.57 thousand; Height: 72.77 Pressure: 100454.00 Pa; T: 24.50 C HeightPT1: 72.sixty yard; Superlative: 72.94 Pressure: 100452.00 Pa; T: 24.50 C HeightPT1: 72.63 m; Top: 72.85 Pressure level: 100453.00 Pa; T: 24.50 C HeightPT1: 72.65 m; Height: 72.85 Pressure level: 100453.00 Pa; T: 24.51 C 22:18 iii/8/17 Probe BMP280: Sensor plant HeightPT1: 5.31 m; Peak: 58.44 Pressure: 100625.00 Pa; T: 27.fourscore C HeightPT1: ten.11 m; Height: 58.11 Pressure: 100629.00 Pa; T: 27.85 C HeightPT1: 14.51 m; Height: 58.53 Pressure level: 100624.00 Pa; T: 27.89 C MP280 examination 17.06 3/8/17 Adafruit library output (when SDO pulled to 3V3) Temperature = 24.61 *C Pressure = 100444.17 Pa Approx altitude = 73.60 m 3/8/17 Adafruit library output (when SDO pulled to 3V3) Temperature = 24.99 *C Force per unit area = 100462.96 Pa Approx distance = 72.02 m 3/8/17 Adafruit library output (when SDO pulled to 3V3) Temperature = 25.03 *C Force per unit area = 100458.71 Pa Approx altitude = 72.38 chiliad 07:09 iv/eight/17 forecast pressure 1009mbar avg sea level pressure level Probe BMP280: Sensor establish HeightPT1: v.08 thousand; Superlative: 55.85 Force per unit area: 100656.00 Pa; T: 21.xxx C HeightPT1: 9.68 k; Height: 55.68 Pressure: 100658.00 Pa; T: 21.36 C HeightPT1: 13.87 m; Height: 55.85 Pressure: 100656.00 Pa; T: 21.42 C 09:04 four/viii/17 HeightPT1: 49.79 grand; Height: 49.57 Force per unit area: 100731.00 Pa; T: 22.46 C HeightPT1: 49.79 m; Summit: 49.74 Pressure: 100729.00 Pa; T: 22.46 C HeightPT1: 49.lxxx m; Height: 49.91 Pressure: 100727.00 Pa; T: 22.45 C HeightPT1: 49.80 g; Height: 49.82 Pressure: 100728.00 Pa; T: 22.44 C
Dissimilar libraries give the same result
Hither the adafruit library was given the actual forecast bounding main level pressure to get an distance. I don't recall it is too accurate because you have to accept the bodily ground level pressure level value at your location. where I am is near 23m above sea level not 2m see the readings below!
The I2C Sensor library does not allow yous change the default value of 1013.25mb so y'all would demand to go and write some code to allow accurate height measurement aligning.
Different libraries Adafruit and I2C library (same result) 07:41 13/8/17 forecast force per unit area 1020mbar avg sea level force per unit area I2C Sensor LIB: Probe BMP280: Sensor found HeightPT1: 1.82 m; Elevation: 20.03 Pressure: 101758.00 Pa; T: 23.27 C HeightPT1: 3.50 yard; Height: 20.28 Pressure: 101755.00 Pa; T: 23.34 C HeightPT1: 5.01 chiliad; Height: xx.12 Pressure level: 101757.00 Pa; T: 23.33 C 07:42 13/eight/17 Adafruit library forecast pressure 1020mbar Temperature = 23.70 *C Pressure = 101755.11 Pa Approx distance = 20.27 m
Notation: The I2C sensor library code averages the 1st 10 readings (come across case 2 below) and then the left mitt values are not stable (until 10 values are gathered) the next measurement is the unaveraged height reading (20.03).
Interestingly in that location is a difference in temperature readings; Perchance one of the library code implementations is not right.
Alarm: Getting a calibrated height using a predicted forecast pressure reading is not accurate as it will be slightly different at your location, and so it is best to pattern lawmaking to store the value (when you are at ground level - by pressing a dedicated button, or assemble the data on power upward). And then use this value as the scale value for measuring relative superlative from ground level.
Why your BMP280 won't start
If you're like me, and you lot have a breakout lath without level shifters, and you lot create some using a few components (see the schematic on this page), to get I2C style going, and and then burn the instance code into the Arduino uno r3. You then wonder why it's doing admittedly nothing!
As a typical engineer you give information technology a go and so - it's time to read the manual! - this is ever a last resort unless there is a danger of blowing up a $800 component! In which case read the manual first.
It turns out that the communication mode of the BMP280 is assault power upward by the state of various command inputs.
One "gotcha" is that an OUTPUT in SPI way turns into an INPUT in I2C manner!
SPI mode uses more pins to define its interface and one of these unused the outputs (in SPI way) is used every bit an input in I2C fashion!. If you have a breakout board then these control inputs are left floating, meaning its just non going to work unless you set them earlier power up.
Warning: Property any interface pivot high while VDDIO is switched off will damage the fleck due to current flow through protection diode. This could happen if yous are designing a circuitous power management organisation where control pins are connected to the processor and power to the chip is controlled separately.
Conversely, if FiveDD is off and VDDIO is supplied, command pins at the scrap are held at high-z (inactive).
IC2 Mode Pick
To get I2C mode going the Chip Select pin (CS) must exist held at the 5DDIO level as the BMP280 powers up.
If CS is held low during power up SPI mode is agile.
I2C Address Selection
In addition to that the SDO pin (used as an output in SPI mode) is used as an input that selects one of two I2C addresses. This pivot must exist held low to go the lower address.
If you don't desire to continuously change from high to low on SDO when changing which library you lot apply merely go into the Adafruit library (or I2C Sensor library) and change the BMP280_address from 0x77 to 0x76 (Adafruit library). The file is at:
C:\Users\<user name>\Documents\Arduino\libraries\Adafruit_BMP280_Library\Adafruit_BMP280.h
I2C pullups
SDI is a bi directional open bleed pin and must have a pullup attached.
There is no need for a pullup on SCK equally it is input; In I2C mode the device is only e'er a slave and does not do clock stretching. I tested this using a resistor drib down (5V to 3V) using 1k connected to a 1k5 then to ground. With the SCK input connected to the acme of the 1k5 - information technology works fine.
Notation: Yous tin merely leave out one pull up resistor if you apply the BMP280 on its own since I2C requires pullups so that the bus tin can be released for other devices.
Note: The SDI and SCK pins are not true open bleed pins and just SDI and SDO are implemented as bi-directional.
Table 29 in the datasheet (Pivot description) shows what is going on:
Adafruit Library just won't go
I found that the ADAFruit BMP280 Library would just not piece of work - the reason was that the SDO pin (used every bit an input in I2c mode) has been defaulted to 0x77 in software - that means the SDO pin needs to be pulled high (3V3 loftier) to work with this library (or change the default address in the library to 0x76).
I2C Address : For the BMP280
The device tin exist set to one of 2 I2C addresses, so you tin can accept ii separate pressure level sensors on 1 I2C bus. The choice is made using the SDO pin every bit an input, and when low selects accost 0x76, and when high selects address 0x77.
BMP280 Datasheet
Click here to download the datasheet
Software Library and versions
Arduino IDE Version
Version : 1.six.4
Bosch BMP280 sensor Libraries:
The libraries used are:
- Adafruit BMP280 Library one.0.2
- I2C-Sensor-Lib Ver 0.8.two
...both tin hands installed from the Arduino IDE.
If you do not see the library as an entry when you click the menus:
Sketch-->Include Library
Then select manage libraries :
Sketch-->Include Library -->Manage Libraries...
Search for and install <lib proper noun> using the "Filter Your Search" form.
Code size results from libraries used:
For the simple example lawmaking used at that place is a large difference in lawmaking use as shown below.
The Adafruit BMP280 uses 1334 bytes more than I2C Sensor Lib - this is something to note if yous are running out of code space.
Code use I2C-Sensor-Lib Lbrary: Sketch uses 8,830 bytes (27%) of plan storage space. Maximum is 32,256 bytes. Global variables use 563 bytes (27%) of dynamic memory, leaving ane,485 bytes for local variables. Lawmaking use Adafruit BMP280 Lbrary: Sketch uses 10,164 bytes (31%) of plan storage space. Maximum is 32,256 bytes. Global variables use 563 bytes (27%) of dynamic retentiveness, leaving 1,485 bytes for local variable
Differences between the libraries
The adafruit BMP280 library comes with a member function (or method) that allows entry of the ocean level altitude and returns the altitude based on this value and your current barometric reading (See case i beneath). This is a sparse library and does not give whatsoever other methods to command the annals settings inside the device.
On the other mitt I2C Sensor lib does have methods to set the internal parameters of the device but does not have a sea level distance correction part. You really need a corrector adjustment to get more than accurate altitude. The code below shows you how to udate the library to allow entry of the sea level pressure reading.
Adding a method to the I2C Sensor lib
This requires a simple addition to the library file:
- C:\Users\<username>\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src\i2c_BMP280.h
Detect the superlative method
"void getAltitude( float & meter)"
...and add in the ane shown beneath:
"void getAltitude( bladder & meter, float seaLevelmbar)"
/**< gives the number of meters above sea level */ void getAltitude( float & meter) { uint32_t iPascal; getPressure(iPascal); meter = 44330.0 *( 1 -pw( float (iPascal)/ 101325.0 , 1.0 / v.255 )); }; /**< gives the number of meters above sea level. JFM parameterised ocean level*/ void getAltitude( float & meter, float seaLevelmbar) { uint32_t iPascal; getPressure(iPascal); meter = 44330.0 *( ane -pow( float (iPascal)/(seaLevelmbar* 100 ), 1.0 / 5.255 )); };
This but adds a public method that allows the ocean level force per unit area (forecast) to be entered instead of the default 1013.25mbar value which gives a more accurate height reading.
Case 1 Adafruit Library : BMP280
The 1st arduino case sketch. This example uses the "Adafruit BMP280" Library.
Click in the code beneath to copy information technology to the clipboard.
/*************************************************************************** This is a library for the BMP280 humidity, temperature & pressure level sensor Designed specifically to piece of work with the Adafruit BMEP280 Breakout ----> http://www.adafruit.com/products/2651 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, delight support Adafruit andopen-source hardware past purchasing products from Adafruit! Written past Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BMP280.h> #define BMP_SCK 13 #define BMP_MISO 12 #define BMP_MOSI 11 #define BMP_CS 10 Adafruit_BMP280 bme; // I2C //Adafruit_BMP280 bme(BMP_CS); // hardware SPI //Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); void setup() { Series.begin( 9600 ); Serial.println(F( "BMP280 examination" )); if (!bme.begin()) { Series.println( "Could not find a valid BMP280 sensor, check wiring!" ); while ( 1 ); } } void loop() { Serial.print( "Temperature = " ); Series.print(bme.readTemperature()); Series.println( " *C" ); Serial.impress( "Pressure = " ); Serial.print(bme.readPressure()); Serial.println( " Pa" ); Series.impress( "Approx altitude = " ); Serial.impress(bme.readAltitude( 1018.00 )); // this should be adapted to your local forcast Serial.println( " k" ); Serial.println(); delay( 2000 ); }
Example ii - I2C Lib : BMP280
The twond arduino example sketch. This exampe uses the "I2C-Sensor-Lib" library.
Annotation: This case requires the additional method shown above for accurate altitude which is non included in the original bmp280 arduino library (instructions for adding it are here):
void getAltitude( float & meter, float seaLevelmbar).
#include <Wire.h> #include "i2c.h" #include "i2c_BMP280.h" BMP280 bmp280; void setup() { Serial.begin( 9600 ); Serial.impress( "I2C Sensor LIB: Probe BMP280: " ); if (bmp280.initialize()) Serial.println( "Sensor found" ); else { Serial.println( "Sensor missing" ); while ( 1 ) {} } // sometime-measure out: bmp280.setEnabled( 0 ); bmp280.triggerMeasurement(); } void loop() { bmp280.awaitMeasurement(); float temperature; bmp280.getTemperature(temperature); float pascal; bmp280.getPressure(pascal); static float meters, metersold; // bmp280.getAltitude(meters); bmp280.getAltitude(meters, 1018.00 ); // Allow entry of forecast sea level force per unit area JFM metersold = (metersold * x + meters)/ 11 ; bmp280.triggerMeasurement(); Series.print( " HeightPT1: " ); Serial.print(metersold); Serial.print( " thousand; Height: " ); Serial.impress(meters); Serial.print( " Pressure: " ); Serial.print(pascal); Serial.print( " Pa; T: " ); Serial.print(temperature); Serial.println( " C" ); delay( 120 ); }
Ideas for using Altitude Sensors
A table in the datasheet repeated below gives an indication of how to setup the device for unlike applications which range from indoor navigation (can't use the GPS hither equally at that place is no betoken indoors- information technology would also require accelerometer and mayhap a gyroscope chip, for expressionless reckoning movement detection). Other usage ideas are: Drop detection. Elevator floor change detection, Weather monitoring (e.thou. Arduino barometric pressure level monitor : everyman power setting), Use in a mobile phone.
Source: Datasheet Table 7: Recommends filter settings based on utilise cases.
Note: ODR is Typical Output Information Rate i.e. the maximum you can read the device for the given settings.
What's the IIR filter for?
The BMP280 chip has a congenital in Infinite Impulse Response filter (which is a type of DSP filter) that is useful for improving the output result from the sensor (or ignoring short term changes). For instance if using the sensor indoors, the sensor is so fast and sensitive that any pocket-sized pressure change will exist recorded e.g. the slamming of a door.
Using the IIR is a merchandise off betwixt sensor response time and the need to ignore short term changes in pressure - exterior you would not need to utilise the IIR filter since there won't be any doors slamming to crusade sudden force per unit area changes (run across Weather monitoring/Indoor Navigation in the table above (IIR=0)). For drop detection the state of affairs is the contrary to indoor navigation employ - you desire to detect sudden pressure level changes for instant height modify detection.
For indoor navigation use you tin can setup the BMP280 and so that small changes are ignored past setting appropriate values for the IIR filter - that would be the maximum value i.e. xvi - meet tabular array above (Indoor Navigation and hand held dynamic device).
Update rate vs oversampling
Oversampling is simply how many times the device reads a sensor and averages out the result and and then allows you to read it. The more oversampling that you set up the more time it takes for a reading to go available.
The table below (table 14 - again from the datasheet) shows the relationship between a specific standby time (that you can control: t_sb) versus the oversampling setting (ovsr_p and ovsr_t). For the to a higher place settings tabular array 7 shows that the oversampling setting is "Standard resolution" so yous tin gear up t_sb to 0.5 and read the device at 83.33Hz i.e. the table below tells yous the maximum achievable output rate for the given settings.
Example 3 Height Change Code
I have this odd idea that I want to discover out the speed of the lift in the local sports centre, and this device is the ideal tool to measure out superlative changes and rate of superlative modify. To practise this you need to setup the BMP280 for elevator floor detection (run into table 7 above) - actually drop detection provides more than data and an ODF of 125Hz - you can average out the information past processing..
Library lawmaking that can be institute at:
- C:\Users\<username>\Documents\Arduino\libraries\Adafruit_BMP280_Library
- C:\Users\<username>\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib
Currently in the Adaftuit Library software the Command register that sets the mode is fixed with no provision for re-programming information technology (within method: begin. Its value is set to 3F). For that reason the post-obit code uses the I2C Sensor library every bit this has a few more functions that allow changing the fashion of the BMP280 (see i2c_BMP280.h).
For elevator movement detection yous need the following setup:
Clarification | parameter | Value | I2C library method |
---|---|---|---|
Pressure level oversampling | osrs_p | x2 | setPressureOversampleRatio |
Temperatuure oversampling | osrs_t | x1 | setTemperatureOversampleRatio |
IIR | IIR | 0 | setFilterRatio |
Standby time | t_sb | 0 = 0.5ms | setStandby |
I selected a standby time every bit '0' for a fast update charge per unit course the sensor. Information technology may need to be adjusted for your code i.eastward. increase standby to reduce ability consumption.
#include <Wire.h> #include "i2c.h" #include "i2c_BMP280.h" BMP280 bmp280; void setup() { Serial.begin( 115200 ); Serial.println( "BMP280 elevator" ); Serial.impress( "Probe BMP280: " ); if (bmp280.initialize()) Serial.println( "Sensor found" ); else { Serial.println( "Sensor missing" ); while ( one ) {} } // Setup for elevator floor change measurement. bmp280.setPressureOversampleRatio( two ); bmp280.setTemperatureOversampleRatio( one ); bmp280.setFilterRatio( 0 ); bmp280.setStandby( 0 ); // onetime-measure: bmp280.setEnabled( 0 ); bmp280.triggerMeasurement(); } float get_altitude() { float meters; bmp280.getTemperature(meters); // throw away - needed for alt. bmp280.getPressure(meters); // throw away - needed for alt. bmp280.getAltitude(meters); return meters; } void loop() { float distance,velocity; static uint32_t time_now, time_was=millis(),dt; static float alt_was=get_altitude(); static uint32_t sample_time_was=millis(); static uint32_t readings= 0 ; static float values= 0 ,avg_alt= 0 ; static float meters; if ( (millis()-sample_time_was) > 2 ) { // read at a specific rate. if (!bmp280.awaitMeasurement()) Series.println( "Measure FAILED" ); meters = get_altitude(); readings++; values += meters; bmp280.triggerMeasurement(); sample_time_was = millis(); } // // Serial plotter // Serial.print(meters); // Serial.print(" "); // Serial.println(metersoldn); time_now = millis(); dt = time_now - time_was; if (dt>= 1000 ) { avg_alt = values/readings; distance = avg_alt - alt_was; velocity = (distance/(( float )dt/ 1000.0 )); alt_was = avg_alt; time_was = time_now; // Serial.print("AVG: "); // Serial.print(avg_alt); // Serial.print(" m/s ; dist: "); // Serial.impress(altitude); if (fabs(velocity)> 0.two ) { Serial.print( "Velocity: " ); Series.print(velocity); Series.print( " k/s ;" ); } Serial.print( "debug: " ); Serial.println(readings); values= 0 ; readings= 0 ; } }
Now you lot can use the BMP280 for more just weather monitoring!
This is the typical output yous get when lifting or lowering the sensor (using the series monitor in the IDE).
Note: The 76 value is as fast as you can become round the loop. In theory the sample rate should be set to 8 since the max you should go at is 125Hz so the sample rate should exist ane/125=8ms. Then the repeat data charge per unit in 1 sec would be 125 only the code is only capable of going at 76 in a sec. This will be due to using floats and serial output - recall well-nigh using fixed betoken and information technology will get faster. The question is do you need information technology to go faster = design determination (the library would accept to be re-written as well!).
You can encounter that increases in tiptop result in positive values while decreases in height result in negative values and anything below 0.2m is ignored. The output beneath is obtained merely from moving the sensor ~30cm up and downwards at a desk and so information technology is very sensitive and ideal for meridian change detection (building navigation).
BMP280 elevator Probe BMP280: Sensor establish Velocity: -3812.96 yard/s ;debug: 73 Velocity: -0.31 m/s ;debug: 76 debug: 76 debug: 76 debug: 76 debug: 76 Velocity: 0.32 m/south ;debug: 76 Velocity: 0.24 k/s ;debug: 76 debug: 76 debug: 76 debug: 76 debug: 76 Velocity: 0.54 yard/south ;debug: 76 debug: 76 Velocity: -0.47 m/s ;debug: 76 debug: 76 debug: 76 Velocity: 0.35 m/s ;debug: 76 debug: 76 Velocity: -0.20 m/s ;debug: 76 Velocity: -0.28 m/s ;debug: 76 Velocity: 0.27 one thousand/s ;debug: 76 debug: 76 debug: 76 Velocity: -0.45 m/s ;debug: 76 debug: 76 debug: 76 debug: 76
The higher up code is only a first go at obtaining velocity. Yous should change it to go a reading every second using either "indoor navigation" or "handheld device" BMP280 modes and stop using the complete data set for averaging i.e. rely on the internal modes of the BMP280. And so brandish velocity based on height changes from one sample to the next at one sec intervals. In a handheld device you lot would want to save power and also practise other tasks! Probably you would need a sample rate greater than 1 2d so as not to miss tiresome changes;.
Other ideas for apply of Distance Sensors : BMP280
The BMP280 could exist used in a drone for measuring height e.yard. for building mapping (or just to figure out how high something is - given that the device seems fairly accurate (approx. 30cm). The stated relative accurateness seems a fleck pessimistic at ±0.12hPa ( ±0.12mbar) for a ±1m resolution and in practise seems a lot better than this (although where you need to claim accuracy you would have to state that the measurement is ±1m).
The results in the Serial Monitor output (above) show that the device is capable of detecting a 30cm change in height (for this specific device).
Site Map | Terms of Use
Source: https://www.best-microcontroller-projects.com/bmp280.html
0 Response to "Arduino Read More Than One Pressure Sensor"
إرسال تعليق