Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino 2 and the Adafruit BMP085 Barometer (I2C)

i2c BMP085 Netduino 2

Best Answer sgraves , 28 September 2013 - 02:38 AM

I can confirm the exact same behavior using Adafruit i2c OLED. I have to disconnect / reconnect the SDA pin for it to work properly. I've been fighting this for over an hour now until I ran across this post.

 

Actually, to work around it, I just do the following as the first part of Main():

            OutputPort p = new OutputPort(Pins.GPIO_PIN_SDA, true);            p.Write(false);            p.Dispose( );
Go to the full post


  • Please log in to reply
17 replies to this topic

#1 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 30 August 2013 - 06:01 PM

Yes, I'm a noob.  Man, I'm glad I got that off my chest.   <_<

 

This is the first time I've attempted to hook up a sensor using I2C and I decided to start with this barometer from Adafruit.com: http://www.adafruit.com/products/391

 

Anyway (11 hours later), what I thought would be simple turned out to be not so simple.  Here is what I am facing.

 

I have:

- A Netduino 2 running Firmware 4.2.2.1

- A Barometric Pressure sensor from Adafruit (BMP085)  http://www.adafruit.com/products/391  (datasheet: http://www.adafruit....85-DS000-06.pdf)

- A headache

- And the following code:

 

            byte[] Addr = new byte[2];            Addr[0] = 0xF4;            Addr[1] = 0x34;            byte[] TxBuff = new byte[4];            byte[] RxBuff = new byte[4];            I2CDevice.Configuration I2C_Configuration = new I2CDevice.Configuration(0x77, 400);            I2CDevice I2C1 = new I2CDevice(I2C_Configuration);            I2CDevice.I2CTransaction[] WriteTran = new I2CDevice.I2CTransaction[]             {                I2CDevice.CreateWriteTransaction(Addr),                I2CDevice.CreateWriteTransaction(TxBuff)            };            I2CDevice.I2CTransaction[] ReadTran = new I2CDevice.I2CTransaction[]            {                I2CDevice.CreateWriteTransaction(Addr),                I2CDevice.CreateReadTransaction(RxBuff)            };            while (true)            {                                int iWriteCount = I2C1.Execute(WriteTran, 1000);                Debug.Print("Write Count: " + iWriteCount.ToString());                Thread.Sleep(200);                int iReadCount = I2C1.Execute(ReadTran, 1000);                Debug.Print("Read Count: " + iReadCount.ToString());                string ReadOut = new string(System.Text.Encoding.UTF8.GetChars(RxBuff));                Debug.Print("EEPROM CONTENT:" + ReadOut);                                Thread.Sleep(200);            }
 
This is one version of a routine of a whole bunch that I've tried, but all result in the same thing.  "0" gets returned from the "Execute()" method whether I try to read or write.  If I set the timeout value on the execute method to Timeout.Infinite, it will just hang there forever, which explains why I'm getting nothing back.  (because it's timing out after 1000ms)
 
The sample Arduino libraries write to the address "0x77" to talk to this chip.  Sparkfun puts out a breakout board just like this one, also using the BMP085 which also refers to 0x77.  Having said that, the data sheet (from the link above) talks about a "Device and register address" on page 17, which admittedly, I don't understand how it fits in to all of this or if I even need to worry about it.  They talk about addresses 0xEE and 0xEF for reading and writing?  I'm lost here.  Forgive me if this is a irrelevant/wasted paragraph.
 
Okay, so...  as far as pins go.  Here's what I did:
Sensor Pin VIn --> Netduino Pin 5V
Sensor Pin GND --> Netduino Pin GND
Sensor Pin SDA --> Netduino Pin SDA
Sensor Pin SCL --> Netduino Pin SCL
 
Seems logical, but did I mess this up?  Arduino has analog pins for I2C, right?  Netduino is not the same way, is it?  
 
Sorry for the rant.  Just trying to get it all out there.
 
If anyone can see any red flags or anything that doesn't look right, I am all ears.
 
Thanks so much!
 

 

 



#2 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 31 August 2013 - 06:39 AM

I am starting to wonder if anyone has ever gotten the Netduino 2 and the BMP085 to work over i2c.  Seems to be a weird combination out there on the web.  Hmm.



#3 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 31 August 2013 - 01:29 PM

your code doesent look correct.

also, has your sensor pullups? if not you have to add 4.7kohm ones

 

 

ill add my classes, use them, i used it, they work.

 

...

IC_BMP085 press;

ress = new IC_BMP085(0x77);

 

...

 

 void print()   {   String logString =   "pressure: " + press.pressure + " " +   "altitude: " + press.altitude.ToString("F1") + " " +   "free mem: " + Debug.GC(false);   Debug.Print(DateTime.Now + ": " + logString);

}

Attached Files



#4 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 01 September 2013 - 06:14 AM

Okay.  I am going to assume your code is good.  Still returning 0's for all values.

 

I did not include pull-ups, because I read this one the adafruit product site:

"The sensor is soldered onto a PCB with a 3.3V regulator, I2C level shifter and pull-up resistors on the I2C pins. "

 

Are you saying I still need to add them anyway?

I will try this regardless, but...  you think it may be a misprint?  That is, did you add them yourself?

 

Thanks, Noom!  



#5 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 02 September 2013 - 12:38 PM

it really shouldnt return 0's. if it has pullups on their board, than you dont need one.

 

maybe upgrade the a newer firmware version of your netduino. iirc there were i2c problems before 4.2.2.2



#6 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 02 September 2013 - 03:11 PM

Man, I do not have Windows 7 installed, but I am totally following what you're saying.

Looks like I have some work to do before I can proceed.

 

You've pointed me in the right direction, NooM!  Thank you!



#7 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 02 September 2013 - 11:35 PM

Okay, I have updated to Windows 7, NETMF 4.3, Visual Studio 2012 and the Netduino Firmware 4.3 Beta.  It didn't make a difference by itself, but then I stumbled upon something that makes no sense.  I'm hoping someone can explain this to me.

 

Using the code that NooM was nice enough to provide, Visual Studio spit out this in the output window upon the Netduino booting up:

 

06/01/2011 00:00:12: pressure: 0 altitude: 0.0 free mem: 81912
06/01/2011 00:00:14: pressure: 0 altitude: 0.0 free mem: 80280
06/01/2011 00:00:16: pressure: 0 altitude: 0.0 free mem: 80472
06/01/2011 00:00:19: pressure: 0 altitude: 0.0 free mem: 80628
 
If I disconnect the SDA pin while it's running, then reconnect it, I get this output:
06/01/2011 00:00:59: pressure: 96033 altitude: 450.2 free mem: 84624
06/01/2011 00:01:01: pressure: 96029 altitude: 450.6 free mem: 84624
06/01/2011 00:01:03: pressure: 96035 altitude: 450.0 free mem: 84396
06/01/2011 00:01:05: pressure: 96041 altitude: 449.5 free mem: 84396
06/01/2011 00:01:07: pressure: 96035 altitude: 450.0 free mem: 84624
06/01/2011 00:01:09: pressure: 96045 altitude: 449.2 free mem: 84624
06/01/2011 00:01:11: pressure: 96036 altitude: 449.9 free mem: 84396
06/01/2011 00:01:13: pressure: 96042 altitude: 449.4 free mem: 84624
 
Can anyone explain why I need to disconnect the SDA pin and then reconnect it in order to get values?
This works consistently, and I haven't been able to read values any other way.


#8 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 September 2013 - 04:33 AM

i meant 4.2.2.2 not the 4.3 beta :D



#9 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 03 September 2013 - 05:15 AM

Hahahahahaha.  WTF did I just do??   :blink:

 

Okay.  This sounds worse than it is.  I will try out 4.2.2.2 on my original development machine and report back.

 

Thanks!



#10 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 03 September 2013 - 08:13 AM

So, I put everything back the way it was, only updated the firmware to 4.2.2.2.  It actually behaves the same say.  All values report 0 until I disconnect and then reconnect the SDA pin while it's running.

 

So my last question still stands, I suppose.  Has anyone ever run into this problem?  Any thoughts on what might cause this?

I'm at a total loss, and almost ready to scrap this Netduino.  

 

Thanks in advance.



#11 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 September 2013 - 04:31 PM

damn :( i thought its fixed in that version :(

 

it works fine with netduino v1 versions (iam using the mini, no problems there with i2c,spi and uart, but other bugs :D )



#12 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 03 September 2013 - 05:13 PM

Hahaha.  You mean an open source platform has other bugs, too?? :D

 

I do have a Netduino Mini sitting on my shelf that I was going to tackle once I got my feet wet with this, but... Maybe I need to hook up this barometer to the mini to isolate the problem being with the Netduino 2.  At least then I would know.

 

NooM, do you have or have you ever used a Netduino 2 or +2 with i2c?  I may end up getting another one, but I don't want to go through this again.  I mean, it does work, right?



#13 joehimself

joehimself

    New Member

  • Members
  • Pip
  • 1 posts

Posted 03 September 2013 - 05:34 PM

Considering buying N2P.

I've read some posts here regarding ic2 problems and I have earmarked this particular sensor for use in my first project, so I'm very much interested in following this post.

Will this sensor work for me using ic2? Sensor problem? firmware problem? Platform problem?

 

@Danger -- could I ask you to be sure to post whether or not you get this problem resolved?

Many thanks and good luck.



#14 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 04 September 2013 - 06:43 AM

no i dont own one, and never have.

 

but i was active a lot and saw a lot of that i2c stuff, but from what i know it got fixed in 4.2.2.2, well doesent look like :(



#15 sgraves

sgraves

    Member

  • Members
  • PipPip
  • 16 posts

Posted 28 September 2013 - 02:34 AM

no i dont own one, and never have.

 

but i was active a lot and saw a lot of that i2c stuff, but from what i know it got fixed in 4.2.2.2, well doesent look like :(

 

I can confirm the exact same behavior using Adafruit i2c OLED. I have to disconnect / reconnect the SDA pin for it to work properly. I've been fighting this for over an hour now until I ran across this post.



#16 sgraves

sgraves

    Member

  • Members
  • PipPip
  • 16 posts

Posted 28 September 2013 - 02:38 AM   Best Answer

I can confirm the exact same behavior using Adafruit i2c OLED. I have to disconnect / reconnect the SDA pin for it to work properly. I've been fighting this for over an hour now until I ran across this post.

 

Actually, to work around it, I just do the following as the first part of Main():

            OutputPort p = new OutputPort(Pins.GPIO_PIN_SDA, true);            p.Write(false);            p.Dispose( );

  • jmjobin likes this

#17 Danger

Danger

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationCalifornia, USA

Posted 10 October 2013 - 02:18 AM

sgraves, you totally did it!  Thanks so much for posting this workaround.

 

It's totally weird that you have to pull something like this to get it to work right, but... after this many hours of trying stuff, I'll take it!

 

Thanks, again!



#18 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 07 March 2014 - 11:55 AM

Hi everyone, 

 

I tried to take a shot at this too. I've got a Netduino Plus 2 too( :)), running NETMF4.2.
Borrowing your code I tried it like this:

     public static void NetduinoForumsMethod2()
        {
            IC_BMP085 press;
            press = new IC_BMP085(0x77);
            while (true)
            {


                var logString = "pressure: " + press.pressure + " " + "altitude: " + press.altitude.ToString("F1") + " " + "free mem: " + Debug.GC(false); Debug.Print(DateTime.Now + ": " + logString);
                Thread.Sleep(3000);
            }


        }

In the code class provided, it now crashes on 2 places.
First in the CalculateTemperature method on following line:

                x2 = mc * 2048 / (x1 + md);
                b5 = x1 + x2;


                temperature = (Single)((b5 + 8) >> 4) / 10;

This was caused by x1 + md being 0.

Trying to bypass I tried

            if (x1 + md == 0)
            {
                temperature = 0;
            }
            else
            {
                x2 = mc * 2048 / (x1 + md);
                b5 = x1 + x2;


                temperature = (Single)((b5 + 8) >> 4) / 10;
            }

This made sure the calculateTemperature method was no longer crashing. But there was a new problem waiting.

 

Second time on the following line in the CalculatePressure method

            p = (b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2);

This is caused again by a divided by zero exception, where b4 is 0.

 

Trying to bypass I tried following code:

            if (b4 == 0) p = 0; //It kept crashing here, /0 doesn't work.
            else p = (b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2);

And now it is always returning 236

 

06/01/2011 00:05:13: pressure: 236 altitude: 30344.2 free mem: 88488
06/01/2011 00:05:16: pressure: 236 altitude: 30344.2 free mem: 87744
06/01/2011 00:05:19: pressure: 236 altitude: 30344.2 free mem: 87972
06/01/2011 00:05:22: pressure: 236 altitude: 30344.2 free mem: 88716
06/01/2011 00:05:25: pressure: 236 altitude: 30344.2 free mem: 88716
06/01/2011 00:05:28: pressure: 236 altitude: 30344.2 free mem: 88488
 
Problem solving! Many crashes in code that worked with you guys.
So something wrong with my wiring? I just took some pictures of my wiring, hope it helps. 

MyHookup.png
MyHookupNP2.png
MyHookUpSensor.png

Only mind the white wires, the other ones are for my OneWire Temperature sensor. (More here)
 
I tried the wiring schema Danger provided: 
Sensor Pin VIn --> Netduino Pin 5V
Sensor Pin GND --> Netduino Pin GND
Sensor Pin SDA --> Netduino Pin SDA
Sensor Pin SCL --> Netduino Pin SCL

But my sensor shows slightly different labels. 
I did it like this:
Sensor VCC => NP2 5V
Sensor GND => NP2 GND
Sensor DA/SDA => NP2 SD
Sensor CL/SCL => NP2 SC
 
Any thing else I could have screwed up? 
 
Thanks in advance!
 
 
 






Also tagged with one or more of these keywords: i2c, BMP085, Netduino 2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.