LM75A Temperature Sensor

In this example we are going to connect from Raspberry Pi to LM75A temperature sensor.

(And at bottom there I tell of how to get it to work also on H3 based Orange Pi)

DISCLAIMER

We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry Pi.

This sensor measures temperature.

Main parameters from the sensors Data sheet:

What is special about the LM75A is that it has the possibility to configure the I2C address. By soldering low value surface mounted resistor between A1, A2, A3 and ground or VCC. Which gives you option to have up to 8 LM75A sensors running at once.

The pads to change the address are extremely small and I had only dried up solder paste for surface mounted soldering so I opted to leave them all unset to see if it would then get default address, and it did get default address of 0x48 or (72 dec), which is same as if all of them would be soldered to ground.

To give you idea of all the different addresses you could set this sensor to if soldering the pads. 

A0 A1 A2 I2C Address
GND GND GND 0x48
VCC GND GND 0x49
GND VCC GND 0x4A
VCC VCC GND 0x4B
GND GND VCC 0x4C
VCC GND VCC 0x4D
GND VCC VCC 0x4E
VCC VCC VCC 0x4F

Pieces we use in this guide:

If you are not familiar with working with a breadboard or on how to place a cobbler on the breadboard then click here bellow

Breadboard

I2C Tools

To install the I2CTools you use the following command:

sudo apt-get install i2c-tools

You need to enable the i2c bus in the Raspberry PI settings, which you can do in the Raspberry Pi user interface.


Wiring up the board:

First we solder the header pins into the brake-out board if needed. It was possible on mine to either solder the pins on front or back.

Once the board has been soldered with header pins or wires then we are ready to wire up the sensor which we do as follows:

BMP180
Raspberry PI cobbler
VIN 3.3 V
GND GND
SCL SCL (Physical pin 5)
SDA SDA (Physical pin 3)
Raspberry Pi pin layout

If you need more information about the GPIO headers on Raspberry Pi or other boards then click bellow.

Raspberry Pi Pin guideOrange Pi One Pin guideOrange Pi Pin guide for most H3 modelsOrange Pi Zero 3 Pin  guideOrange Pi 5 Plus Pin guideRock 64 Pin guide

Sanity tests in console:

After you have connected everything and made sure that wiringPI, i2ctools are installed that I2C is enabled in the Raspberry PI settings, then we are ready to do sanity tests in console, or you can run the I2C example project that comes with the I2C Plugin.

If doing it in console then you would issue command like this:

sudo i2cdetect -y 1

This should show our device at 0x40. Or if you use the example project that comes with the I2C plugin then you click Get adapters and then select the adapter and then click Scan the selected adapter this should get you 72, which converted to Hex is 0x48, same as the i2cdetect returns.  (This address will be different of course if you changed the address of the sensor by soldering the pads).

The example project that comes with the I2C Plugin, which can help you scan for the device address. It returned 72 for me which is 0x48 in hex.

If you can see your sensor on address 0x48 (or 72 dec) or which ever address you changed it to then you are ready to start coding.

The Xojo code:

Coding against this sensor was unusually simple but I still made small driver class around it, called LM75A (see download
link at bottom).

Read temperature:

Sub Pressed() Handles Pressed
  #if TargetARM and TargetLinux
    try
      // We want adapter 1 and device 0x48 (if we had all the config pads on the sensor empty)
      var htu as new LM75A(1, &h48)
      
      MessageBox(Format(htu.ReadTemperature(),"#.00") + "° C")
      
    catch ex as I2CException
      MessageBox("Error: " + ex.Message)
    end try
    
  #endif
End Sub

The small driver class:

Protected Class LM75A

Private mAdapter As I2C.Adapter

#tag Constant, Name = REG_READTEMP, Type = Double, Dynamic = False, Default = \"&h00", Scope = Private
#tag EndConstant

Sub Constructor(adapterNo as Integer, deviceId as UInt32)
  #If TargetARM And TargetLinux Then
    mAdapter = I2C.Adapter.Open(adapterNo)
    mAdapter.SetAddress(deviceId)

  #else
    #Pragma unused adapterNo
    #Pragma unused deviceId
  #Endif
End Sub

Function ReadTemperature() As Single
  #If TargetARM And TargetLinux Then
    var res as Int32 = ctype(mAdapter.ReadWord(REG_READTEMP), int32)

    res = (Bitwise.ShiftLeft(res, 8) and &hFF00) + Bitwise.ShiftRight(res, 8)

    return (res / 32.0) / 8.0
  #endif
End Function

Getting the code

You can find this example code at Example code for GPIO guides.


I got this also to work on H3 based Orange Pi running Armbian.

To get things to work on H3 based Orange Pi I had to: