Code Monkey home page Code Monkey logo

pico-bh1750's Introduction

pico-bh1750

This is a MicroPython library for the Raspberry Pi Pico and the BH1750 digital Ambient Light Sensor.

Example

from machine import Pin, I2C
from utime import sleep

from bh1750 import BH1750

i2c0_sda = Pin(8)
i2c0_scl = Pin(9)
i2c0 = I2C(0, sda=i2c0_sda, scl=i2c0_scl)

bh1750 = BH1750(0x23, i2c0)

while True:
    print(bh1750.measurement)
    sleep(1)

This is the circuit for the example code above. It uses the GY-302 BH1750 breakout board.

Fritzing wiring for the example code.

Customizing configuration

By default, the BH1750 class uses the following settings:

  • Measurement mode: 'one time' (it measures once and then shuts down, a next measurement automatically powers the device back on and configures it again),
  • Resolution: high (1 lx)
  • Measurement time: 120 ms

These values can be changed via the configure method:

bh1750.configure(BH1750.MEASUREMENT_MODE_CONTINUOUSLY,
                 BH1750.RESOLUTION_HIGH_2,
                 BH1750.MEASUREMENT_TIME_MAX)

The example above configures the BH1750 to measure continuously, use a higher resolution (0.5 lx) and the maximum measurement time. Configuration can greatly affect the measurement time. The BH1750 class has a generator function that attempts to calculate the correct 'sleep time' between measurements based on the chosen configuration:

for measurement in bh1750.measurements():
    print(measurement)

pico-bh1750's People

Contributors

flrrth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pico-bh1750's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.