Other OneWire (DallasTemperature)

Erel

Administrator
Staff member
Licensed User
Working library is available here: https://www.b4x.com/android/forum/threads/onewire-dallas-1-wire-protocol.66672/

rWireOne library wraps the following libraries:
https://github.com/milesburton/Arduino-Temperature-Control-Library
http://www.pjrc.com/teensy/td_libs_OneWire.html

It allows reading the temperature from one wire temperature sensors (see the first link for more details).

This is a beta version.

B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private deviceAddress() As Byte = Array As Byte(0x28, 0xFF, 0x5E, 0x18, 0x04, 0x15, 0x03, 0x34)
   Private dt As DallasTemperature
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   dt.Initialize(3)
   dt.SetResolution(deviceAddress, 10)
   timer1.Initialize("timer1_Tick", 250)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   dt.RequestTemperatures
   Dim tempC As Double = dt.GetTempC(deviceAddress)
   If tempC = -127 Then
     Log("Error getting temperature.")
     Log(dt.ToFahrenheit(tempC))
     Log(dt.ToCelsius(dt.ToFahrenheit(tempC)))
   Else
     Log("Temperature: C: ", tempC, ", F: ", dt.ToFahrenheit(tempC))
   End If
End Sub
 
Last edited:

rwblinn

Well-Known Member
Licensed User
Hi,

tested the B4R code and receiving error:
B4X:
Error getting temperature.
Celsius: -127
Fahrenheit: -196.6000
 

rbghongade

Active Member
Licensed User
Dear Erel,
The device address in your example is hardcoded. It would make the library more versatile if address search method is exposed. pardon me if it is already done. I just had a cursory glance at the example.
PS:Same result as reported by Rob, even after changing the device address and pin.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
The address is not set in the library. It is set in the code. You can change it as needed.

What is the output of:
Log(dt.IsConnected(deviceAddress)) ?
 

Erel

Administrator
Staff member
Licensed User
Can this lib be used to control adressable RGB Leds?
No. This can only be used for temperature reading. However there is a problem with the library.

I should receive such a sensor in a week or two and I will then further test it.
 

Cableguy

Expert
Licensed User
I have one, i only need to find it, lol... I will also test it...

Any chance for a "one wire" dedicated lib, so we can control 1 wire devices like the adressable LEDs?
 

raphaelcno

Active Member
Licensed User
B4X:
Sub Timer1_Tick
   dt.RequestTemperatures
   Dim tempC As Double = dt.GetTempC(deviceAddress)
   [...]
End Sub
I have not tested the code yet, but I just had a look at the code here and was thinking about a previous Arduino project where I was using several DS18B20 temperature sensors.
I see that you send "GetTempC" right after "RequestTemperatures".
Maybe there should be a delay (up to 750 ms when using the highest resolution) between these 2 commands.

I had an Arduino program with a sequence (finite-state machine) approximately like this:
- Send request ("Convert"/0x44) to all sensors.
- Wait 1 second (not blocking the rest of the code)
- Send "Read Scratchpad" (0xBE) to sensor #1, then extract the temperature data.
- Next loop: The same for sensor #2
- ...
- Next loop: The same for sensor #n
- Wait 4 seconds (not blocking)
- And back to start (Send request to all sensors)
That means the temperatures are measured every 5 seconds (+ a few milliseconds...).

I preferred using the OneWire library alone, without the Dallas library, because the Dallas library contained some hard coded delays blocking the rest of the code. I'm not completely updated, so maybe the most recent Dallas library has been changed.

2016-04-21 - B4R Forum - DS18B20 Resolution + Conversion time.png

Datasheet:
http://www.mouser.com/ds/2/256/DS18B20-PAR-315769.pdf
 

raphaelcno

Active Member
Licensed User
I see that you send "GetTempC" right after "RequestTemperatures".
Maybe there should be a delay (up to 750 ms when using the highest resolution) between these 2 commands.
I see now in the file "DallasTemperature.cpp" that the delay is included in the command "RequestTemperatures":

// sends command for all devices on the bus to perform a temperature conversion
void DallasTemperature::requestTemperatures(){

_wire->reset();
_wire->skip();
_wire->write(STARTCONVO, parasite);

// ASYNC mode?
if (!waitForConversion) return;
blockTillConversionComplete(bitResolution, NULL);

}

// Continue to check if the IC has responded with a temperature
void DallasTemperature::blockTillConversionComplete(uint8_t bitResolution, const uint8_t* deviceAddress){

int delms = millisToWaitForConversion(bitResolution);
if (deviceAddress != NULL && checkForConversion && !parasite){
unsigned long now = millis();
while(!isConversionAvailable(deviceAddress) && (millis() - delms < now));
} else {
delay(delms);
}

}

// returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
int16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution){

switch (bitResolution){
case 9:
return 94;
case 10:
return 188;
case 11:
return 375;
default:
return 750;
}

}
 

George Anifantakis

Member
Licensed User
Working library is available here: https://www.b4x.com/android/forum/threads/onewire-dallas-1-wire-protocol.66672/

rWireOne library wraps the following libraries:
https://github.com/milesburton/Arduino-Temperature-Control-Library
http://www.pjrc.com/teensy/td_libs_OneWire.html

It allows reading the temperature from one wire temperature sensors (see the first link for more details).

This is a beta version.

B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private deviceAddress() As Byte = Array As Byte(0x28, 0xFF, 0x5E, 0x18, 0x04, 0x15, 0x03, 0x34)
   Private dt As DallasTemperature
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   dt.Initialize(3)
   dt.SetResolution(deviceAddress, 10)
   timer1.Initialize("timer1_Tick", 250)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   dt.RequestTemperatures
   Dim tempC As Double = dt.GetTempC(deviceAddress)
   If tempC = -127 Then
     Log("Error getting temperature.")
     Log(dt.ToFahrenheit(tempC))
     Log(dt.ToCelsius(dt.ToFahrenheit(tempC)))
   Else
     Log("Temperature: C: ", tempC, ", F: ", dt.ToFahrenheit(tempC))
   End If
End Sub

Hi, why using this library i am getting an error at definition dim dt As DallasTemperature
Error description: Unknown type: dallastemperature
Are you missing a library reference?
Error occurred on line: 10 (Main)
Private dt As DallasTemperature

I am using library rOneWire
 
Top