Hey all, I posted a similar topic in sensors but I think that it should actually be posted here, anyways here goes:
I have a humidity sensor that uses SPI, and since I'm a complete noob at it I can't seem to make it work
Sensor SPI data:http://sensing.honeywell.com/spi-comms-with-digital-humidity-temp-sensors-tn-009071-1-en-final-07jun12.pdf
From this I developed code that I thought would work but seems to just return two full bytes:
#include <SPI.h>
byte slave1 = 48;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println();
pinMode(slave1, OUTPUT);
digitalWrite(SS, HIGH);
digitalWrite(slave1, HIGH);
pinMode(MISO, INPUT);
///////////////////////////////////////////////////////////
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV32);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
}
///////////////////////////////////////////////////////////
String MeasurementReady()
{
digitalWrite(slave1, LOW);
delay(10);
digitalWrite(slave1, HIGH);
delay(10);
digitalWrite(slave1, LOW);
byte a = SPI.transfer(0);
byte b = SPI.transfer(0);
digitalWrite(slave1, HIGH);
String Result = String(a,BIN);
Result = Result + String(b,BIN);
return Result;
}
//////////////////////////////////////////////////////////
void loop()
{
// put your main code here, to run repeatedly:
Serial.println("Test");
Serial.println(MeasurementReady());
while(1);
}
Can someone tell me where I am going wrong please.
Thanks.