Let us see how to get the temperature and barometric pressure values using the O Watch sensor board.
The specific sensor used in O Watch is a product/chip named BMP280. To use this sensor we need a software library with easy to use functions to read the sensor values. In this case we will use the BMP280 Library from the awesome folks at Adafruit.
- The Adafruit BMP library requires the Adafruit Sensor library. Frist download and rename the uncompressed folder Adafruit_Sensor and check that the Adafruit_Sensor folder contains Adafruit_Sensor.h
- Then download the Adafruit BMP280 Library.
- Rename the uncompressed folder Adafruit_BMP280 and check that the Adafruit_BMP280 folder contains Adafruit_BMP280.cpp and Adafruit_BMP280.h.
- Place the Adafruit_BMP280 library folder in your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library.
- Restart the Arduino IDE.
Here is a simple example that shows these values. This demo is derived from the example provided by Adafruit in their library.
/***************************************************************************
This is a demo of the BMP280 humidity, temperature & pressure sensor
for the O Watch. http://theowatch.com
Made on products from http://tiny-circuits.com
Derived from the BMP280 library test program by Adafruit
----> http://www.adafruit.com/products/2651
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
Original library and example written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Adafruit_BMP280.h> //include the Adafruit BMP280 library
#include <TinyScreen.h>
TinyScreen display = TinyScreen(TinyScreenPlus);
//Initialize the library using I2C
Adafruit_BMP280 bme; // I2C is the interface used in TinyScreen+ for all sensors
void setup()
{
display.begin();
display.setBrightness(8);
display.setFlip(1);
display.setCursor(5,5);
display.setFont(liberationSans_8ptFontInfo);
display.fontColor(TS_8b_White,TS_8b_Black);
if (!bme.begin()) //check if you are able to read the sensor
{
display.print("Not valid BMP280");
while (1);
}
}
void loop() {
display.setCursor(5,5);
display.print("Temp = ");
//call library function to reach temp value and converting it to farenheit
display.print((bme.readTemperature()*9/5+32-13)); //you can delete '*9/5+32-13' to show in celsius
display.print(" *F");
display.setCursor(5,25);
display.print("Pr = ");
//call library function to reach pressure value
display.print(bme.readPressure()/3389.39);
display.print(" inHg.");
display.setCursor(5,45);
display.print("Alt = ");
//call library function to calculate altitude from pressure
display.print(bme.readAltitude(1015.3)); // this should be adjusted to your local forcase
display.print(" m ");
delay(2000);
display.clearWindow(0,0,96,64);
}
You can copy and paste the above code to load it to your O Watch and see it working. Note the following based on Adafruit documentation:
- Temperature is calculated and returned in degrees C in the library, it is converted to to F in the example by using the classic F = C * 9/5 + 32 equation.
- Pressure is returned by the library function in the SI units of Pascals. 100 Pascals = 1 hPa = 1 millibar. Often times barometric pressure is reported in millibar or inches-mercury. For future reference 1 pascal =0.000295333727 inches of mercury, or 1 inch Hg = 3386.39 Pascal. So if you take the pascal value of say 100734 and divide by 3389.39 you’ll get 29.72 inches-Hg. This calculation is done in the example and the result printed is in Hg.
- You can also calculate Altitude. However, you can only really do a good accurate job of calculating altitude if you know the hPa pressure at sea level for your location and day! The sensor is quite precise but if you do not have the data updated for the current day then it can be difficult to get more accurate than 10 meters.
- To get the sea level pressure for your location, in US you can use this website: http://www.aviationweather.gov/adds/metars/. Find the station code for your nearest airport from stations.txt link on that page and use that code and select ‘translated’ results. In the resulting page you will be able to see the pressure at the station as well as it gives you the sea level pressure.
- Substitute the sea level pressure value in the altitude function to get the correct altitude for your location. You can check the altitude(elevation) for your location (choose meters) at http://www.whatismyelevation.com. Be aware that sea level pressure changes during the day and even slight variations impact the altitude calculation.
Comments
Please log in or sign up to comment.