| 129 | |
| 130 | |
| 131 | int DHT20::readData() |
| 132 | { |
| 133 | // GET DATA |
| 134 | const uint8_t length = 7; |
| 135 | int bytes = _wire->requestFrom(DHT20_ADDRESS, length); |
| 136 | |
| 137 | if (bytes == 0) return DHT20_ERROR_CONNECT; |
| 138 | if (bytes < length) return DHT20_MISSING_BYTES; |
| 139 | |
| 140 | bool allZero = true; |
| 141 | for (int i = 0; i < bytes; i++) |
| 142 | { |
| 143 | _bits[i] = _wire->read(); |
| 144 | // if (_bits[i] < 0x10) Serial.print(0); |
| 145 | // Serial.print(_bits[i], HEX); |
| 146 | // Serial.print(" "); |
| 147 | allZero = allZero && (_bits[i] == 0); |
| 148 | } |
| 149 | // Serial.println(); |
| 150 | if (allZero) return DHT20_ERROR_BYTES_ALL_ZERO; |
| 151 | |
| 152 | _lastRead = millis(); |
| 153 | return bytes; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | int DHT20::convert() |