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

NP2 & Sparkfun BMP085 (I2C)

I2C BMP085 NP2 Sparkfun

  • Please log in to reply
8 replies to this topic

#1 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 22 March 2014 - 08:53 AM

Hi everyone, 

 

(I asked for help in the previous topic, but no reaction, probably because of the solved state of that topic? So I place it in a new one!)

 

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!

Edited by Tobias Vandenbempt, 25 April 2014 - 07:19 AM.


#2 wendo

wendo

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 23 March 2014 - 03:38 AM

You don't seem to have any pullup resisters on the I2C bus. Could that be the issue?



#3 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 23 March 2014 - 07:52 AM

You don't seem to have any pullup resisters on the I2C bus. Could that be the issue?

I believe they are already on the BMP085 Sensor, you can see them on the picture. Unless I'm completely mistaken?



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 March 2014 - 07:49 AM

Hi tobiasv,

At first glance, your wiring looks alright. The pull-ups are 4.7K (and you have shorted the solder jumper on the breakout...so they should be working as pull-ups). That's a little higher value than we like, but it should work with the 5V supply.

Have you tried using a slower I2C speed?

Also...what line of code in the project does this crash on, exactly? If we can reduce this down a simpler sample, we may be able to help out from this side.

Chris

#5 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 25 March 2014 - 08:04 AM

Hi tobiasv,

At first glance, your wiring looks alright. The pull-ups are 4.7K (and you have shorted the solder jumper on the breakout...so they should be working as pull-ups). That's a little higher value than we like, but it should work with the 5V supply.

Have you tried using a slower I2C speed?

Also...what line of code in the project does this crash on, exactly? If we can reduce this down a simpler sample, we may be able to help out from this side.

Chris

I'm not able to test the slower I2C Speed atm, not sure how to, even if I could. ;).

 

But I do know it now crashes in the IC_BMP085 Class in the method CalculateTemperature() on the following line: 

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

This was caused by x1 + md being 0, so DivideByZero Exception. 

 

I'll test the slower I2C, once I know how, tomorrow. 

 

Thanks for looking at the issue ! :)

Tobias



#6 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 31 March 2014 - 02:38 PM

Hi tobiasv,

At first glance, your wiring looks alright. The pull-ups are 4.7K (and you have shorted the solder jumper on the breakout...so they should be working as pull-ups). That's a little higher value than we like, but it should work with the 5V supply.

Have you tried using a slower I2C speed?

Also...what line of code in the project does this crash on, exactly? If we can reduce this down a simpler sample, we may be able to help out from this side.

Chris

Is this the I2C speed setting ? 

 public IC_BMP085(Byte Address, int speed = 400)
            : base(new I2CDevice.Configuration(Address, speed)) // maybe 400khz
        {
            Thread updateThread = new Thread(Update);
            updateThread.Priority = ThreadPriority.Lowest;
            updateThread.Start();
        }
 
It used to be like this:  
public IC_BMP085(Byte Address)
            : base(new I2CDevice.Configuration(Address, 400)) // maybe 400khz
        {
            Thread updateThread = new Thread(Update);
            updateThread.Priority = ThreadPriority.Lowest;
            updateThread.Start();
        }

I tried it at 200. But no luck, keeps failing at the same line in CalculateTemperature()



#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 April 2014 - 02:39 PM

Hi Tobias,

On your I2C issue...try reducing the speed to 100 kHz. Get rid of the threading temporarily, and create a simple app which just reads/writes a few bytes--to get I2C working. Then you can add back in all the threading and other fancy features.

Also: double-check the I2C address of the device.

Chris

#8 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 24 May 2014 - 05:31 PM

I tried the 100 Khz setting, tried different addresses, tried creating a new solution with a simple setup to test the I2C communication.

However still bumping into errors.
This time it fails on the initialization of I2CDevice class in the MultiI2C base class. 

 

I created a rar file with the solution in it, don't know if it'll help. 

 

Download : http://bit.ly/SwLUGY

 

Sigh! :)



#9 tonofsteel

tonofsteel

    Member

  • Members
  • PipPip
  • 14 posts

Posted 24 May 2014 - 07:14 PM

You should solder pin headers on your BMP board and plug into the breadboard directly.  The way you are using jumper wires to pin the board to the breadboard and hope a connection is going to be made is asking for trouble IMHO. 

 

With the values being zero it might be that you are not getting the data read back correctly due to a bad connection.  Your issue brings up a good point for that library, there should be checking for values read back as zero and some way to handle this case in code.  IE detect and indicate to the user that there is something wrong with the sensor reading. 

 

I am using the BMP180 and according to the specs it should have the same interface as the BMP085.  I am actually using libraries written for the 085 with the 180 and it is working so far.

 

The post that solved the problems for me using it with the NP2 were (this looks like the exact same one you linked to):

 

http://forums.netdui...-barometer-i2c/

 

Specifically I needed to use this code for it to even start working:

 

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( );

 

And then used NooM's libraries for the rest:

Attached Files

 

 

It looks like from your post you are using these libraries but have you included the code to get the I2C working correctly as one of the first lines in main?

 

Since it looks like the I2C fix code might be required often I included it as another module:

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace BSOF.Netduino.Common
{
    public static class I2C
    {
        public static void MainStartupI2CDeviceFix()
        {
            OutputPort p = new OutputPort(Pins.GPIO_PIN_SDA, true);
            p.Write(false);
            p.Dispose();
        }
    }
}

Now My main():

public static void Main()
{
    I2C.MainStartupI2CDeviceFix();

    SparkLCD myLCD = new SparkLCD(SerialPorts.COM1);
    myLCD.Clear();
    myLCD.Write(SparkLCDCommands2x16.SetBacklightBrightness(157));
            
    IC_BMP085 press = new IC_BMP085(0x77);

    while (true)
    {
        float temp = press.temperature;
        string formattedtemp = temp.ToString("F2");

        myLCD.Clear();
        myLCD.WriteString("Temperature:    " + formattedtemp);
        Debug.Print("Temperature:    " + formattedtemp);
        Thread.Sleep(2000);
    }
}

I did not change anything inside the libraries so I am still at 400 as the default clock rate KHz in the posted libraries.  This code is confirmed all working for me.  I know without using the I2C fix before instantiating the BMP085 class I will get problems for sure.







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.