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

LM75 (I2C temperature sensor)


Best Answer alesbedac, 26 March 2014 - 07:21 PM

Hi All,

problem solved, lot of thanks to GRISMO and MBROSSETT

Problem was with address pins ground and misssing resistors.

 

So how to work with LM75 ...short desciption :
 

1) connect SDA -> resistor 2K2 -> 3V(or 5V)

2) connect SCL -> resistor 2K2 -> 3V(or 5V)

3) Address pins must be always connected (to ground or VCC]

4) use program on TOP

 

 

Really nice working, again thanks to GRISMO and MBROSSETT.

Go to the full post


  • Please log in to reply
9 replies to this topic

#1 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 25 March 2014 - 01:00 PM

Hi All,

 

i am trying to get temperature using LM75, this sensor has I2C interface.

But its not working, i have atached code, this code i found somewhere on internet like working code.
Another example how to get temperature from sensor i didnt get.

Please, can anybody help me ?

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace LM75_Tutorial
{
  
    public class Program
    {     
        public static void Main()
        {
            const byte DeviceId = 0x49; //address
            const byte ClockRateKHz = 59; //kHz
            const int transactionTimeout = 1000; //1 sec.
            const byte halfMask = 0x80; //0.5 st.C, 0b10000000

            while (true)
            {
                I2CDevice device = null;                

                try
                {
                    device = new I2CDevice(
                        new I2CDevice.Configuration(DeviceId, ClockRateKHz));

                    byte[] writeBuffer = { 0x00 };
                    byte[] readBuffer = new byte[2];

                    I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] 
                        { 
                            I2CDevice.CreateWriteTransaction(writeBuffer) 
                            , I2CDevice.CreateReadTransaction(readBuffer)
                        };
                    
                    if (device.Execute(action, transactionTimeout) == 3)
                    {
                        float temperature = readBuffer[0] +
                            (((readBuffer[1] & halfMask) != 0) ? 0.5f : 0f);

                        Debug.Print(temperature.ToString());
                    }
                    else
                        Debug.Print("LM75 is not responding...");
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                }
                finally
                {
                    device.Dispose();
                    Thread.Sleep(1000);
                }
            }
        }


    }
}



#2 gismo

gismo

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 25 March 2014 - 01:03 PM

knowing nothing about your device...your code looks ok. So, I'll ask the question that's always asked: do you have pull-up resistors connected to the SDA and SCL lines?



#3 mbrossett

mbrossett

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts

Posted 25 March 2014 - 02:09 PM

Can you describe what is happening? ...are you seeing "LM75 is not responding..." printed out, or are you getting an exception thrown, or is the temperature reading not right? As gismo said verify pull-up resistors and also check the address of the device (is A0 pulled HIGH, and A1, A2 pulled LOW?).



#4 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 25 March 2014 - 06:43 PM

Can you describe what is happening? ...are you seeing "LM75 is not responding..." printed out, or are you getting an exception thrown, or is the temperature reading not right? As gismo said verify pull-up resistors and also check the address of the device (is A0 pulled HIGH, and A1, A2 pulled LOW?).

I am not using any pull-up resistors, i am using ND2+

On The same ND2+ is working LCD with I2C interface...without pullup resistor.

 

In which case is important to use pull up resistor ?

 

 

I have used all address combination

A0, A1 and A2 are not soldered, so i think the address if 49, but i have tried last address 4F, because i wasnt sure..so it must be the last or first address.

1001000 = 40

...
1001111 = 4F

But in the debug is displayed ....LM75 is not responding...



#5 gismo

gismo

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 25 March 2014 - 08:22 PM

I bet that LCD has pull-ups built into it. With a volt meter, check voltage of SDA and SCL. If they are high, pullups are built in.

 

All I2C needs a pull-up on the bus. If so, just connect the LM75 to the same bus as the LCD at the same time. OR just connect the LM47 with pull-up resistors. 4.7kOhm to start.



#6 mbrossett

mbrossett

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts

Posted 25 March 2014 - 08:23 PM

I have used all address combination

A0, A1 and A2 are not soldered, so i think the address if 49, but i have tried last address 4F, because i wasnt sure..so it must be the last or first address.

 

Ah, I believe that is your problem. See page 4 of the datasheet...

 

http://datasheets.ma.../en/ds/LM75.pdf

 

It states that the address pins A0, A1, and A2 should "not be left unconnected". Tie them all to ground and set the address of the device to be 0x48. Hopefully that will work for you.

 

As far as the pull-ups go, you are probably fine if the pull-up resistors exist somewhere on the bus...i.e. on the LCD module. Especially since the I2C bus is working for the LCD.

 

Keep us posted.



#7 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 26 March 2014 - 11:08 AM

Ah, I believe that is your problem. See page 4 of the datasheet...

 

http://datasheets.ma.../en/ds/LM75.pdf

 

It states that the address pins A0, A1, and A2 should "not be left unconnected". Tie them all to ground and set the address of the device to be 0x48. Hopefully that will work for you.

 

As far as the pull-ups go, you are probably fine if the pull-up resistors exist somewhere on the bus...i.e. on the LCD module. Especially since the I2C bus is working for the LCD.

 

Keep us posted.

 

oh i see that for now...Do not leave unconnected....i will check it...then i give back feedback



#8 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 26 March 2014 - 11:09 AM

I bet that LCD has pull-ups built into it. With a volt meter, check voltage of SDA and SCL. If they are high, pullups are built in.

 

All I2C needs a pull-up on the bus. If so, just connect the LM75 to the same bus as the LCD at the same time. OR just connect the LM47 with pull-up resistors. 4.7kOhm to start.

i will check it...then i give back feedback



#9 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 26 March 2014 - 07:21 PM   Best Answer

Hi All,

problem solved, lot of thanks to GRISMO and MBROSSETT

Problem was with address pins ground and misssing resistors.

 

So how to work with LM75 ...short desciption :
 

1) connect SDA -> resistor 2K2 -> 3V(or 5V)

2) connect SCL -> resistor 2K2 -> 3V(or 5V)

3) Address pins must be always connected (to ground or VCC]

4) use program on TOP

 

 

Really nice working, again thanks to GRISMO and MBROSSETT.



#10 mbrossett

mbrossett

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts

Posted 26 March 2014 - 09:20 PM

Awesome, glad I could help! Also, please mark this topic as "answered" if you can.






1 user(s) are reading this topic

0 members, 1 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.