Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. BH1750 library hangs

BH1750 library hangs

Scheduled Pinned Locked Moved Troubleshooting
20 Posts 2 Posters 3.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    João Gouveia
    wrote on last edited by
    #1

    Hello everyone!

    I have been am trying to make a wireless light sensor to connect to my home assistant. As of now I have been successfully using one connected directly to the pi but I want to be able to eventually use different ones and spread them around the house so I decided to go with MySensors for that.

    I have an Arduino mini pro connected to an NRF24L01+ wireless radio that uses my Pi as the gateway. I have successfully established a connection and I am able to send messages to the Pi and see the results in home assistant.
    What I don't seem to be able to do is get information from the light sensor. I am using a BH1750 light sensor for that.

    I have two versions, one is the GY-302 (small one) and the other GY-30 (longer one). They both work well when connected directly to the pi. I can get light levels both through a python script and directly to home assistant.
    When I connect them to my arduino though the BH1750 library doesn't work.

    • With the GY-302 it just crashes on calling begin. I have dug under the library and realized it hangs on the call endTransmission.
    • With the GY-30 it does not hang but instead it always reports the same value of lux, no matter how much light I put on it or how much light I remove from it. The value is always 54612.

    I am a software engineer by profession so my circuit skills are extremely low and it is likely I am doing something wrong.
    At first I thought that, since I am a newbie, I fried something while soldering so I soldered a new mini pro (same manufacturer) but I got the same results.

    I was mostly following this guide online: http://sebastiaanschimmel.me/blog/2015/06/arduino-temp-hum-light-sensor.html so my circuit looks like the one described (without the temperature sensor). I can send pictures of it if required.

    The boards I got are the following:
    https://www.aliexpress.com/item/WAVGAT-Atmega328-3-3V-Version-Pro-Mini-Module-16M-For-Arduino-Compatible/32820596876.html?spm=a2g0s.9042311.0.0.rYlqk6
    https://www.aliexpress.com/item/1Pcs-New-Arrival-BH1750FVI-GY-302-GY302-Digital-Light-intensity-Sensor-BH1750-16bitAD-Module-For-AVR/32821717980.html?spm=a2g0s.9042311.0.0.rYlqk6
    https://www.aliexpress.com/item/1pc-Basic-Breakout-Board-For-FTDI-FT232RL-USB-to-Serial-IC-For-Hot-Top-Sale/32648158894.html?spm=a2g0s.9042311.0.0.2Wt045

    Hope someone is able to help! :)

    Thanks and sorry for the long post!!

    alexsh1A 1 Reply Last reply
    0
    • J João Gouveia

      Hello everyone!

      I have been am trying to make a wireless light sensor to connect to my home assistant. As of now I have been successfully using one connected directly to the pi but I want to be able to eventually use different ones and spread them around the house so I decided to go with MySensors for that.

      I have an Arduino mini pro connected to an NRF24L01+ wireless radio that uses my Pi as the gateway. I have successfully established a connection and I am able to send messages to the Pi and see the results in home assistant.
      What I don't seem to be able to do is get information from the light sensor. I am using a BH1750 light sensor for that.

      I have two versions, one is the GY-302 (small one) and the other GY-30 (longer one). They both work well when connected directly to the pi. I can get light levels both through a python script and directly to home assistant.
      When I connect them to my arduino though the BH1750 library doesn't work.

      • With the GY-302 it just crashes on calling begin. I have dug under the library and realized it hangs on the call endTransmission.
      • With the GY-30 it does not hang but instead it always reports the same value of lux, no matter how much light I put on it or how much light I remove from it. The value is always 54612.

      I am a software engineer by profession so my circuit skills are extremely low and it is likely I am doing something wrong.
      At first I thought that, since I am a newbie, I fried something while soldering so I soldered a new mini pro (same manufacturer) but I got the same results.

      I was mostly following this guide online: http://sebastiaanschimmel.me/blog/2015/06/arduino-temp-hum-light-sensor.html so my circuit looks like the one described (without the temperature sensor). I can send pictures of it if required.

      The boards I got are the following:
      https://www.aliexpress.com/item/WAVGAT-Atmega328-3-3V-Version-Pro-Mini-Module-16M-For-Arduino-Compatible/32820596876.html?spm=a2g0s.9042311.0.0.rYlqk6
      https://www.aliexpress.com/item/1Pcs-New-Arrival-BH1750FVI-GY-302-GY302-Digital-Light-intensity-Sensor-BH1750-16bitAD-Module-For-AVR/32821717980.html?spm=a2g0s.9042311.0.0.rYlqk6
      https://www.aliexpress.com/item/1pc-Basic-Breakout-Board-For-FTDI-FT232RL-USB-to-Serial-IC-For-Hot-Top-Sale/32648158894.html?spm=a2g0s.9042311.0.0.2Wt045

      Hope someone is able to help! :)

      Thanks and sorry for the long post!!

      alexsh1A Offline
      alexsh1A Offline
      alexsh1
      wrote on last edited by
      #2

      @joão-gouveia Did you try to run it with different arduino / radio? Just to eliminate hardware issue. My ESP8266 is working fine with my GY-302 module.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        João Gouveia
        wrote on last edited by
        #3

        @alexsh1 said in BH1750 library hangs:

        ESP8266

        You mean a different model? Unfortunately I don't have another model to test it, only mini pro. I have tried another mini pro (same manufacturer though). I also don't have another model of the radio. But the messages are being sent properly so I am not sure if the problem could come from that.

        alexsh1A 1 Reply Last reply
        0
        • J João Gouveia

          @alexsh1 said in BH1750 library hangs:

          ESP8266

          You mean a different model? Unfortunately I don't have another model to test it, only mini pro. I have tried another mini pro (same manufacturer though). I also don't have another model of the radio. But the messages are being sent properly so I am not sure if the problem could come from that.

          alexsh1A Offline
          alexsh1A Offline
          alexsh1
          wrote on last edited by
          #4

          @joão-gouveia I do not mean different model, I mean GY-302. I have the same setup with atmega328p and BH1750 running fine as well. Lib is not a problem - this is what I am trying to say.

          Show your wiring please. How do you connect the module?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            João Gouveia
            wrote on last edited by
            #5

            I have tried with both a GY-302 and a GY-30 and both don't work although they show different problems (mentioned on my OP). Both the sensors work well when connected to the pi.

            I don't have a drawing of the circuit but I can show you a picture, if it helps.

            0_1522680160710_IMG_20180402_163933.jpg

            The diagram is essential like this one but without the temperature sensor and I am currently using an FTDI board to provide the power, instead of a battery.

            The SCL is connected to A5 and the SDA to A4 of the mini pro.

            I can also do a drawing, if further info is required but, as I said, it is like the one I linked above.

            alexsh1A 2 Replies Last reply
            1
            • J João Gouveia

              I have tried with both a GY-302 and a GY-30 and both don't work although they show different problems (mentioned on my OP). Both the sensors work well when connected to the pi.

              I don't have a drawing of the circuit but I can show you a picture, if it helps.

              0_1522680160710_IMG_20180402_163933.jpg

              The diagram is essential like this one but without the temperature sensor and I am currently using an FTDI board to provide the power, instead of a battery.

              The SCL is connected to A5 and the SDA to A4 of the mini pro.

              I can also do a drawing, if further info is required but, as I said, it is like the one I linked above.

              alexsh1A Offline
              alexsh1A Offline
              alexsh1
              wrote on last edited by
              #6

              @joão-gouveia Do you have any other sensors you could try with Pro mini?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                João Gouveia
                wrote on last edited by
                #7

                Not at the moment but I ordered a DHT22 sensor I can try that when it arrives.

                1 Reply Last reply
                0
                • J João Gouveia

                  I have tried with both a GY-302 and a GY-30 and both don't work although they show different problems (mentioned on my OP). Both the sensors work well when connected to the pi.

                  I don't have a drawing of the circuit but I can show you a picture, if it helps.

                  0_1522680160710_IMG_20180402_163933.jpg

                  The diagram is essential like this one but without the temperature sensor and I am currently using an FTDI board to provide the power, instead of a battery.

                  The SCL is connected to A5 and the SDA to A4 of the mini pro.

                  I can also do a drawing, if further info is required but, as I said, it is like the one I linked above.

                  alexsh1A Offline
                  alexsh1A Offline
                  alexsh1
                  wrote on last edited by alexsh1
                  #8

                  @joão-gouveia hard to tell. I spent days trying to troubleshoot the connectivity problem and it turned out to be a bad nrf24l01+. Just to make sure - you have no RF issues? Pro Mini is talking to RPi no problem?

                  Another possible issue is I2C - this is why it is freezing on Wire.begin(); Double check wiring just in case. (SDA and SDL correctly connected?). You can also use an example sketch to scan i2c bus. You may need to update the lib with the correct address.

                  If both sensors are working with RPi, this eliminates them.

                  J 1 Reply Last reply
                  0
                  • alexsh1A alexsh1

                    @joão-gouveia hard to tell. I spent days trying to troubleshoot the connectivity problem and it turned out to be a bad nrf24l01+. Just to make sure - you have no RF issues? Pro Mini is talking to RPi no problem?

                    Another possible issue is I2C - this is why it is freezing on Wire.begin(); Double check wiring just in case. (SDA and SDL correctly connected?). You can also use an example sketch to scan i2c bus. You may need to update the lib with the correct address.

                    If both sensors are working with RPi, this eliminates them.

                    J Offline
                    J Offline
                    João Gouveia
                    wrote on last edited by
                    #9

                    @alexsh1 There doesn't seem to be no RF issues, no. The freezing occurs on Wire.endTransmition(), not begin. I meant the begin function of the BH1750 library from MySensors, sorry if that wasn't very clear.

                    SDA and SDL seem to be connected correcly. I've checked that a few times now.

                    alexsh1A 1 Reply Last reply
                    0
                    • J João Gouveia

                      @alexsh1 There doesn't seem to be no RF issues, no. The freezing occurs on Wire.endTransmition(), not begin. I meant the begin function of the BH1750 library from MySensors, sorry if that wasn't very clear.

                      SDA and SDL seem to be connected correcly. I've checked that a few times now.

                      alexsh1A Offline
                      alexsh1A Offline
                      alexsh1
                      wrote on last edited by alexsh1
                      #10

                      @joão-gouveia OK, if i2c wiring is fine, load up i2c scanner and see if you can read the sensor address.

                      J 1 Reply Last reply
                      0
                      • alexsh1A alexsh1

                        @joão-gouveia OK, if i2c wiring is fine, load up i2c scanner and see if you can read the sensor address.

                        J Offline
                        J Offline
                        João Gouveia
                        wrote on last edited by
                        #11

                        @alexsh1 I ran this example: https://playground.arduino.cc/Main/I2cScanner (I'm not sure if this is what you meant).

                        It seems to hang on Wire.endTransmition() it prints the string "Scanning..." but nothing else.

                        alexsh1A 1 Reply Last reply
                        0
                        • J João Gouveia

                          @alexsh1 I ran this example: https://playground.arduino.cc/Main/I2cScanner (I'm not sure if this is what you meant).

                          It seems to hang on Wire.endTransmition() it prints the string "Scanning..." but nothing else.

                          alexsh1A Offline
                          alexsh1A Offline
                          alexsh1
                          wrote on last edited by alexsh1
                          #12

                          @joão-gouveia Yes, that's what I meant. OK, here we go - this is an i2c problem. I am shooting a bit in the dark here - how about trying to change your power source? Maybe a different 3.3V FTDI adapter.

                          J 1 Reply Last reply
                          0
                          • alexsh1A alexsh1

                            @joão-gouveia Yes, that's what I meant. OK, here we go - this is an i2c problem. I am shooting a bit in the dark here - how about trying to change your power source? Maybe a different 3.3V FTDI adapter.

                            J Offline
                            J Offline
                            João Gouveia
                            wrote on last edited by
                            #13

                            @alexsh1 Hm that seems reasonable. The FTDI board I have seems to be a bit funky it gives a lot of errors when I am trying to upload sometimes. Could that be related? I am not sure if it is the FTDI or the mini pro itself though.

                            I don't have another type with me though.

                            alexsh1A 1 Reply Last reply
                            0
                            • J João Gouveia

                              @alexsh1 Hm that seems reasonable. The FTDI board I have seems to be a bit funky it gives a lot of errors when I am trying to upload sometimes. Could that be related? I am not sure if it is the FTDI or the mini pro itself though.

                              I don't have another type with me though.

                              alexsh1A Offline
                              alexsh1A Offline
                              alexsh1
                              wrote on last edited by
                              #14

                              @joão-gouveia A good a reliable power source is a key unless you what to spend hours troubleshooting. Yes, FTDI could be the reason when used as a power source.

                              Another thing to try is to load an example sketch for BH1750, disconnect the FTDI adapter and use 2xAA batteries to power up your schematic. Then you can check your controller for a log. Unfortunately, you cannot check the log on the node.

                              J 1 Reply Last reply
                              1
                              • alexsh1A alexsh1

                                @joão-gouveia A good a reliable power source is a key unless you what to spend hours troubleshooting. Yes, FTDI could be the reason when used as a power source.

                                Another thing to try is to load an example sketch for BH1750, disconnect the FTDI adapter and use 2xAA batteries to power up your schematic. Then you can check your controller for a log. Unfortunately, you cannot check the log on the node.

                                J Offline
                                J Offline
                                João Gouveia
                                wrote on last edited by
                                #15

                                @alexsh1 I think I will try to get a more reliable FTDI since this one seems to give me some troubles. It also isn't properly detected on my PC sometimes. Is there a reliable one I could get from, for example, aliexpress, you recommend? My knowledge on these is close to zero, hahaha. Thanks. :)

                                alexsh1A 1 Reply Last reply
                                0
                                • J João Gouveia

                                  @alexsh1 I think I will try to get a more reliable FTDI since this one seems to give me some troubles. It also isn't properly detected on my PC sometimes. Is there a reliable one I could get from, for example, aliexpress, you recommend? My knowledge on these is close to zero, hahaha. Thanks. :)

                                  alexsh1A Offline
                                  alexsh1A Offline
                                  alexsh1
                                  wrote on last edited by
                                  #16

                                  @joão-gouveia I would highly recommend Adafruit FTDI :

                                  https://www.adafruit.com/product/284

                                  Expensive, yes, but I modified with two switches - 3.3V-5V power and 3.3v-5V logic level.

                                  Alternatively, you can try a few cheap Aliexpress ones like this one (make sure it is a genuine FTDI chip):

                                  https://www.aliexpress.com/item/1PCS-FT232RL-Serial-adapter-Module-USB-to-TTL-3-3V-5V-Mini-USB-TTL/32326225256.html?ws_ab_test=searchweb0_0,searchweb201602_1_10152_10151_10065_10344_10130_10068_10324_10342_10547_10325_10343_10340_10548_10341_10697_10696_10192_10190_10084_10083_10618_10307_10301_10303_10059_10184_10534_100031_10103_441_10624_10623_10622_10621_10620,searchweb201603_25,ppcSwitch_5&algo_expid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0-2&algo_pvid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0&transAbTest=ae803_2&priceBeautifyAB=0

                                  J 2 Replies Last reply
                                  0
                                  • alexsh1A alexsh1

                                    @joão-gouveia I would highly recommend Adafruit FTDI :

                                    https://www.adafruit.com/product/284

                                    Expensive, yes, but I modified with two switches - 3.3V-5V power and 3.3v-5V logic level.

                                    Alternatively, you can try a few cheap Aliexpress ones like this one (make sure it is a genuine FTDI chip):

                                    https://www.aliexpress.com/item/1PCS-FT232RL-Serial-adapter-Module-USB-to-TTL-3-3V-5V-Mini-USB-TTL/32326225256.html?ws_ab_test=searchweb0_0,searchweb201602_1_10152_10151_10065_10344_10130_10068_10324_10342_10547_10325_10343_10340_10548_10341_10697_10696_10192_10190_10084_10083_10618_10307_10301_10303_10059_10184_10534_100031_10103_441_10624_10623_10622_10621_10620,searchweb201603_25,ppcSwitch_5&algo_expid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0-2&algo_pvid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0&transAbTest=ae803_2&priceBeautifyAB=0

                                    J Offline
                                    J Offline
                                    João Gouveia
                                    wrote on last edited by
                                    #17

                                    @alexsh1 Thanks I will check it out and give it a try! :) I'll let you know the results

                                    1 Reply Last reply
                                    0
                                    • alexsh1A alexsh1

                                      @joão-gouveia I would highly recommend Adafruit FTDI :

                                      https://www.adafruit.com/product/284

                                      Expensive, yes, but I modified with two switches - 3.3V-5V power and 3.3v-5V logic level.

                                      Alternatively, you can try a few cheap Aliexpress ones like this one (make sure it is a genuine FTDI chip):

                                      https://www.aliexpress.com/item/1PCS-FT232RL-Serial-adapter-Module-USB-to-TTL-3-3V-5V-Mini-USB-TTL/32326225256.html?ws_ab_test=searchweb0_0,searchweb201602_1_10152_10151_10065_10344_10130_10068_10324_10342_10547_10325_10343_10340_10548_10341_10697_10696_10192_10190_10084_10083_10618_10307_10301_10303_10059_10184_10534_100031_10103_441_10624_10623_10622_10621_10620,searchweb201603_25,ppcSwitch_5&algo_expid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0-2&algo_pvid=1d05e7ee-d1d0-4628-b1ab-56fd947c7eb0&transAbTest=ae803_2&priceBeautifyAB=0

                                      J Offline
                                      J Offline
                                      João Gouveia
                                      wrote on last edited by
                                      #18

                                      @alexsh1 I just realized my full blown stupidity. The breadboard I am using has the buses connected half way and I was convinced they were fully connected. So the light sensor was not getting power, obviously. :man-facepalming: :man-facepalming: :man-facepalming: :man-facepalming: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile:

                                      It works now.

                                      alexsh1A 1 Reply Last reply
                                      0
                                      • J João Gouveia

                                        @alexsh1 I just realized my full blown stupidity. The breadboard I am using has the buses connected half way and I was convinced they were fully connected. So the light sensor was not getting power, obviously. :man-facepalming: :man-facepalming: :man-facepalming: :man-facepalming: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile:

                                        It works now.

                                        alexsh1A Offline
                                        alexsh1A Offline
                                        alexsh1
                                        wrote on last edited by
                                        #19

                                        @joão-gouveia The problem is very often much simpler than we think :-)

                                        J 1 Reply Last reply
                                        0
                                        • alexsh1A alexsh1

                                          @joão-gouveia The problem is very often much simpler than we think :-)

                                          J Offline
                                          J Offline
                                          João Gouveia
                                          wrote on last edited by
                                          #20

                                          @alexsh1 Very true :) Anyways, thanks for the tips!

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          27

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular