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

MCP9808 Temperature Sensor (I2C)


  • Please log in to reply
5 replies to this topic

#1 thunderbird

thunderbird

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 May 2014 - 07:29 PM

Hello!

 

I'm trying to read the temperature from a MCP9808. The sensor is on a breakout board from Adafruit, so pull-up resistors are already built in. I have tried with 3.3 and 5V. The problem is that I get no error, but the read data is always 0.

 

My code:

Byte[] rx = new Byte[2];
// 0x18 is the default address of the sensor
// I have tried 100 and 400kHz
I2CDevice.Configuration config = new I2CDevice.Configuration(0x18, 400);
I2CDevice sensor = new I2CDevice(config);

I2CDevice.I2CTransaction[] settings = new I2CDevice.I2CTransaction[]
{
    // 0x05 is the register for the temperature
    // I have also tried register 0x07 which should get the device ID
    I2CDevice.CreateWriteTransaction(new byte[] { 0x05 })
};

I2CDevice.I2CTransaction[] rd = new I2CDevice.I2CTransaction[]
{
    I2CDevice.CreateReadTransaction(rx)
};

sensor.Execute(settings, 1000);

while (true)
{
    sensor.Execute(rd, 1000);
    // always "00"
    Debug.Print(rx[0].ToString() + rx[1].ToString());
    Thread.Sleep(2000);
}

Can you give me a hint what I'm doing wrong?

 

I got the register numbers from the Arduino library: https://github.com/a...hive/master.zip

 

Thank you very much!



#2 thunderbird

thunderbird

    New Member

  • Members
  • Pip
  • 4 posts

Posted 27 May 2014 - 06:10 PM

I had SCL and SDA connected to A4 and A5 as told in several (old?) documents. But correct is SCL to SC and SDA to SD, at least for the netduino plus 2 with the latest firmware. Sorry for asking!



#3 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 29 May 2014 - 04:30 AM

Curious how you tried 5v and 3.3v?   I have a 3.3v 9dof stick that will only work when the analyser is attached and powered on.

 

https://www.sparkfun.../products/10724

 

It has pullups built in as well.



#4 thunderbird

thunderbird

    New Member

  • Members
  • Pip
  • 4 posts

Posted 02 June 2014 - 06:37 AM

Hi Spiked,

 

I just tried connecting it to 3.3V after it did not work on 5V.



#5 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 02 June 2014 - 06:44 AM

Ok, I apologize for my lack of hardware knowledge. I had recently been told by 'an i2c expert' that the i2c clock & data was at 3.3 or 5v.  I've since learned to not trust an expert. I was confused / misled.

 

My problem appears to be that if the analyser is attached it MUST be powered.  But part of me also wonders about ground loops, and maybe that is the issue.  I sure wish us software types were not forced into hardware, there is a reason I avoided it for 60 years.



#6 thunderbird

thunderbird

    New Member

  • Members
  • Pip
  • 4 posts

Posted 03 June 2014 - 06:16 PM

No need to apologize! I'm also no hardware guy, but I was an interesting experience. Soldering and bit-shifting is a contrast to high-level development with mighty frameworks. :)

 

I have read the specifications of your 9dof stick: it should run with 3.3V. In the comments other people had the same problem. A solution could be to add 1uF capacitors in parallel to the existing 0.1uF caps on the board. Or maybe try a lower clock frequency?






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.