• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

bh1750 • AttributeError: 'module' object has no attribute 'luminance'

Q&A Forum › bh1750 • AttributeError: 'module' object has no attribute 'luminance'
0 Vote Up Vote Down
Steve asked 1 year ago

Could I ask for some help please troubleshooting the above error.
line 22 in main.py
code here:
https://pastebin.com/urwKuKnZ
and module here
https://pastebin.com/urwKuKnZ
line 49
Thank you

Question Tags: light sensor I2C
17 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
You shared the same link twice.
I didn’t receive your main.py file.
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hello Sara,
It was kinda late and I had been trying to work it out myself for quite some time.
Try this
https://pastebin.com/Z6rqg7Mk
Thank you
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
Replace:

light = bh1750 

with

light = bh1750.BH1750(i2c)

Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hi Sara
Thank you.
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Is everything working now?
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hello Sara
Thank you for the follow-up.
I have not had the chance to pick this project up again but once I do I’ll make a note here if all’s good
or raise a new question
Seasons Greetings
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Thanks.
Then, let me know if it fixed the issue.
Regards.
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hi Again
I made it beyond that error to:
File “main.py”, line 22, in <module>
AttributeError: ‘module’ object has no attribute ‘ONCE_HIRES_1’
Looking at main.py and bh1750.py I THINK I can begin to see what’s wrong but I don’t yet, know how to sort it.
Regards
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
I’m sorry for taking so long to get back to you.
What does your code look like at the moment?
Did you double-check that you have loaded the library properly?
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hi Sara
No worries with the slow response.
Immediately after my previous post regarding the AttributeError:
‘module’ object has no attribute ‘ONCE_HIRES_1’
I messed around with the code to see if I could effect a change and when that didn’t work out I put it it to one side over the break.
Picking it up again this evening I was initially unable to repeat the problem.
I was getting a string of errors in the module for the ssd1306
So I hashed out the lines relating to the SSD1306 in main.py.
‘module’ object has no attribute ‘ONCE_HIRES_1’
now appears
I think this points to line 19 in the bh1750.py module:
https://pastebin.com/urwKuKnZ
The modified main.py file is here:
https://pastebin.com/sayNF0DC
NOTE. I fully appreciate this will not work. Its not complete
My thinking is; To get as far as getting the data off the bh1750 I can the move on to getting it to display on the ssd1306.
My next step will be to print the value of lux in the REPL then move on to showing it on a ssd1306.
Thank you
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
Can you share the Github page of the library?
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hello Sara
Here it is.
https://github.com/PinkInk/upylib/blob/master/bh1750/bh1750/__init__.py
Thank you
Steve
 

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
I think this line should be (BH1750 because it’s the class of the library and not the library itself)

lux=light.luminance(BH1750.ONCE_HIRES_1) ## Sample luminance in lux

Take a look at the example provided: https://github.com/PinkInk/upylib/blob/master/bh1750/test.py
I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hi
Sadly I have not been able to progress any further.
Maybe I have bitten off more than I can learn.
My idea had been to use the reading(s) from the BH1750 in conjunction with a PIR to trigger an alert (only) during the day with the addition of turning outside lights on at night.
I am going to put put the idea aside for the time being and work on some other I2C projects. There are 2 in MicroPython Programming with….
Can you suggest any others?
Thank you for your help.
Happy New Year
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
You said “There are 2 in MicroPython Programming with….
Can you suggest any others?”
 
I’m sorry, but I didn’t understand your question. Can you reformulate it?
Regards,
Sara

0 Vote Up Vote Down
Steve answered 1 year ago

Hi,
Apologies, my message was incomplete.
I was enquiring about other courses relating specifically to Micropython.
BUT
I have since found Ruis’s mail-out – dated 19th Aug last entitled
9 MicroPython Guides: Sensors/Modules with the ESP32/ESP8266.
Which, I think, will keep me going.
Regards
Steve

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

We only have one eBook about MicroPython with the ESP32: https://randomnerdtutorials.com/micropython-programming-with-esp32-and-esp8266/
We also have several free ESP32 and ESP8266 MicroPython tutorials. You can check them all here: https://randomnerdtutorials.com/projects-esp32-esp8266-micropython/
 
Let me know if you need further help.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.