BMP180 voltage level problems

Hi,

I've been playing with a BMP180 barograph chip https://www.sparkfun.com/products/11824. The setup is quite simple, one wire to ground, one to 3.3v and the other two to SDA and SCL. The wiring is shown here https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-/connecting-the-hardware. The problem is this, I've noticed that after plugging the module's power leads (only) into the arduino, the voltage across them is 3.3 volts (as expected) but as soon as I plug in the SDA and SCL leads then the voltage across the power leads goes up to 5 volts. This isn't what I was expecting, I guess somehow either the SDA or SCL lead is 'pulling' the voltage up to 5 volts, which probably isn't very healthy! (the 'resting state' for both the SDA and SCL pins seems to be 5 volts)

Is this right? I know I'm following the wiring diagram correctly and connecting SDA and SCL directly to the arduino, but I'm wondering if because the arduino is a 5 volt device and the BMP180 is a 3.3 volt device I ought to be using some sort of buffer or level shifter between the two. (different to what sparkfun claim)

Some background info - I'm working with a Mega2560, and using pins 20 and 21. I've not actually attempted to run any code yet, I unplugged it straight away as soon as I noticed the voltage come up. I have got a compass module https://www.sparkfun.com/products/7915 to work on the same arduino which indicates that a) the mega works ok, and b) I'm not a complete numpty (others may dispute this) and c)I2C works on this arduino. I first noticed this issue on a old BMP080 http://www.coolcomponents.co.uk/barometric-pressure-sensor-bmp085-breakout.html but I put this down to it being an old unit that had been lying in a draw for 6 months, hence this issue was the first thing I checked when I plugged in the new unit. I haven't run any code on it, because I didn't want to risk frying the chip, so far it's only been connected for about 3 seconds so I'm hoping it hasn't been damaged.

All guidance appreciated!

Yes the two I2C leads use the internal pull up resistors to 5V. Soloution 1) hack the wire libary to not enable the pull ups. 2) get another libary that does not do this by default like the I2C Master libary

The standard "Wire" library enables the Arduino internal pullups. This is wrong, but it does it and there's no option to disable it.

Solutions: a) Do digitalWrite(SCL,LOW)/digitalWrite(SCL,LOW) after you call Wire.begin() b) Hack the wire library to change this.

Thanks for the responses.

Doesn't this harm the arduino and the barograph module? If the SDA and SCL pins are pulling the barograph supply up from 3.3 to 5 volts, which is in turn pulling the arduino 3.3 volt supply up to 5 volts, isn't something going to start smoking soon?

a) Do digitalWrite(SCL,LOW)/digitalWrite(SCL,LOW) after you call Wire.begin()

This seems like the simplest solution, but isn't this like grounding the pins? how will I2C work over these pins if I've set them both to 0?

thanks

Doesn't this harm the arduino

No.

..... barograph module

Yes if it is a 3v3 device you are giving it signals greater than the supply voltage, always a bad idea.

but isn't this like grounding the pins

No it is turning off the pull up resistors. The question is will they stay off. I would recommend https://github.com/DSSCircuits/I2C-Master-Library

BigusDickus:

a) Do digitalWrite(SCL,LOW)/digitalWrite(SCL,LOW) after you call Wire.begin()

This seems like the simplest solution, but isn't this like grounding the pins?

Not if they're inputs...

fungus:

BigusDickus:

a) Do digitalWrite(SCL,LOW)/digitalWrite(SCL,LOW) after you call Wire.begin()

This seems like the simplest solution, but isn't this like grounding the pins?

Not if they're inputs...

Doing a 'digitalWrite()' implies they are outputs doesn't it?

a) Do digitalWrite(SCL,LOW)/digitalWrite(SCL,LOW) after you call Wire.begin()

I've tried the following.....

  pinMode(20, OUTPUT);      // sets the digital pin as output
  pinMode(21, OUTPUT);      // sets the digital pin as output
  digitalWrite(20,LOW);
  digitalWrite(21,LOW);

Immediately after wire.begin(), but the pins persistently remain at 5 volts. A little bit of experimentation (no libraries, and no barograph chips) seems to indicate that although pins 20 and 21 are described as dual purpose (digital IO and I2C) the digitalWrite() function doesn't seem to do anything (or maybe I'm doing something wrong?)

I will investigate the I2C master library as suggested.

thanks for everyone's input.

Some further data for information.....

I've just tried all my old BMP080 modules (all the one I thought I'd cooked) on a Duemilanove, and they all work fine, so I guess this indicates the issues are not related to either my libraries, or the barograph modules, but are something to do with using a Mega.

On a related issue, on the Duemilanove the I2C pins are dual purpose Anlogue Input / SDA&SCL pins, but on the Mega they are dual purpose Digital I/O and SDA&SCL pins. How does one library (Wire) work on two different types of pins?

Thanks

digitalWrite() function doesn't seem to do anything (or maybe I'm doing something wrong?)

Yes you are doing the digital write before you call wire begin you were told to do it after. This is because it will then be an input and a digital write to a pin whose mode is an input controls the internal pull up resistor.

you are doing the digital write before you call wire begin

this is a typo on my part, I was doing it after Wire.Begin() as suggested.

I had also tried striping out all hardware and libraries and just using the lines....

pinMode(20, OUTPUT);      
  pinMode(21, OUTPUT);      
  digitalWrite(20,LOW);
  digitalWrite(21,LOW);

To set the pins to low, but it doesn't seem to work, hence my doubts about these pins being dual purpose.

Cheers

this is a typo on my part, I was doing it after Wire.Begin() as suggested.

So this code is a typo?

 pinMode(20, OUTPUT);      // sets the digital pin as output
  pinMode(21, OUTPUT);      // sets the digital pin as output
  digitalWrite(20,LOW);
  digitalWrite(21,LOW);

Do not set the pins to be an output.

To set the pins to low, but it doesn’t seem to work, hence my doubts about these pins being dual purpose.

They are dual purpose if that fails to set the output to LOW then you have fried those pins in the output mode.

You are obviously failing to understand this so why not use a library?

BigusDickus: Doing a 'digitalWrite()' implies they are outputs doesn't it?

As it happens, no such thing. It writes to the output register inside the chip, but if it is set as an input, that does nothing in itself.

What does happen is that if the output register is set high and it is defined as an input, it enables a weak pull-up of the order of 10k ohms.

If however, the "Wire" library insists on writing the output high on calls other than "Wire.Begin()", then the pull-up will be enabled.

OTOH, given that it supplies no more than half a milliamp, it is rather unlikely to do any damage. You could clamp the lines with a pair of red LEDs each.

You are obviously failing to understand this

Yes.

Posts on this thread have suggested that I need to set the SDA/SCL pins to low using digitalWrite(20,LOW), after wire.begin().

Before I do a digitalWrite() don't I need to set the pinMode()?

why not use a library?

I currently have a library to control my barograph, it uses the Wire.h library and works fine on a Duemilanove, but not on a mega. I am currently re-writing it to use the I2C library as per some earlier suggestions.

Posts on this thread have suggested that I need to set the SDA/SCL pins to low using digitalWrite(20,LOW), after wire.begin().

NO NO NO!

They have said do a digital write low to these pins once they have been set to be an input. You have been told that writing to a pin that is defined as an input turns on / off the internal pull up resistor. No on ever said set the pins LOW.

Ok, I think some of this is slowly sinking in!

Some of the subtleties of the previous posts were missed by me on the first reading (and the 2nd and 3rd to!)

In my naivety I thought that doing a

digital write low to these pins

meant

set the pins LOW

. Obviously not. I now realize that digitalWrite() can behave in different ways depending on how the pin is configured.

Thanks

There is a bit of code in the wire library, which you need to delete.

Actually, it isn't in Wire, it is in a file calle twi.c

Here is the code ( the last two lines )

void twi_init(void)
{
  // initialize state
  twi_state = TWI_READY;
  twi_sendStop = true;     // default value
  twi_inRepStart = false;
  
  // activate internal pullups for twi.
  //digitalWrite(SDA, 1);
  //digitalWrite(SCL, 1);

Ok, I think I have finally understood the issues here, but I still haven't managed to get a solution. Here's what I've tried.... a) I've edited the file twi.c to comment-out the following two lines.....

//digitalWrite(SDA, 1);
  //digitalWrite(SCL, 1);

b) I have re-written my barograph library to use the I2C.h library instead of the Wire.h library.

Neither solution has worked so far. The symptoms are as follows, if I connect the BMP180 to the gnd and 3.3.v pins then (as expected) the measured voltage is 3.3 volts. As soon as I connect either the SDA or SCL pins then the measured voltage across the supply is pulled up to about 4.5 volts. The problem occurs on a mega, but not a Duemilanove. I've tried this with several barograph modules, and I get the same problem with all of them (a couple of these devices do appear to still work even when the supply is pulled up to 4.5 volts).

Is it possible I have fried the pull-up resistors? If so, how can I test this? I have tried two different megas (same results with both) and the I2C interface seems to still work, so I guess not.

Incidentally, I also tried a 3rd solution, rather than just commenting out the digitalWrite() lines shown above, I set them to zero instead of one, but this made no difference.

thanks for your patience guys, any further suggestions?

cheers

The problem occurs on a mega, but not a Duemilanove.

This is because the mega has hardware pull up resistors on them. Time to get your soldering iron out.

Time to get your soldering iron out.

Don't think my eyesight is up to de-soldering a mega. Maybe I'll just stick to the Duemilanove.

Cheers