mc-Module > mc-Module
NTC Thermistor Demo
AndrewPratt:
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
AndrewPratt:
Now that I have it working on the mc120 how do you suggest I port it to the 205 given that the 205 doesn't seem to support the AnalogInputPullUp?
mc-Josh:
Andrew,
You don't need the AnalogInputPullUp if you are providing the pullup yourself. The CWF1B104F3950 thermistor does not need an external pullup since it uses the 100k pullup on the mod120. The USP10972 uses the 10k pullup that you added to the circuit.
Josh
AndrewPratt:
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
mc-Josh:
That is great, what was the root of the problem?
Thanks,
Josh
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version