Ambient light control #1

Open
opened 1 year ago by kemonine · 0 comments
kemonine commented 1 year ago
Owner

The Raspberry Pi 4 doesn't have proper HDMI 'stuff' via i2c or similari which dccutil needs to manage things like brightness of a display.

When this support is available, use the below ideas to get automatic HDMI brightness based on a LUX sensor working.


tweak /boot/config.txt to have dtoverlay=vc4-kms-v3d instead of fkms
apt install i2c-tools
cat > /etc/modules-load.d/i2c.conf <<EOF
i2c-dev
EOF
modprobe i2c-dev
lsmod | grep i2c
ls /dev/i2c*
i2cdetect -r -y 11
i2cdetect 1

pip3 install RPI.GPIO
pip3 install adafruit-blinka
pip3 install adafruit-circuitpython-bh1750
python3 <<EOF
import time
import board
import adafruit_bh1750

i2c = board.I2C()
 
sensor = adafruit_bh1750.BH1750(i2c)
 
while True:
    print("%.2f Lux" % sensor.lux)
    time.sleep(1)
EOF



apt install ddcutil
ddcutil detect
ddcutil capabilities
ddcutil getcvp
ddcutil setvcp
ddcutil vcpinfo
ddcutil dumpvcp


package ui

import (
	bh1750 "github.com/d2r2/go-bh1750"
	i2c "github.com/d2r2/go-i2c"
	logger "github.com/d2r2/go-logger"
	"time"
)

var lg = logger.NewPackageLogger("main",
	logger.ErrorLevel,
)

func main() {
	defer logger.FinalizeLogger()

	logger.ChangePackageLogLevel("i2c", logger.ErrorLevel)
	logger.ChangePackageLogLevel("bh1750", logger.ErrorLevel)

	// Create new connection to I2C to bh1750
	i2c, err := i2c.NewI2C(0x23, 1)
	if err != nil {
		lg.Fatal(err)
	}

	// Free I2C connection on exit
	defer i2c.Close()

	// Setup sensor
	sensor := bh1750.NewBH1750()

	// Reset sensor prior to use
	err = sensor.Reset(i2c)
	if err != nil {
		lg.Fatal(err)
	}

	// Read sensor value over time
	for {
		resolution := bh1750.HighResolution
		lux, err := sensor.MeasureAmbientLight(i2c, resolution)
		if err != nil {
			lg.Fatal(err)
		}

		println("Illuminance:", lux, "lx")

		time.Sleep(500 * time.Millisecond)
	}
}

The Raspberry Pi 4 doesn't have proper HDMI 'stuff' via i2c or similari which ```dccutil``` needs to manage things like brightness of a display. When this support is available, use the below ideas to get automatic HDMI brightness based on a LUX sensor working. * https://www.adafruit.com/product/4463 * https://www.adafruit.com/product/4681 * https://learn.adafruit.com/adafruit-bh1750-ambient-light-sensor/python-circuitpython * https://www.raspberrypi.org/forums/viewtopic.php?t=145894 * http://www.ddcutil.com/building/ * http://www.ddcutil.com/raspberry/ * https://github.com/raspberrypi/linux/issues/3152 * https://git.kemonine.info/PiFrame/piframe-go/src/branch/master/cmd/ui/ui.go (lux sensor in go) ``` tweak /boot/config.txt to have dtoverlay=vc4-kms-v3d instead of fkms apt install i2c-tools cat > /etc/modules-load.d/i2c.conf <<EOF i2c-dev EOF modprobe i2c-dev lsmod | grep i2c ls /dev/i2c* i2cdetect -r -y 11 i2cdetect 1 pip3 install RPI.GPIO pip3 install adafruit-blinka pip3 install adafruit-circuitpython-bh1750 python3 <<EOF import time import board import adafruit_bh1750 i2c = board.I2C() sensor = adafruit_bh1750.BH1750(i2c) while True: print("%.2f Lux" % sensor.lux) time.sleep(1) EOF apt install ddcutil ddcutil detect ddcutil capabilities ddcutil getcvp ddcutil setvcp ddcutil vcpinfo ddcutil dumpvcp ``` ``` package ui import ( bh1750 "github.com/d2r2/go-bh1750" i2c "github.com/d2r2/go-i2c" logger "github.com/d2r2/go-logger" "time" ) var lg = logger.NewPackageLogger("main", logger.ErrorLevel, ) func main() { defer logger.FinalizeLogger() logger.ChangePackageLogLevel("i2c", logger.ErrorLevel) logger.ChangePackageLogLevel("bh1750", logger.ErrorLevel) // Create new connection to I2C to bh1750 i2c, err := i2c.NewI2C(0x23, 1) if err != nil { lg.Fatal(err) } // Free I2C connection on exit defer i2c.Close() // Setup sensor sensor := bh1750.NewBH1750() // Reset sensor prior to use err = sensor.Reset(i2c) if err != nil { lg.Fatal(err) } // Read sensor value over time for { resolution := bh1750.HighResolution lux, err := sensor.MeasureAmbientLight(i2c, resolution) if err != nil { lg.Fatal(err) } println("Illuminance:", lux, "lx") time.Sleep(500 * time.Millisecond) } } ```
kemonine added the
enhancement
help wanted
labels 1 year ago
kemonine changed title from future : ambient light control to Ambient light control 1 year ago
kemonine added this to the Future milestone 1 year ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.