For detecting small altitude changes, reading the barometric altitude, or for just detecting changes in pressure, you may want to use a pressure sensor. The Bosch BMP-180 is a very reasonably priced one, which is accessed over I2C. There are several nice breakout boards available from Adafruit.featuring the BMP-180. There is, for example, one featuring only the BMP-180, and another one featuring gyros and accelerometers as well.
No matter which, you would access it in a similar fashion.
As usual, before you start, you need to install PI4J and set up the Rasberry for i2c communication.
Next decide in which mode you want the device to run. Check out the OperatingMode for details. The higher resolution, the longer time it takes to read values, and the higher the current draw.
If you are using the standard address and i2c bus, next create a BMPDevice:
BMPDevice bmp = new BMPDevice(OperatingMode.STANDARD);
Next, reading the pressure, altitude and temperature is done like this:
System.out.println(String.format(“Temperature: %.1fC, Pressure: %dhPa, Altitude: %.1fm”,
bmp.readTemperature(),
bmp.readPressure() / 100,
bmp.readAltitude()));
To run the standard example, which will print the above every two seconds:
sudo java -classpath .:classes:/opt/pi4j/lib/*:./bmp.jar se.hirt.pi.adafruit.bmp.test.BMPTest
Summary
The Bosh BMP-180 is an easy way to measure the barometric altitude and/or changes in pressure.
Where can I find documentation about the class “BMPDevice” ?
Hi there!
I haven’t really had time to blog about it yet, but I am working on the open source framework Robo4J together with a friend. Much of my code has been donated to that project, so you could start using this class instead:
https://github.com/Robo4J/robo4j/blob/master/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/bmp/BMP085Device.java
For more information, see:
http://www.robo4j.io/2017/01/getting-started-with-robo4j-hw-rpi.html
Hope this helps!
Kind regards,
Marcus
Yeah!
The one of Robo4j.io framework main goals is to help Robotics/IoT communicty enabling rapid development of also advanced systems. We have already available some simple examples.
see: https://github.com/Robo4J
We are systematically working hard on updates and improvements
Kind Regards,
Miro
Robo4J Team