Jeremy Harris
Senior Member
I recently bought a couple of these sensors, mounted on interface boards with 3.3V regulators, level shifters and 4k7 pull-ups. I assumed they'd be fairly easy to hook up to a Picaxe, but it seems that it isn't as easy as I'd thought. The datasheet isn't great (it's sort of written in Chinglish - see here: http://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf ).
AFAICS, using this should be pretty straightforward, just send the right command to put the device into the correct mode, then read the light value register as a pair of bytes, hi byte first.
If only. I've spent an hour or so trying to read data out of this device to no avail. The only clue I have to what might, just possibly, be the problem is that the LSB of the address (the eighth bit) sets read or write, and this seems (unless I've misunderstood the datasheet - quite possible) to be the wrong way around. I've always assumed (and would guess that HI2CIN and HI2COUT use) this eighth bit in the sense that 1 = write, 0 = read, yet the datasheet seems to suggest that this chip uses 0 = write, 1 = read (assuming I've read it correctly).
If anyone has used on of these sensors with a Picaxe and got it working I'd appreciate some insight into driving it. I'm about to revert to bit bashing it if I can't get the HI2C commands to work (BTW, I have set it up correctly, right address, slow I2C, byte size instructions, etc).
AFAICS, using this should be pretty straightforward, just send the right command to put the device into the correct mode, then read the light value register as a pair of bytes, hi byte first.
If only. I've spent an hour or so trying to read data out of this device to no avail. The only clue I have to what might, just possibly, be the problem is that the LSB of the address (the eighth bit) sets read or write, and this seems (unless I've misunderstood the datasheet - quite possible) to be the wrong way around. I've always assumed (and would guess that HI2CIN and HI2COUT use) this eighth bit in the sense that 1 = write, 0 = read, yet the datasheet seems to suggest that this chip uses 0 = write, 1 = read (assuming I've read it correctly).
If anyone has used on of these sensors with a Picaxe and got it working I'd appreciate some insight into driving it. I'm about to revert to bit bashing it if I can't get the HI2C commands to work (BTW, I have set it up correctly, right address, slow I2C, byte size instructions, etc).