Thanks, I've read all of those posts before I posted. It seems to be back and forth with the code, the latest was edited August 4th 2010. So, I've tried all the code examples in those posts and others linked etc. I still cannot get any data from the sensor. All I have connected is ground, to pin 1 of the SHT11, Data via 10K pullup resistor (Parallax datasheet from May 2010 calls for a 10Kohm pullup resistor, not pulldown) to pin 2 on SHT11. VDD of +5vdc from the Arduino. The clk and data pins change in various code so I shift them as needed. I have also tried pullup and no pullup resistor with no change. So, using the simple code below, when viewing the serial monitor I get:
Resetting SHT...
Followed by
Starting Temperature/Humidity reading...
And that's it, never changes, I don't have another sensor to try but is there any way to know if it even works?
/*
*/
int dataPin = 9;
int sckPin = 8;
void resetSHT()
{
pinMode(dataPin,OUTPUT);
pinMode(sckPin,OUTPUT);
shiftOut(dataPin, sckPin, LSBFIRST, 255);
shiftOut(dataPin, sckPin, LSBFIRST, 255);
digitalWrite(dataPin,HIGH);
for(int i = 0; i < 15; i++){
digitalWrite(sckPin, LOW);
digitalWrite(sckPin, HIGH);
}
}
//Specific SHT start command
void startSHT()
{
pinMode(sckPin,OUTPUT);
pinMode(dataPin,OUTPUT);
digitalWrite(dataPin,HIGH);
digitalWrite(sckPin,HIGH);
digitalWrite(dataPin,LOW);
digitalWrite(sckPin,LOW);
digitalWrite(sckPin,HIGH);
digitalWrite(dataPin,HIGH);
digitalWrite(sckPin,LOW);
}
void writeByteSHT(byte data)
{
pinMode(sckPin,OUTPUT);
pinMode(dataPin,OUTPUT);
// digitalWrite(dataPin,LOW);
shiftOut(dataPin,sckPin,MSBFIRST,data);
pinMode(dataPin,INPUT);
//Wait for SHT15 to acknowledge by pulling line low
while(digitalRead(dataPin) == 1);
digitalWrite(sckPin,HIGH);
digitalWrite(sckPin,LOW); //Falling edge of 9th clock
//wait for SHT to release line
while(digitalRead(dataPin) == 0 );
//wait for SHT to pull data line low to signal measurement completion
//This can take up to 210ms for 14 bit measurments
int i = 0;
while(digitalRead(dataPin) == 1 )
{
i++;
if (i == 255) break;
delay(10);
}
//debug
i *= 10;
Serial.print("Response time = ");
Serial.println(i);
}
//Read 16 bits from the SHT sensor
int readByte16SHT()
{
int cwt = 0;
unsigned int bitmask = 32768;
int temp;
pinMode(dataPin,INPUT);
pinMode(sckPin,OUTPUT);
digitalWrite(sckPin,LOW);
for(int i = 0; i < 17; i++) {
if(i != 8) {
digitalWrite(sckPin,HIGH);
temp = digitalRead(dataPin);
// Serial.print(temp,BIN);
cwt = cwt + bitmask * temp;
digitalWrite(sckPin,LOW);
bitmask=bitmask/2;
}
else {
pinMode(dataPin,OUTPUT);
digitalWrite(dataPin,LOW);
digitalWrite(sckPin,HIGH);
digitalWrite(sckPin,LOW);
pinMode(dataPin,INPUT);
}
}
//leave clock high??
digitalWrite(sckPin,HIGH);
// Serial.println();
return cwt;
}
int getTempSHT()
{
startSHT();
writeByteSHT(B0000011);
return readByte16SHT();
}
int getHumidSHT()
{
startSHT();
writeByteSHT(B00000101);
return readByte16SHT();
}
void setup() {
pinMode(dataPin,OUTPUT);
pinMode(sckPin,OUTPUT);
Serial.begin(9600); // connect to the serial port
Serial.println("Resetting SHT...");
resetSHT();
}
void loop () {
delay(2000);
Serial.println("Starting Temperature/Humidity reading...");
int temp = getTempSHT();
Serial.print("Temprature:");
Serial.println(temp);
temp = getHumidSHT();
Serial.print("Humidity:");
Serial.println(temp);
}