Author Topic: NTC Thermistor Demo  (Read 424 times)

AndrewPratt

  • Newbie
  • *
  • Posts: 9
  • Location: Winnipeg, MB
    • View Profile
Re: NTC Thermistor Demo
« on: December 12, 2017, 11:09:59 am »
Update. I decided that since I only had 1 temp probe attached to the 120 I didn't need to use the resistor and pin's 0 & 6 so I swapped it over to the ground and pin7 approach with the internal pullup and it now works perfectly. This is the new code.

Define PinMode Pin7 As AnalogInputPullUp Alias USP10972_VOLTAGE

Class ThermistorTheThings
   
    Const USP10972_BETA As Integer = 3892
    Const USP10972_R25 As Integer = 10000 '10kOhm
    Const USP10972_DIVIDER_R1 As Integer = 100000 '100kOhm
   
    Shared USP10972 As NTCTermistor
   
    Shared Event Boot() 
        USP10972 = New NTCTermistor(USP10972_BETA, USP10972_R25)
    End Event
   
    Shared Event measureTemperature() RaiseEvent Every 10 Seconds
        Device.EnableOpamp()
        Thread.Sleep(10000) 
        Dim thermistorResistance As Float = USP10972_DIVIDER_R1 * (1 / ((Device.BatteryVoltage().ToFloat/ USP10972_VOLTAGE.ToFloat) - 1)) 
        Device.DisableOpamp()
       
        Dim battShort As Short = Device.BatteryVoltage()
        Dim battFloat As Float = battShort / 1000
        Dim battString As String = battFloat.ToString()
        Dim tempTMP102string As String = Temperature.GetTemp().ToString
        Dim tempPstring As String = USP10972.TemperatureCFromResistance(thermistorResistance).ToString         
       
        Dim LosantTopic As String = "losant/myDeviceID/state"
        Dim losantPayload As Json = New Json       
        Dim mcJson As Json = New Json
       
        mcJson.Add("probeTemp", tempPstring)
        mcJson.Add("temperature", tempTMP102string)
        mcJson.Add("batteryVoltage", battString)
       
        losantPayload.Add("data", mcJson)
        Lplan.Publish(LosantTopic, losantPayload.ToListOfByte)
    End Event
End Class
« Last Edit: December 13, 2017, 11:44:53 am by AndrewPratt »