Xadow Adapter

Hi Seeed,

I’m having difficulty using the Grove Tempurature & Humidity Pro with the Xadow Adapter. The problem is that this sensor requires a quarter second pull to HIGH before reading. How do you do that via the Xadow Adapter? :confused:

seeedstudio.com/wiki/Grove_- … Sensor_Pro

seeedstudio.com/wiki/Xadow_Grove_Adaptor

Looking at the example code for the Xadow Adapter, I believe I could send what the sensor needs if I had more information about these defines:

#define REG_ADDR_RESULT 0x00
#define REG_ADDR_ALERT 0x01
#define REG_ADDR_CONFIG 0x02
#define REG_ADDR_LIMITL 0x03
#define REG_ADDR_LIMITH 0x04
#define REG_ADDR_HYST 0x05
#define REG_ADDR_CONVL 0x06
#define REG_ADDR_CONVH 0x07

How does the Xadow Adapter board interpret wire writes to these defines? That is the documentation that seems to be lacking…

Thanks,

-R.

Some more information…

Here is the read code for the sensor normally that needs to be adapted to read from the ADC121 via I2C. The problem is this part:

// pull the pin high and wait 250 milliseconds
digitalWrite(_pin, HIGH);
delay(250);

[code]boolean DHT::read(void) {
uint8_t laststate = HIGH;
uint8_t counter = 0;
uint8_t j = 0, i;
unsigned long currenttime;

// pull the pin high and wait 250 milliseconds
digitalWrite(_pin, HIGH);
delay(250);

currenttime = millis();
if (currenttime < _lastreadtime) {
// ie there was a rollover
_lastreadtime = 0;
}
if (!firstreading && ((currenttime - _lastreadtime) < 2000)) {
return true; // return last correct measurement
//delay(2000 - (currenttime - _lastreadtime));
}
firstreading = false;
/*
Serial.print("Currtime: “); Serial.print(currenttime);
Serial.print(” Lasttime: "); Serial.print(_lastreadtime);
*/
_lastreadtime = millis();

data[0] = data[1] = data[2] = data[3] = data[4] = 0;

// now pull it low for ~20 milliseconds
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delay(20);
cli();
digitalWrite(_pin, HIGH);
delayMicroseconds(40);
pinMode(_pin, INPUT);

// read in timings
for ( i=0; i< MAXTIMINGS; i++) {
counter = 0;
while (digitalRead(_pin) == laststate) {
counter++;
delayMicroseconds(1);
if (counter == 255) {
break;
}
}
laststate = digitalRead(_pin);

if (counter == 255) break;

// ignore first 3 transitions
if ((i >= 4) && (i%2 == 0)) {
  // shove each bit into the storage bytes
  data[j/8] <<= 1;
  if (counter > _count)
    data[j/8] |= 1;
  j++;
}

}

sei();

/*
Serial.println(j, DEC);
Serial.print(data[0], HEX); Serial.print(", “);
Serial.print(data[1], HEX); Serial.print(”, “);
Serial.print(data[2], HEX); Serial.print(”, “);
Serial.print(data[3], HEX); Serial.print(”, “);
Serial.print(data[4], HEX); Serial.print(” =? ");
Serial.println(data[0] + data[1] + data[2] + data[3], HEX);
*/

// check we read 40 bits and that the checksum matches
if ((j >= 40) &&
(data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) {
return true;
}

return false;

}[/code]

How do I do that in this example:

[code]#include <Wire.h>
#include <Streaming.h>

#define ADDR_ADC121 0x59

#define V_REF 3.00

#define REG_ADDR_RESULT 0x00
#define REG_ADDR_ALERT 0x01
#define REG_ADDR_CONFIG 0x02
#define REG_ADDR_LIMITL 0x03
#define REG_ADDR_LIMITH 0x04
#define REG_ADDR_HYST 0x05
#define REG_ADDR_CONVL 0x06
#define REG_ADDR_CONVH 0x07

unsigned int getData;
float analogVal=0; // convert
void init_adc()
{
Wire.beginTransmission(ADDR_ADC121); // transmit to device
Wire.write(REG_ADDR_CONFIG); // Configuration Register
Wire.write(0x20);
Wire.endTransmission();
}

void read_adc() //unsigned int *data
{

Wire.beginTransmission(ADDR_ADC121);        // transmit to device
Wire.write(REG_ADDR_RESULT);                // get reuslt
Wire.endTransmission();

Wire.requestFrom(ADDR_ADC121, 2);           // request 2byte from device
delay(1);
if(Wire.available()<=2)
{
  getData = (Wire.read()&0x0f)<<8;
  getData |= Wire.read();
}
Serial.print("getData:");
Serial.println(getData);
delay(5);
Serial.print("The analog value is:");
Serial.print(getData*V_REF*2/4096); 
Serial.println("V");

}
void setup()
{
Serial.begin(9600);
Wire.begin();
init_adc();
}

void loop()
{
read_adc();//adcRead);
delay(500);
}[/code]

OK, in case someone else is trying to figure this out…

I’ve come to the conclusion that the Xadow Adapter can really only be used with standard analog sensors and I2C. If you have an analog sensor that is doing something fancy like sending bits after being pulled high, you need to use this board:

seeedstudio.com/wiki/Xadow_Breakout

It will allow you to get directly at the Xadow’s digital, analog, or I2C pins.

:ugeek:

Cheers,

-R.