Moderators: adafruit_support_bill, adafruit
hibyte = self.bus.read_byte_data(self.address, reg)
result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1)
pandring wrote:Also, do you know of a python library I can use to calculate lux? I see that there is code for a C++ function to convert lux, but it would make my life a lot easier if there's a premade python function out there.
from Adafruit_I2C import * ## Code from Github
address = 0x39 ## Device address
control_on = 0x03 ## "On" value
control_off = 0x00 ## "Off" value
i2c = Adafruit_I2C(address)
def enable():
print "enabling"
i2c.write8(0x00, control_on) ##Writes on value to control register
def disable():
print "disabling"
i2c.write8(control, control_off) ##Writes off value to control register
def getLight():
Channel0 = i2c.readU16(0x8C) ## Read total light (from channel 0)
Channel1 = i2c.readU8(0x8E) ## Read infrared light (from channel 1)
return Channel0, Channel1
enable()
print getLight()
void TSL2561::enable(void)
{
// Enable the device by setting the control bit to 0x03
write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
void TSL2561::disable(void)
{
// Disable the device by setting the control bit to 0x03
write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
#define TSL2561_COMMAND_BIT (0x80)
. . .
TSL2561_REGISTER_CONTROL = 0x00,
. . .
#define TSL2561_CONTROL_POWERON (0x03) uint32_t x;
x = read16(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= read16(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
uint32_t x;
x = read16(0xAE);
x <<= 16;
x |= read16(0xAC);
Return to General Project help
Users browsing this forum: csracruisers and 10 guests