Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:33 19 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : [Example Code] Read Temperature Sensor LM75BD (i2c)

Author Message
Calli
Regular Member

Joined: 20/10/2021
Location: Germany
Posts: 74
Posted: 01:09pm 29 Oct 2021
Copy link to clipboard 
Print this post

The LM75BD is a cheap temperature sensor I had around in my boxes. This is a slightly better version from the LM75 which has a resolution of 0.5K as opposed to the "B" which is 0.125K resolution.

Datasheet: https://www.nxp.com/docs/en/data-sheet/LM75B.pdf



' Read LM75BD(!) this has 0.125 deg. C resolution! LM75 has 0.5 deg.C
' for LM75 just read ONE byte and set a(1)=0 (untestet!)

' Set accordingly to your schematic
SetPin gp8, gp9, I2C
I2C open 100, 100   ' 100kHz, 100ms timeout

addr = &h4D     'Address of your chip, it is &h48 by default!

Dim As Integer a(2) ' holds the data

Do
 I2C write addr, 0, 1, &H00        ' ask for &H00-temperature register
 I2C read  addr, 0, 2, a()         ' read back 2 bytes (11bits used)
' some testvalues from datasheet
'  a(0)=&B01110
'  a(1)=&B101
'  a(0)=&B11001001
'  a(1)=&B001

 temp = (a(0)<<3 Or a(1)>>5)     ' 2 complement 11bit
 If MM.I2C=0 Then                ' ack?
   If (a(0) And &B10000000) Then ' negative value?
     Print "Temp.: "; Str$(-(2048-temp)*0.125,-4,1); " deg. C"
   Else
     Print "Temp.:  ";Str$(temp*0.125,-4,1); " deg. C"
   EndIf
 EndIf
 Pause 1000
Loop

I2C CLose    ' hrmp...


Please comment if you see errors or have suggestions for the binary calculations.

Best,
Carsten
Edited 2021-10-29 23:09 by Calli
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025