https://nearbus.xyz/wiki/index.php?title=Temperature_%26_Humidity_Sensor_Pro&feed=atom&action=history
Temperature & Humidity Sensor Pro - Revision history
2024-03-28T16:16:46Z
Revision history for this page on the wiki
MediaWiki 1.30.0
https://nearbus.xyz/mediawiki/index.php?title=Temperature_%26_Humidity_Sensor_Pro&diff=151&oldid=prev
Nearwiki: Created page with " * '''Product Web:''' http://seeedstudio.com/depot/grove-temperaturehumidity-sensor-pro-p-838.html?cPath=25_27 * '''Wiki:''' http://seeedstudio.com/wiki/Grove_-_Temperature_..."
2018-03-29T21:17:11Z
<p>Created page with " * '''Product Web:''' http://seeedstudio.com/depot/grove-temperaturehumidity-sensor-pro-p-838.html?cPath=25_27 * '''Wiki:''' http://seeedstudio.com/wiki/Grove_-_Temperature_..."</p>
<p><b>New page</b></p><div><br />
<br />
* '''Product Web:''' http://seeedstudio.com/depot/grove-temperaturehumidity-sensor-pro-p-838.html?cPath=25_27<br />
<br />
* '''Wiki:''' http://seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro<br />
<br />
* '''Code Source:''' http://seeedstudio.com/wiki/File:Humidity_Temperature_Sensor.zip<br />
<br />
* '''Technical Spec:''' Humidytly: 5% RH - 99% RH - Temperature -40°C - 80°C - Acuracy: 2% RH / 0.5°C<br />
<br />
* '''Connector Type:''' Base Shield V1.3 - Grove compatible - http://seeedstudio.com/depot/base-shield-v13-p-1378.html<br />
<br />
<br />
<br />
----<br />
===Temperature & Humidity Sensor Pro===<br />
<br /><br />
<br />
[[File:Grove_Tem_Humid.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_NBIOS CUSTOM CODE banners in the Hello_World_xxx.ino example.'''<br />
<br />
<br />
<pre><br />
void Nearbus::MyNbios_0( byte portId, UINT setValue, ULONG* pRetValue, byte vmcuMethod, PRT_CNTRL_STRCT* pPortControlStruct )<br />
{ <br />
UINT data[6];<br />
UINT _pin;<br />
UINT _count = 6;<br />
ULONG _lastreadtime = 0;<br />
boolean firstreading = true;<br />
float h;<br />
float t; <br />
byte ret;<br />
UINT laststate = HIGH;<br />
UINT counter = 0;<br />
UINT j = 0;<br />
UINT i;<br />
ULONG currenttime;<br />
<br />
//************************************<br />
// Reconfiguring Ports as I/O<br />
//************************************<br />
if( pPortControlStruct->portMode != MYDRIVER_MODE ) <br />
{<br />
PortModeConfig( portId, MYDRIVER_MODE ); <br />
}<br />
<br />
//************************************<br />
// Custom Function<br />
//************************************<br />
_pin = pPortControlStruct->pinId;<br />
<br />
// pull the pin high and wait 250 milliseconds<br />
digitalWrite(_pin, HIGH);<br />
delay(250);<br />
<br />
currenttime = millis();<br />
if (currenttime < _lastreadtime) {<br />
// ie there was a rollover<br />
_lastreadtime = 0;<br />
}<br />
if (!firstreading && ((currenttime - _lastreadtime) < 2000)) {<br />
ret = 0; // return last correct measurement<br />
//delay(2000 - (currenttime - _lastreadtime));<br />
}<br />
else {<br />
firstreading = false;<br />
_lastreadtime = millis();<br />
<br />
data[0] = data[1] = data[2] = data[3] = data[4] = 0;<br />
<br />
// now pull it low for ~20 milliseconds<br />
pinMode(_pin, OUTPUT);<br />
digitalWrite(_pin, LOW);<br />
delay(20);<br />
cli();<br />
digitalWrite(_pin, HIGH);<br />
delayMicroseconds(40);<br />
pinMode(_pin, INPUT);<br />
<br />
// read in timings<br />
for ( i=0; i< 85; i++) { // #define MAXTIMINGS = 85 // how many timing transitions we need to keep track of. 2 * number bits + extra<br />
counter = 0;<br />
while (digitalRead(_pin) == laststate) {<br />
counter++;<br />
delayMicroseconds(1);<br />
if (counter == 255) {<br />
break;<br />
}<br />
}<br />
laststate = digitalRead(_pin);<br />
<br />
if (counter == 255) break;<br />
<br />
// ignore first 3 transitions<br />
if ((i >= 4) && (i%2 == 0)) {<br />
// shove each bit into the storage bytes<br />
data[j/8] <<= 1;<br />
if (counter > _count)<br />
data[j/8] |= 1;<br />
j++;<br />
}<br />
}<br />
sei();<br />
<br />
// check we read 40 bits and that the checksum matches<br />
if ((j >= 40) && <br />
(data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) {<br />
ret = 0;<br />
}<br />
else{<br />
ret = 1;<br />
}<br />
}<br />
if (ret == 0) {<br />
h = data[0];<br />
h *= 256;<br />
h += data[1];<br />
h *= 10;<br />
<br />
t = data[2] & 0x7F;<br />
t *= 256;<br />
t += data[3];<br />
t *= 10;<br />
if (data[2] & 0x80)<br />
t *= -1;<br />
}<br />
else {<br />
t = 0;<br />
h = 0; <br />
} <br />
// delay(250); <br />
<br />
//************************************<br />
// Updating register <br />
//************************************ <br />
* pRetValue = (ULONG) t; <br />
}<br />
<br />
</pre></div>
Nearwiki