Documentation ¶
Overview ¶
Package bh1750 controls a ROHM BH1750 ambient light sensor, over an i2c bus.
Datasheet ¶
http://cpre.kmutnb.ac.th/esl/learning/bh1750-light-sensor/bh1750fvi-e_datasheet.pdf
Example ¶
package main import ( "fmt" "log" "periph.io/x/periph/conn/i2c/i2creg" "periph.io/x/periph/experimental/devices/bh1750" "periph.io/x/periph/host" ) func main() { // Make sure periph is initialized. if _, err := host.Init(); err != nil { log.Fatal(err) } // Open default I²C bus. bus, err := i2creg.Open("") if err != nil { log.Fatalf("failed to open I²C: %v", err) } defer bus.Close() // Create a new light sensor. sensor, err := bh1750.NewI2C(bus, bh1750.I2CAddr) if err != nil { log.Fatalln(err) } // Read value from sensor. measurement, err := sensor.Sense() if err != nil { log.Fatalln(err) } fmt.Println(measurement) }
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const AlternativeI2CAddr uint16 = 0x5c
AlternativeI2CAddr i2c alternative address.
View Source
const I2CAddr uint16 = 0x23
I2CAddr i2c default address.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is a handler to bh1750 controller
func NewI2C ¶
NewI2C opens a handle to an bh1750 sensor.
To use on the default address, bh1750.I2CAddr must be passed as argument.
func (*Dev) Sense ¶
func (d *Dev) Sense() (physic.LuminousFlux, error)
Sense reads the light value from the bh1750 sensor.
func (*Dev) SetResolution ¶
func (d *Dev) SetResolution(r Resolution) error
SetResolution set the resolution mode of the sensor.
type Resolution ¶
type Resolution uint8
Resolution represents the measurements modes.
const ( // ContinuousHighResMode start measurement at 1lx resolution. Measurement time is approx 120ms. ContinuousHighResMode Resolution = 0x10 // ContinuousHighResMode2 start measurement at 0.5lx resolution. Measurement time is approx 120ms. ContinuousHighResMode2 Resolution = 0x11 // ContinuousLowResMode start measurement at 4lx resolution. Measurement time is approx 16ms. ContinuousLowResMode Resolution = 0x13 // OneTimeHighResMode measurement at 1lx resolution and the device is automatically set to Power Down after measurement. OneTimeHighResMode Resolution = 0x20 // OneTimeHighResMode2 measurement at 0.5lx resolution and the device is automatically set to Power Down after measurement. OneTimeHighResMode2 Resolution = 0x21 // OneTimeLowResMode measurement at 4lx resolution and the device is automatically set to Power Down after measurement. OneTimeLowResMode Resolution = 0x23 )
Click to show internal directories.
Click to hide internal directories.