Hello, I am new to forums, microcontrollers, and Arduino!
I am trying to interface the ADJD-S313-QR999 Reflective Color Sensor to an Arduino Duemilanove.
I want to output the contents of the registers of the Avago sensor to the serial terminal on the computer.
I believe I have powered the sensor properly and I have written the following code:
/*program for ADJD-S313-QR999 Reflective Color Sensor
Draft by Bradley J Piekie?ko
Start date: September 18, 2011
Corrections/Assistance by
*/
#include "Wire.h"
byte r = 0x00;//variable for storing data from ADJD-S313 RED register
byte g = 0x00;//variable for storing data from ADJD-S313 GREEN register
byte b = 0x00;//variable for storing data from ADJD-S313 BLUE register
void setup()
{
Wire.begin();
Serial.begin(9600);//allows computer terminal output
int xrset = 13;//sets pin 13 as ADJD-S313 reset
pinMode(xrset, OUTPUT);
digitalWrite(xrset, LOW);//a LOW will reset all registers on the ADJD-S313
delay(500);// ??necessary??
digitalWrite(xrset,HIGH);
/???set ADJD-S313 as slave???/
Wire.beginTransmission(0x58);
Wire.send(0);
Wire.endTransmission();
/at the start of the application, the following setup data must be written
to the setup registers:/
Wire.beginTransmission(0x03);//address of ADJD-S313 SETUP0 register
Wire.send(0x01);
Wire.endTransmission();
Wire.beginTransmission(0x04);//address of ADJD-S313 SETUP1 register
Wire.send(0x01);
Wire.endTransmission();
Wire.beginTransmission(0x0C);//address of ADJD-S313 SETUP2 register
Wire.send(0x01);
Wire.endTransmission();
Wire.beginTransmission(0x0D);//address of ADJD-S313 SETUP3 register
Wire.send(0x01);
Wire.endTransmission();
Wire.beginTransmission(0x0E);//address of ADJD-S313 SETUP4 register
Wire.send(0x01);
Wire.endTransmission();
}
void loop()
{
/to obtain sensor ADC value, '02' Hex must be written to ACQ register
before reading the sensor ADC output registers/
Wire.beginTransmission(0x02);//address of ACQ register
Wire.send(0x02);//sends '02' hex to the ACQ register
Wire.endTransmission();
Wire.requestFrom(0x44, 1);//address of the ADJD-S313 RED register
r = Wire.receive();
Wire.requestFrom(0x43, 1);//address of the ADJD-S313 GREEN register
g = Wire.receive();
Wire.requestFrom(0x42, 1);//address of the ADJD-S313 BLUE register
b = Wire.receive();
Serial.println(r);
Serial.println(g);
Serial.println(b);
delay(1000);//makes output readable
}
I get no output on the terminal. I think it is an addressing issue?
I am not sure when to use the "slave" address for the Avago sensor,
and when to use the addresses of the specific registers.
I have attached the datasheet for the Avago sensor.
So...
Any assistance would be appreciated.
Maybe my entire code is wrong.
If so, where is a good place to learn the I2C interface?
Thanks
ColorSensorDatasheet.pdf (1.12 MB)