Working with BMP180 Pressure Sensor and ATtiny85 using USITWIX Library

USITWIX – Using USI as TWI / I2C

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.


Here’s the setup:

BMP180 with Tinusaur ATtiny85 USITWIX

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)


The source code is available at
— 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.

The page about USITWIX and articles about USITWIX.

New Library: USITWIX – Using USI as TWI / I2C

Attiny85 Tinusaur USI TWI I2C BMP180 Variometer

As we know, there’s no I²C on ATtiny85, not even the TWI (Two Wire Interface, which is basically I2C with a different name) that some other Atmel chips have, so I had to write my own that takes advantage on the built-in USI unit. This library is called USITWIX and will be presented in this blog post.

Of course, I used other people’s work write mine and they’re references in the source code.

The primary source is the Atmel application note AVR312: Using the USI module as a I2C slave that explains how to use the  built-in USI unit as I2C slave.

The source code is already available at

Some important code fragments

Although the TWI and I2C is a synchronous communication protocol it still requires precise timing.

In the code there are few places where some fixed time intervals are specified and this is in the usitwim.h file:

#define T2_TWI 5 // >4,7us
#define T4_TWI 4 // >4,0us

These may need to be adjusted if the CPU runs at a frequency different than default 1 MHz.

Using the USITWIX library


The BMP180TINY is another library for working with the BOSCH BMP180 atmospheric pressure sensor.The source code is available at along with some samples.

There is also a Variometer project that uses those libraries to produce audible measurements of the changes in the altitude by measuring the atmospheric pressure and taking into account the temperature. Such tools, or instruments, are often used by paragliders.

Video here:


Here are some references to sources that I used while working on this project.

AVR312: Using the USI module as a I2C slave
C-code driver for TWI slave, with transmit and receive buffers; Compatible with I2C protocol; Interrupt driven, detection and transmission/reception; Wake up from all sleep mode, including Power Down.

TINY USI Interface in I2C mode and the AVR312 Appnote
What’s wrong with the AVR Appnote?

ATTiny USI I2C Introduction – A powerful, fast, and convenient communication interface for your ATTiny projects!
I2C, it’s a standard that’s been around for around 20 years and has found uses in nearly every corner of the electronics universe. It’s an incredibly useful technology for us microcontroller hobbyists but can seem daunting for new users. This tutorial will solve that problem, first by reviewing what I2C is and how it works, then by going in-depth on how to implement I2C in Atmel’s ATTiny USI (Universal Serial Interface) hardware.

I2C Bus for ATtiny and ATmega
This two wire interface is formally known as the Inter-Integrated Circuit bus, or just the I2C bus and was invented by NXP when it was still Philips Semiconductors. If you’re reading this Instructable then you’ve probably heard of the I2C bus and may even have used it on a PIC or other microcontroller. While conceptually very simple, and supported by hardware resources on the AVRs, software drivers are still necessary to use the I2C bus. Atmel provides Application Notes (see the Resources later in this Instructable), but these are incomplete and don’t show any examples beyond communicating with another AVR device.