I am trying to use BH170FVI sensor via on I²C interface on Ubuntu-16.04. My board is UpSquared not Raspberry.
To be able to use i2c interface, I installed i2c-tools
. I also controlled BMI160 sensor with this tool before without meeting a problem.
When I tried to detect my sensor via on terminal with the command:
i2cdetect -r -y 5
This command detects my sensor correctly as shown below:
As it seems my device adress is 0x23
.
After this when I tried to read all the register map data by the command:
i2cdump -y -f 5 0x23
The result is:
The problem is all map adresses are zero. At least one of them should read light amount. I thought the sensor power may off but I tried to use command i2cset
for power-on but still nothing change.
Note: My sensor has no problem because I tried it with Arduino and also with below code:
#!/usr/bin/python
import smbus
import time
# Define some constants from the datasheet
DEVICE = 0x23 # Default device I2C address
POWER_DOWN = 0x00 # No active state
POWER_ON = 0x01 # Power on
RESET = 0x07 # Reset data register value
ONE_TIME_HIGH_RES_MODE = 0x20
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
def convertToNumber(data):
# Simple function to convert 2 bytes of data
# into a decimal number
return ((data[1] + (256 * data[0])) / 1.2)
def readLight(addr=DEVICE):
data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE)
return convertToNumber(data)
def main():
while True:
print "Light Level : " + str(readLight()) + " lux"
time.sleep(0.5)
if __name__=="__main__":
main()
My question is that why I cant control my sensor via on i2c-tools
.
To my knowledge it is not possible doing that with i2c-tools. The problem is the way you need to read the measurement results from BH1750. See datasheet:
S Adr Rd (A) (Data) A (Data) NA P
You cannot create such a sequence with i2c-tools:
Both will result in I2C command sequences which are not what the chip wants.
It worked for me in C from userspace. See my question here:
Read a word (2 byte) without providing a register address from userspace