SHT71 Using Long Wire

I am able to to use the SHT71 on a short cable just fine but am unable to reach the 50’ that I need. I have modified the Sensirion.h file

From:

#define PULSE_LONG delayMicroseconds(3)
#define PULSE_SHORT delayMicroseconds(1)

To:

#define PULSE_LONG delayMicroseconds(300)
#define PULSE_SHORT delayMicroseconds(100)

Which reading one post claimed to reach 40 meters.

I am using: Rewritten (v2.0) December 10, 2010 version of the Sensirion.h file.

This is the code example I am using:

/*

  • Example code for SHT1x or SHT7x sensors demonstrating blocking calls
  • for temperature and humidity measurement in the setup routine and
  • non-blocking calls in the main loop. The pin 13 LED is flashed as a
  • background task while temperature and humidity measurements are made.
  • Note that the status register read/write demonstration code places the
  • sensor in low resolution mode. Delete it to stay in high res mode.
  • This example contains two versions of the code: one that checks library
  • function return codes for error indications and one that does not.
  • The version with error checking may be useful in debuging possible
  • connection issues with the sensor. A #define selects between versions.
    */

#include <Sensirion.h>

#define ENA_ERRCHK // Enable error checking code

const byte dataPin = 9; // SHTxx serial data
const byte sclkPin = 8; // SHTxx serial clock
const byte ledPin = 13; // Arduino built-in LED
const unsigned long TRHSTEP = 5000UL; // Sensor query period
const unsigned long BLINKSTEP = 250UL; // LED blink period

Sensirion sht = Sensirion(dataPin, sclkPin);

unsigned int rawData;
float temperature;
float humidity;
float dewpoint;

byte ledState = 0;
byte measActive = false;
byte measType = TEMP;

unsigned long trhMillis = 0; // Time interval tracking
unsigned long blinkMillis = 0;

#ifdef ENA_ERRCHK

// This version of the code checks return codes for errors
byte error = 0;

void setup() {
byte stat;
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(15); // Wait >= 11 ms before first cmd
// Demonstrate status register read/write
if (error = sht.readSR(&stat)) // Read sensor status register
logError(error);
Serial.print(“Status reg = 0x”);
Serial.println(stat, HEX);
if (error = sht.writeSR(LOW_RES)) // Set sensor to low resolution
logError(error);
if (error = sht.readSR(&stat)) // Read sensor status register again
logError(error);
Serial.print(“Status reg = 0x”);
Serial.println(stat, HEX);
//Serial.println(long);
//Serial.println(PULSE_SHORT);
// Demonstrate blocking calls
if (error = sht.measTemp(&rawData)) // sht.meas(TEMP, &rawData, BLOCK)
logError(error);
temperature = sht.calcTemp(rawData);
if (error = sht.measHumi(&rawData)) // sht.meas(HUMI, &rawData, BLOCK)
logError(error);
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}

void loop() {
unsigned long curMillis = millis(); // Get current time

// Rapidly blink LED. Blocking calls take too long to allow this.
if (curMillis - blinkMillis >= BLINKSTEP) { // Time to toggle the LED state?
ledState ^= 1;
digitalWrite(ledPin, ledState);
blinkMillis = curMillis;
}

// Demonstrate non-blocking calls
if (curMillis - trhMillis >= TRHSTEP) { // Time for new measurements?
measActive = true;
measType = TEMP;
if (error = sht.meas(TEMP, &rawData, NONBLOCK)) // Start temp measurement
logError(error);
trhMillis = curMillis;
}
if (measActive && (error = sht.measRdy())) { // Check measurement status
if (error != S_Meas_Rdy)
logError(error);
if (measType == TEMP) { // Process temp or humi?
measType = HUMI;
temperature = sht.calcTemp(rawData); // Convert raw sensor data
if (error = sht.meas(HUMI, &rawData, NONBLOCK)) // Start humi measurement
logError(error);
} else {
measActive = false;
humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}
}
}

#else // If ENA_ERRCHK is not defined

// This code is the same as above but without error checking
void setup() {
byte stat;
byte error = 0;
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(15); // Wait >= 11 ms before first cmd
// Demonstrate status register read/write
sht.readSR(&stat); // Read sensor status register
Serial.print(“Status reg = 0x”);
Serial.println(stat, HEX);
sht.writeSR(LOW_RES); // Set sensor to low resolution
sht.readSR(&stat); // Read sensor status register again
Serial.print(“Status reg = 0x”);
Serial.println(stat, HEX);
// Demonstrate blocking calls
sht.measTemp(&rawData); // sht.meas(TEMP, &rawData, BLOCK)
temperature = sht.calcTemp(rawData);
sht.measHumi(&rawData); // sht.meas(HUMI, &rawData, BLOCK)
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}

void loop() {
unsigned long curMillis = millis(); // Get current time

// Rapidly blink LED. Blocking calls take too long to allow this.
if (curMillis - blinkMillis >= BLINKSTEP) { // Time to toggle the LED state?
ledState ^= 1;
digitalWrite(ledPin, ledState);
blinkMillis = curMillis;
}

// Demonstrate non-blocking calls
if (curMillis - trhMillis >= TRHSTEP) { // Time for new measurements?
measActive = true;
measType = TEMP;
sht.meas(TEMP, &rawData, NONBLOCK); // Start temp measurement
trhMillis = curMillis;
}
if (measActive && sht.measRdy()) { // Check measurement status
if (measType == TEMP) { // Process temp or humi?
measType = HUMI;
temperature = sht.calcTemp(rawData); // Convert raw sensor data
sht.meas(HUMI, &rawData, NONBLOCK); // Start humi measurement
} else {
measActive = false;
humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}
}
}

#endif // End of non-error-checking example

void logData() {
Serial.print(“Temperature = “); Serial.print(temperature);
Serial.print(” C, Humidity = “); Serial.print(humidity);
Serial.print(” %, Dewpoint = “); Serial.print(dewpoint);
Serial.println(” C”);
}

// The following code is only used with error checking enabled
void logError(byte error) {
switch (error) {
case S_Err_NoACK:
Serial.println(“Error: No response (ACK) received from sensor!”);
break;
case S_Err_CRC:
Serial.println(“Error: CRC mismatch!”);
break;
case S_Err_TO:
Serial.println(“Error: Measurement timeout!”);
break;
default:
Serial.println(“Unknown error received!”);
break;
}
}

I am using an arduino mega 2560, the on board 5v and ground, and pin 8 for data and 9 for sclk.
My wire is Shielded cat5 and this is the result:

Status reg = 0x0
Status reg = 0x1
Error: CRC mismatch!
Error: CRC mismatch!
Temperature = 2581.30 C, Humidity = 0.10 %, Dewpoint = 265.37 C
Error: CRC mismatch!
Temperature = 2581.30 C, Humidity = 100.00 %, Dewpoint = 2581.30 C
Error: CRC mismatch!
Temperature = 2581.30 C, Humidity = 100.00 %, Dewpoint = 2581.30 C
Error: CRC mismatch!
Temperature = 2581.30 C, Humidity = 100.00 %, Dewpoint = 2581.30 C
Error: CRC mismatch!
Temperature = 2581.30 C, Humidity = 100.00 %, Dewpoint = 2581.30 C

Thanks much!

What sort of cable are you using for clock/data.
What is it's capacitance to ground, and what is the capacitance between clock and ground wires.
The datasheet has some weird (useless) info about spacing. Page 4, 1.8.
Leo..

Wawa:
What sort of cable are you using for clock/data.

He did mention ethernet cable.

In sensiron.h:

// Clock pulse timing macros
// Lengthening these may assist communication over long wires
#define PULSE_LONG  delayMicroseconds(3)
#define PULSE_SHORT delayMicroseconds(1)

Hint hint. There's no limit to how long those delays can be; you could increase them by 100 or 1000 times and still get decent speed.

Chagrin:
He did mention ethernet cable.

Doh. Just saw that. Cat-5
Cat-6 might be slightly better. More separation between the pairs.
I assume OP is running clock and data on different pairs.
Combining them on one twisted pair could be bad.
Leo..

If you don't use pull up resistors, pulling Data and Clock line up with about 10k resistors might solve the problem.

The datasheet mentions that one 10k pull-up resistor on the Data line is required.

Not on the clock line.
Leo..