https://nearbus.xyz/wiki/index.php?title=One-Wire_Temperature_Sensor_-_DS18B20&feed=atom&action=history
One-Wire Temperature Sensor - DS18B20 - Revision history
2024-03-29T05:48:39Z
Revision history for this page on the wiki
MediaWiki 1.30.0
https://nearbus.xyz/mediawiki/index.php?title=One-Wire_Temperature_Sensor_-_DS18B20&diff=150&oldid=prev
Nearwiki: Created page with " === Reference Information === <br /> * '''Info Web:''' http://seeedstudio.com/depot/one-wire-temperature-sensor-p-1235.html?cPath=25_27 * '''Techinical Spec:''' Temperature..."
2018-03-29T21:16:38Z
<p>Created page with " === Reference Information === <br /> * '''Info Web:''' http://seeedstudio.com/depot/one-wire-temperature-sensor-p-1235.html?cPath=25_27 * '''Techinical Spec:''' Temperature..."</p>
<p><b>New page</b></p><div><br />
=== Reference Information ===<br />
<br /><br />
* '''Info Web:''' http://seeedstudio.com/depot/one-wire-temperature-sensor-p-1235.html?cPath=25_27<br />
<br />
* '''Techinical Spec:''' Temperature range: -55°C to +125°C - Accuracy: ±0.5°C( -10°C to +85°C)<br />
<br />
* '''Connector Type:''' Base Shield V1.3 - Grove compatible - http://seeedstudio.com/depot/base-shield-v13-p-1378.html<br />
<br />
* '''Code Source:''' http://playground.arduino.cc/Learning/OneWire<br />
<br />
<br />
<br />
----<br />
<br />
===Temperature Sensor - DS18B20 - (Waterproof)===<br />
<br /><br />
[[File:Temp probe 18B20.jpg]]<br />
<br />
<br />
<br />
----<br />
<br />
=== MyNbios Code - Example ===<br />
<br /><br />
<br />
'''In order to run this code you should copy the following code into the area delimited by the MY_BIOS CUSTOM CODE banners in the Hello_World_xxx.ino example.'''<br />
<br />
<pre><br />
<nowiki>#include <OneWire.h></nowiki><br />
<br />
OneWire ds(3); // Arduino PIN_3<br />
<br />
void Nearbus::MyNbios_0( byte portId, ULONG setValue, ULONG* pRetValue, byte vmcuMethod, PRT_CNTRL_STRCT* pPortControlStruct )<br />
{<br />
byte i;<br />
byte present = 0;<br />
byte type_s;<br />
byte data[12];<br />
byte addr[8];<br />
float celsius, fahrenheit;<br />
<br />
for (i=0 ; i < 20 ; i++) {<br />
if ( ds.search(addr)) {<br />
break;<br />
}<br />
ds.reset_search();<br />
delay(250); <br />
}<br />
if (i == 20 ) {<br />
*pRetValue = 0; <br />
return;<br />
}<br />
<br />
if(OneWire::crc8(addr, 7) != addr[7]) {<br />
*pRetValue = 0;<br />
return;<br />
}<br />
<br />
// the first ROM byte indicates which chip<br />
switch (addr[0]) {<br />
case 0x10:<br />
type_s = 1;<br />
break;<br />
<br />
case 0x28:<br />
type_s = 0;<br />
break;<br />
<br />
case 0x22:<br />
type_s = 0;<br />
break;<br />
<br />
default:<br />
*pRetValue = 0;<br />
return;<br />
} <br />
ds.reset();<br />
ds.select(addr);<br />
ds.write(0x44, 1); // start conversion, with parasite power on at the end<br />
delay(1000); // maybe 750ms is enough, maybe not<br />
present = ds.reset();<br />
ds.select(addr); <br />
ds.write(0xBE); // Read Scratchpad<br />
<br />
for ( i = 0; i < 9; i++) { // we need 9 bytes<br />
data[i] = ds.read();<br />
}<br />
<br />
int16_t raw = (data[1] << 8) | data[0];<br />
if (type_s) {<br />
raw = raw << 3; // 9 bit resolution default<br />
if (data[7] == 0x10) { // "count remain" gives full 12 bit resolution<br />
raw = (raw & 0xFFF0) + 12 - data[6];<br />
}<br />
} <br />
else {<br />
byte cfg = (data[4] & 0x60);<br />
// at lower res, the low bits are undefined, so let's zero them<br />
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms<br />
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms<br />
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms<br />
// default is 12 bit resolution, 750 ms conversion time<br />
}<br />
celsius = (float)raw / 16.0;<br />
fahrenheit = celsius * 1.8 + 32.0; <br />
<br />
if ( !setValue ) { // NearAPI: [value=1] => Fahrenheit - [value=0] => Celsius<br />
*pRetValue = (ULONG) (celsius * 100);<br />
}<br />
else {<br />
*pRetValue = (ULONG) (fahrenheit * 100);<br />
} <br />
}<br />
</pre></div>
Nearwiki