3

I'm writing code in Raspberry Pi, trying to communicate BH1750 ambient light sensor connected in a I2C port. Most working ways are using Python SMBus library but I'm writing C++ code. After some search, I found that:

  • The well-known wiringPi library seems outdated and even removed from raspbian's repo.
  • the i2c-tools is not usable, as it requires a memory mapping of client functions, but BH1750 is based on simple raw data flows.
  • There are i2c.h and i2c-dev.h Linux API, so at least I can use them as a last resort.
  • In Linux repo, there is a bh1750.c source file, so I guess there are some easy-to-use APIs and I don't need to write communication code at all. But I don't find a bh1750.h in /usr/include/linux. Instead, there is a /usr/include/linux/iio directory, but header files in it don't provide any function APIs and I don't know how to use it.

How can I use the BH1750 support in Linux kernel?

0andriy
  • 4,183
  • 1
  • 24
  • 37
jiandingzhe
  • 1,881
  • 15
  • 35
  • 1
    You need to install `libiio` which provides a rich API for the C code and IIRC there is a Python binding. But even in shell you may do some things (single reads of raw values or so) without any of the libraries at all. – 0andriy Apr 16 '23 at 20:47

0 Answers0