| 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 |