P.S.
here's my updated code.
/* QT300 interface
* ------------------
* Jon Drews, 30 Jan, 2007.
* mistersquiggle at hot mail
* ------------------
*
* notes:
* burst length timing shows normal/expected results. but 16bit data returned is almost static.
* tried several values of Cs capacitor. this changes the data returned, but it is still static. hmmmm.
*
*/
int DRDY = 2; // 'data ready' pin set to pin 2 on arduino
int SDI = 3; // data input pin set to pin 3 on arduino
int SCK = 4; // clock output pin set to pin 4 on arduino
int REQ = 5; // 'request data' output pin set to pin 5 on arduino
byte qtbytea = 0; // stores the first byte of data returned from QT300
byte qtbyteb = 0; // stores the second byte of data returned from QT300
int i = 0;
int bl = 0; // used to count the time of the acquisition burst
void setup() {
pinMode(DRDY, INPUT);
pinMode(SDI, INPUT);
pinMode(SCK, OUTPUT);
pinMode(REQ, OUTPUT);
digitalWrite(REQ, HIGH); // set data request pin HIGH
digitalWrite(SCK, LOW); // set clock pin LOW
Serial.begin(115200); // set baud rate for arduino-->pc communication
delay(1000); // weird. things only seem to work if i allow a 1sec pause here...
Serial.println("ready...");
while(Serial.available() == -1){
// wait for any key to be pressed
}
}
void loop(){
qtbytea = 0; // reset data variables
qtbyteb = 0;
bl = 0; // reset burst length var.
digitalWrite(REQ, LOW); // request data from QT300 by grounding the REQ line
delayMicroseconds(80); // minimum REQ pulse is 30us
digitalWrite(REQ, HIGH);
while(digitalRead(DRDY) == HIGH){
bl++; // time the length of the acquisition burst.
}
for (i = 0; i < 8; i++) { // loop for transfering the first byte of data from QT300 to arduino
delayMicroseconds(20); // minimum delay 12us
digitalWrite(SCK, HIGH); // trigger the clock pin high
delayMicroseconds(20); // minimum delay 13us
if (digitalRead(SDI))
qtbytea |= (1 << i); //set individual bit in qtbytea variable using shift left
digitalWrite(SCK, LOW); //return clock pin low
}
i = 0;
for (i = 0; i < 8; i++) { // loop for transfering the second byte of data from QT300 to arduino
delayMicroseconds(20);
digitalWrite(SCK, HIGH);
delayMicroseconds(20);
if (digitalRead(SDI))
qtbyteb |= (1 << i);
digitalWrite(SCK, LOW);
}
Serial.print(qtbytea, BIN); // print the first byte in binary format
Serial.print("-");
Serial.print(qtbyteb, BIN); // print the second byte in binary format
Serial.print(" BL: ");
Serial.println(bl, DEC); // print the length of the acquisition burst. then do a line break.
delay(100); // wait a bit to avoid flooding the serial port with data
}