Greetings. I'm trying to get the TSL26711 proximity sensor up and running with a 3.3v Pro Mini, and I'm not having any luck. This is my first foray in to the world of i2c communications, so that could be the root of my issue (plus I'm not much of a programmer). I've read through i2c examples and came across this post:
http://forum.arduino.cc/index.php/topic,243729.0.html
which seemed promising (the register addresses even match), but I cannot even get the incorrect output realized in that post.
Anyway, here is my code - apologies for how linear it is, I wanted to get it working first before building tidy functions:
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Wire.beginTransmission(0x39);
Wire.write(0x00); //move to enable register
Wire.write(0x00);
Wire.endTransmission();
Wire.beginTransmission(0x39);
Wire.write(0x02); //move to time control register
Wire.write(0xFF);
Wire.endTransmission();
Wire.beginTransmission(0x39);
Wire.write(0x03); //move to wait control register
Wire.write(0xFF);
Wire.endTransmission();
Wire.beginTransmission(0x39);
Wire.write(0x0E); //move to prox pulse register
Wire.write(0x10); //16 pulses
Wire.endTransmission();
Wire.beginTransmission(0x39);
Wire.write(0x0F); //move to control register
Wire.write(0x30); //00110000 - 100mA, use both diodes for prox
Wire.endTransmission();
Wire.beginTransmission(0x39);
Wire.write(0x00); //move to enable register
Wire.write(0x7);
Wire.endTransmission();
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.beginTransmission(0x39);
Wire.write(0x18);
Wire.endTransmission();
Wire.requestFrom(0x39, 2);
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.read(); // receive a byte as character
Serial.print("Low= ");
Serial.println(c, HEX);
}
Wire.beginTransmission(0x39);
Wire.write(0x19);
Wire.endTransmission();
Wire.requestFrom(0x39, 2);
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.read(); // receive a byte as character
Serial.print("High= ");
Serial.println(c, HEX);
}
Wire.beginTransmission(0x39);
Wire.write(0x13);
Wire.endTransmission();
Wire.requestFrom(0x39, 2);
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.read(); // receive a byte as character
Serial.print("Status= ");
Serial.println(c, HEX);
}
Wire.beginTransmission(0x39);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(0x39, 2);
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.read(); // receive a byte as character
Serial.print("Enable= ");
Serial.println(c, HEX);
}
delay(500);
}
I go through the process of setting up the various registers, then reading the low byte of the output, then the high byte, but the output I get is always the same, and it always is the register address for first byte, and nothing for the second byte. It appears that I am communicating, but even if I query one of the registers I allegedly set (enable, for instance), the response is the same - address for the first byte, nothing for the second. I'm using 1.5k pullups as per the datasheet and checked out the transmissions under a scope - the edges look pretty clean. Also, beyond the lack of output, I should be seeing 100mA blips on my power supply to drive the IR LED based on the setup configuration - I'm seeing no appreciable power draw at all. So, any ideas what I am doing wrong?
Thanks,
Chris