Here it is, even if the board has not arrived yet.
The program compiles without errors, but take it with a grain of salt, since I tested nothing but the correct addressing on first i2c message on my logic analyzer.
The i2c bus on Arduino (tested on diecimila version) is defined in the library on the analog header (near the power header).
Pin 4 is SDA (data)
Pin 5 is SCL (clock)
Ciao
#include <Wire.h>
#define DEVICE_WRITE 0x74 // Default ADJD-S371 I2C address - write. Would be 0xE8 but only most significant 7 bits.
#define DEVICE_READ 0x74 // Default ADJD-S371 I2C address - read. Would be 0xE9 but only most significant 7 bits.
#define CAP_RED 0x06
#define CAP_GREEN 0x07
#define CAP_BLUE 0x08
#define CAP_CLEAR 0x09
#define INT_RED_LO 0x0A
#define INT_RED_HI 0x0B
#define INT_GREEN_LO 0x0C
#define INT_GREEN_HI 0x0D
#define INT_BLUE_LO 0x0E
#define INT_BLUE_HI 0x0F
#define INT_CLEAR_LO 0x10
#define INT_CLEAR_HI 0x11
#define DATA_RED_LO 0x40
#define DATA_RED_HI 0x41
#define DATA_GREEN_LO 0x42
#define DATA_GREEN_HI 0x43
#define DATA_BLUE_LO 0x44
#define DATA_BLUE_HI 0x45
#define DATA_CLEAR_LO 0x46
#define DATA_CLEAR_HI 0x47
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
Serial.print("Sending Calibration data … ");
adjd_init();
Serial.print("Calibration data sent. ");
}
void loop()
{
adjd_s371_read();
delay(4000);
}
void adjd_s371_read(void)
{
uint16_t red, green, blue, cclear;
// request 8 bytes from slave device
Wire.requestFrom(DEVICE_READ, 8);
if(8 <= Wire.available())
{
red = Wire.receive();
red = red << 8;
red |= Wire.receive();
Serial.println(red);
green = Wire.receive();
green = green << 8;
green |= Wire.receive();
Serial.println(green);
blue = Wire.receive();
blue = blue << 8;
blue |= Wire.receive();
Serial.println(blue);
cclear = Wire.receive();
cclear = cclear << 8;
cclear |= Wire.receive();
Serial.println(cclear);
}
}
static void adjd_init()
{
write_register(CAP_RED, 0x05);
write_register(CAP_GREEN, 0x05);
write_register(CAP_BLUE, 0x05);
write_register(CAP_CLEAR, 0x05);
write_register(INT_RED_LO, 0xC4);
write_register(INT_RED_HI, 0x09);
write_register(INT_GREEN_LO, 0xC4);
write_register(INT_GREEN_HI, 0x09);
write_register(INT_BLUE_LO, 0xC4);
write_register(INT_BLUE_HI, 0x09);
write_register(INT_CLEAR_LO, 0xC4);
write_register(INT_CLEAR_HI, 0x09);
}
static void write_register(uint8_t register_name, uint8_t register_value)
{
Wire.beginTransmission(DEVICE_WRITE);
Wire.send(register_name);
Wire.send(register_value);
Wire.endTransmission();
}