-3

So,

Currently I am using a RTC with my Pi. It takes up the SDA and SCL pins which are GPIO2 and GPIO3.

I now wish to add a Lux sensor. I am using the BH1750 Light Sensor. It too needs to use the SDA and SCL GPIO pin.

The design I am using cannot use a shim or hat in addition to everything else that I am using so the only option I have is to use different pins.

I read how to 'add' additional I2C ports by adding an entry to the boot.config file. Which was this line:

dtoverlay=i2c-gpio,bus=2,i2c_gpio_sda=12,i2c_gpio_scl=13  

So I am saying (hopefully) use GPIO pins 12 and 13.

But the sensor does not show up:

I tested that by 1st typing in:

sudo i2cdetect -1

Which gave me:

enter image description here

Then I did this:

sudo i2cdetect -y 3

Which gave me:

enter image description here

11
  • You need to explain how you are connecting devices and why you can't use the normal bus.
    – Milliways
    Jun 30 at 8:35
  • 1
    DO NOT post pictures of text post TEXT
    – Milliways
    Jun 30 at 8:38
  • @Milliways Sorry what does that mean? What is wrong with a screenshot? Is that not more clearer than just typing the text.? Jun 30 at 8:40
  • Unless you mean type TEXT for the commands and put the result into the sreenshot only. Hapopy to do so if that is what you meant. Please confirm? Thanks Jun 30 at 8:43
  • 1
    Is that not more clearer than just typing the text ... not type text ... copy the text and paste it into the question ... how can a picture of text be clearer than the text? ... text can be read by people with vision problems, pictures cannot
    – jsotola
    Jul 2 at 2:53

1 Answer 1

2

I2C is a bus, and that means you can connect more than a single device to the same bus (SDA+SCL pair). IOW, you can connect your RTC and your BH1750 Light Sensor to the I2C bus on pins GPIO 2 & GPIO 3 (I2C1).

Since you already have I2C1 set up for use with your RTC, all you should need to do is add the device tree overlay for the BH1750 to the file at /boot/config.txt. Consult the file /boot/overlays/README file on your RPi's local drive (or the GitHub version here) to get the proper syntax for the overlay; it should be something like this assuming you have grounded the ADDR pin on the BH1750:

dtoverlay=i2c-sensor,bh1750=0x23

You can install & use the i2c-tools package to verify your I2C bus is working properly before you start coding:

$ sudo apt update
...
$ sudo apt install i2c-tools 
...
$ i2cdetect -y 1
... which should yield something like this : 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- UU -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The UU designation at addr 0x23 indicates the driver for the BH1750 has been loaded. If you don't see this, try rebooting, or use the dtoverlay command if you're feeling frisky :)

4
  • Hi, many thanks for your reply. But this would involve physically connecting both to the same pins. The design I am using cannot use a shim or hat in addition to everything else that I am using so the only option I have is to use different pins. But useful info. Thanks Jun 30 at 6:39
  • 2
    @AndrewSimpson So you put the real question in a comment to an answer. People tend to look at questions just the once. The people who could have answered your question will probably never see this new information.
    – joan
    Jun 30 at 8:20
  • Ah. Thank you Joan, I got a lot to learn. Let me adjuts. Many thanks! Jun 30 at 8:22
  • I am going to accept this answer. I have wired to wires to one GPIO end point and it works. So thank you Jun 30 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.