I've been using my first B4R project for a while now and so far it is pretty solid except for one problem that keeps recurring. I am using these probes. Overall they have a very good rating so I am unsure where the problem lies: Code, circuitry or just a bad batch of probes. This was a 5 pack, and I have now gone through 4 of them. These probes are in pool water, but they are supposed to be waterproof and on the first probe, I actually dipped it in plasti-dip to further waterproof it. After the first failed, I no longer bothered with the plasti-dip but do eventually plan to use it again to prolong probe life in pool water.
What happens: Initially the probe works fine. I get no errors and they track perfectly. Eventually, after several hours or days, I start to get errors that the probe is not connected or more typically, I get incorrect readings. Some examples I have seen:
Initially, the connections to the DS18B20 were straightforward: 5v to Power, Gnd to Gnd, ESP pin to data. After the third time the probe stopped working, I did some Googling and decided to try a 4.7k resistor between power and data. I still don't understand why it should be necessary, but had nothing to lose. Again, it worked for a day or two then acted up once again.
The only thing I haven't tried yet is to change over to 3v for the DS18B20, but it is supposed to be able to take 5v. Has anyone else ever had problems with these probes as described above? What should my next step be? I do plan on buying a different brand of probe, but since these got such good ratings, I am not too confident that it will fix the problem. What do others recommend regarding supply voltage (5v vs 3v) and whether or not a resistor is needed between power and data?
The only noteable changes I made to the onewire sample code is that I increased the delay from 1000 to 1350 ms between requesting the temp and reading it, and I also moved the "onewireTemp.ResetSearch" line in order to allow for me to detect if no probe is connected. If there is a better way to do this then any advice is welcome. Before I moved it, it would always skip a reading on every other call to this sub. Side note: Is there is way to simply read 'index' 0 (which would be the first probe detected - and the ONLY probe in a single-probe onewire configuration)?
Any warning messages are stored with GlobalStore and the UpdateDisplay sub (not shown due to complexity) displays them on the last line of the LCD on a cycle every time it is updated (every 5 seconds it shows the next message as needed then loops).
What happens: Initially the probe works fine. I get no errors and they track perfectly. Eventually, after several hours or days, I start to get errors that the probe is not connected or more typically, I get incorrect readings. Some examples I have seen:
- 31.9 F (essentially 0 C) - Supposedly this can happen with a bad "read", such as not giving the probe enough time between requesting a read and getting the result. I tried increasing the delay to no avail.
- 194.3 F (essentially 90.2 C)
- 193.4 F
- 195.8 F
Initially, the connections to the DS18B20 were straightforward: 5v to Power, Gnd to Gnd, ESP pin to data. After the third time the probe stopped working, I did some Googling and decided to try a 4.7k resistor between power and data. I still don't understand why it should be necessary, but had nothing to lose. Again, it worked for a day or two then acted up once again.
The only thing I haven't tried yet is to change over to 3v for the DS18B20, but it is supposed to be able to take 5v. Has anyone else ever had problems with these probes as described above? What should my next step be? I do plan on buying a different brand of probe, but since these got such good ratings, I am not too confident that it will fix the problem. What do others recommend regarding supply voltage (5v vs 3v) and whether or not a resistor is needed between power and data?
The only noteable changes I made to the onewire sample code is that I increased the delay from 1000 to 1350 ms between requesting the temp and reading it, and I also moved the "onewireTemp.ResetSearch" line in order to allow for me to detect if no probe is connected. If there is a better way to do this then any advice is welcome. Before I moved it, it would always skip a reading on every other call to this sub. Side note: Is there is way to simply read 'index' 0 (which would be the first probe detected - and the ONLY probe in a single-probe onewire configuration)?
Any warning messages are stored with GlobalStore and the UpdateDisplay sub (not shown due to complexity) displays them on the last line of the LCD on a cycle every time it is updated (every 5 seconds it shows the next message as needed then loops).
B4X:
Private Sub ReadTemp (u As Byte)
onewireTemp.Reset
onewireTemp.Select(address)
onewireTemp.Write(0xBE, False)
Dim data(12) As Byte
onewireTemp.ReadBytes(data, 9)
Dim raw As Int = Bit.Or(Bit.ShiftLeft(data(1), 8), data(0))
If type_s Then
raw = Bit.ShiftLeft(raw, 3)
If data(7) = 0x10 Then
raw = Bit.And(raw, 0xFFF0) + 12 - data(6)
End If
Else
Dim cfg As Byte = Bit.And(data(4), 0x60)
If cfg = 0 Then
raw = Bit.And(raw, Bit.Not(7))
Else if cfg = 0x20 Then
raw = Bit.And(raw, Bit.Not(3))
Else if cfg = 0x40 Then
Bit.And(raw, Bit.Not(1))
End If
End If
Dim celsius As Double = raw / 16
If celsius <> 85 Then '85C means it failed to get temperature so ignore it.
PoolTemperature = ((celsius * 9) / 5) + 32
End If
UpdateDisplay
End Sub
Private Sub THScanTimer_Tick '<---- main loop timer, which is set for 5000 ms
'Air temp & Humidity
Dim dhtResult As Int = DHT22sensor.Read22(DHT22pin.PinNumber) '0 = OK, -3 = N/C (Library incorrectly says 0 = fail)
Select dhtResult
Case 0 'OK
AirHumidity=DHT22sensor.GetHumidity
AirTemperature = (DHT22sensor.GetTemperature * 1.8) + 32
AirHeatIndex = HeatIndex (AirTemperature, AirHumidity)
GlobalStore.Put (5, "") 'Remove any warnings that may have shown earlier about air temp probe
Case -3 'N/C
If Logging Then Log ("DHT22: N/C")
AirTemperature = 999: AirHeatIndex = 999 'UpdateDisplay sub checks for this and converts to dashes
GlobalStore.Put (5, "Air Temp/Hum Sensor?")
End Select
'Pool Temp (onewire)
onewireTemp.ResetSearch 'Should only reset before search if there is only one device connected to onewire. Otherwise put if after if search = false below
If onewireTemp.Search(address) = False Then
If Logging Then Log ("OneWire: N/C")
GlobalStore.Put (6, "Pool Temp Sensor?")
PoolTemperature = 999 'UpdateDisplay sub checks for this and converts to dashes
UpdateDisplay
Return
End If
If Logging Then Log ("OneWire address found: ",bc.HexFromBytes(address))
If onewireTemp.CRC8(address, 7) <> address(7) Then
If Logging Then Log ("Pool Temp Probe: CRC is not valid")
GlobalStore.Put (6, "Pool Temp CRC Fail")
UpdateDisplay
Return
End If
Select address(0)
Case 0x10
'WriteLog("Chip = DS18S20")
type_s = True
Case 0x28
'WriteLog("Chip = DS18B20")
type_s = False
Case 0x22
'WriteLog("Chip = DS1822")
type_s = False
Case Else
If Logging Then Log ("Pool Temp Probe is not a DS18x20 family device.")
GlobalStore.Put (6, "Pool Probe Incorrect")
PoolTemperature = 999
UpdateDisplay
Return
End Select
GlobalStore.Put (6, "") 'Remove any warnings that may have shown earlier about pool temp probe
onewireTemp.Reset
onewireTemp.Select(address)
onewireTemp.Write(0x44, True)
'give it 1 second to read the temperature
CallSubPlus("ReadTemp", 1350, 0) 'Used to wait 1000ms, increased delay a bit
End Sub