In our previous post “USITWIX – Using UART as TWI / I2C” we looked at the USITWIX library that implements TWI / I2C communication between а ATtiny85 micro-controller and peripherals. Let’s see now how we can use that library to work with the BOSCH BMP180 atmospheric pressure sensor and a ATtiny85/Tinusaur boards.
The BMP180tiny Library
So, we wrote a simple library (called it BMP180tiny) that uses USITWIX to read and write from/to BMP180 registers, retrieve the measurements, do some additional calculations and produce result suitable for use in an application.
Setup
Here’s the setup:
NOTE: We need the USB-to-Serial just for debugging – it isn’t essential part of the setup.
Here is a short fragment of initialization code
uint8_t bmp180_result; if ((bmp180_result = bmp180_init()) != BMP180_RESULT_SUCCESS) { return -1; }
And here is now to use the functions …
// Read raw temperature uint16_t temp_rawdata = bmp180_read_temp_raw(); uint16_t temp_10x = bmp180_read_temp10x(); // temp_10x holds the result dC, i.e. 123 means 12.3 Celsius // Read raw pressure int32_t pres_rawdata = bmp180_read_pres_raw(); // Read pressure int32_t pres = bmp180_read_pres(); int16_t pres_hpa = pres / 100; // pres_hpa holds the result in hPa (hectopascals) // Read altitude int32_t alt_x = bmp180_read_alt_x(); int16_t alt_dm = alt_x / 100; // alt_dm holds the result in dm (decimeters)
The debugging output would look something like this …
t:raw=28622; t(dC)=253; p:raw/hi=5; p:raw/lo=4940; p(Pa)/hi=1; p(Pa)/lo=33948; p(hPa)=994; a/lo=24222; a(dm)=1552; t:raw=28624; t(dC)=253; p:raw/hi=5; p:raw/lo=4964; p(Pa)/hi=1; p(Pa)/lo=33933; p(hPa)=994; a/lo=24307; a(dm)=1553; t:raw=28623; t(dC)=253; p:raw/hi=5; p:raw/lo=4951; p(Pa)/hi=1; p(Pa)/lo=33939; p(hPa)=994; a/lo=22619; a(dm)=1536; t:raw=28624; t(dC)=253; p:raw/hi=5; p:raw/lo=4942; p(Pa)/hi=1; p(Pa)/lo=33940; p(hPa)=994; a/lo=24560; a(dm)=1556;
NOTE: This is generated using OWOWOD library and hardware (not required by the library itself to work)
References
The source code is available at https://bitbucket.org/tinusaur/bmp180tiny.
— The library is in the “bmp180tiny” folder.
— A sample code could found in the “bmp180tiny_test1” folder.
The page about BMP180tiny and articles about BMP180tiny.
Hello!!! Can you explain please how can I add this libraries into Arduino 1.6.7, just trying to make the variometer project but I just stuck on this step. I just made downloaded the bmp180tiny and usitiwix, but can´t find a way to put into my IDE. And last ask you to share the source code for the vario, if isn’t to much! Thanks a lot!!
Hello Felipe,
I’m glad to see you’re interested in our projects.
I don’t know how to add libraries to the new Arduino IDE, e.g. 1.6+ – I have not tried it yet.
But here are 2 articled about older versions of Arduino IDE:
http://tinusaur.org/2014/07/03/arduino-ide-setup-guide/
http://tinusaur.org/guides/arduino-ide-setup-guide/
… that may be helpful.