Author Topic: NTC Thermistor Demo  (Read 477 times)

AndrewPratt

  • Newbie
  • *
  • Posts: 9
  • Location: Winnipeg, MB
    • View Profile
Re: NTC Thermistor Demo
« on: December 12, 2017, 02:45:10 pm »
Thanks Josh I now have it working on the Demo 205 as well using the following.


Define PinMode Pin0 As AnalogInput Alias USP10972_VOLTAGE
Define PinMode Pin6 As DigitalOutput Alias USP10972_DIVIDER_ENABLE

Class ThermistorTheThings
   
    Const USP10972_BETA As Integer = 3892
    Const USP10972_R25 As Integer = 10000 '10kOhm
    Const USP10972_DIVIDER_R1 As Integer = 10000 '10kOhm
   
    Shared USP10972 As NTCTermistor
   
    Shared Event Boot()
        USP10972_DIVIDER_ENABLE = False
        USP10972 = New NTCTermistor(USP10972_BETA, USP10972_R25)
    End Event
   
    Shared Event measureTemperature() RaiseEvent Every 1 Hours
        USP10972_DIVIDER_ENABLE = True
        Device.EnableOpamp()
        Thread.Sleep(10000) 
        Dim thermistorResistance As Float = USP10972_DIVIDER_R1 * (1 / ((Device.BatteryVoltage().ToFloat/ USP10972_VOLTAGE.ToFloat) - 1))
        USP10972_DIVIDER_ENABLE = False
        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 12, 2017, 04:33:22 pm by AndrewPratt »
Like Like x 1 View List