Enviro pHAT, turn leds off

With a dallas ds18b20 on GPIO17 channel, the Enviro pHAT leds remain illuminated.

How do I set them to off?

My python code runs every two minutes to log reading to mysql.

Thank you.

According to the Function Reference it’s leds.off()
http://docs.pimoroni.com/envirophat/#light

I’ve tried that in a few places, can’t seem to get it right.

import os
import time
import datetime
from envirophat import light, motion, weather, leds
import glob
import MySQLdb
from time import strftime
 
os.system('modprobe w1-gpio')   
os.system('modprobe w1-therm')
temp_sensor_red = '/sys/bus/w1/devices/28-0000000000ff/w1_slave'
temp_sensor_blk = '/sys/bus/w1/devices/28-000000000eff/w1_slave' 

# Variables for MySQL
mydb = MySQLdb.connect("Login details here")
mycursor = mydb.cursor() 


mag_values = motion.magnetometer()
YaxisVal = mag_values[1]
TempVal = weather.temperature()
LuxVal = light.light()

def tempRead_red():
    t = open(temp_sensor_red, 'r')
    lines = t.readlines()
    t.close()
    
    temp_output = lines[1].find('t=')
    if temp_output != -1:
        temp_string = lines[1].strip()[temp_output+2:]
        temp_c = float(temp_string)/1000.0
    return round(temp_c,1)


def tempRead_blk():
    t = open(temp_sensor_blk, 'r')
    lines = t.readlines()
    t.close()    

    temp_output = lines[1].find('t=')
    if temp_output != -1:
        temp_string = lines[1].strip()[temp_output+2:]
        temp_c = float(temp_string)/1000.0
    return round(temp_c,1)
 
while True:
    temp_red = tempRead_red()
    temp_blk = tempRead_blk()
    print "red", temp_red 
    print "blk", temp_blk 

    datetimeWrite = (time.strftime("%Y-%m-%d ") + time.strftime("%H:%M:%S"))
    print datetimeWrite

    mycursor.execute("INSERT INTO readings (cffr, effb, Temp,Yaxis,Lux) VALUES (%s, %s, %s, %s, %s)", [temp_red, temp_blk, TempVal, YaxisVal, LuxVal])
    mydb.commit()

    print(mycursor.rowcount, "record inserted.")
    break

Try

import os
import time
import datetime
from envirophat import light, motion, weather, leds
leds.off()

I’m still getting low lux readings, 11-21ish. They should be zero, Enviro pHAT is in a very dark location.

What model Pi are you using? You may have to put some tape on its power and status LED’s or turn them off.
It may just be that the sensor never actually reads zero, even in dark conditions. I have an Si1145 that behaves this way. It always displays a value above 0 for visible light, even at night, or in a dark room.

It’s a Pi3, the En’Phat is remote by a short distance, primarily to encourage greater accuracy with temperature readings.

The lux level has been written to the db every two minutes for well over a year now. When there’s no light it records 0, with maybe just the occasional 1 or 2, but very mostly 0.

It’s not critical, but there must be a way to kill those pesky En 'Phat leds?!

Old readings, lux consistantly at zero

New readings, with added temperature recordings, and lux showing light presence caused by the two white leds being on.

I think I might know what’s going on. Does that dallas ds18b20 use 1-Wire?
The Enviro Phat LED’s are controlled by GPIO 4, which is also used by 1-Wire.
If 1-wire is enabled thats likely what’s turning the LED’s on and blocking you from turning them off again.

Does that dallas ds18b20 use 1-Wire?
It most certainly does, yes.

I’ll live with it, and hope that one day there will be a Pi with more 1-wire channels available.

Thanks for your help.

GPIO pin conflicts are just something that happens some times when try to connect more than one thing to a Pi’s GPIO header. You could likely cover up those LED’s with something? Gaffer tape, or what we call duct tape. ;)

Ah, gaffer tape/duct tape/duck tape/hostage tape.
I’ll probably just make any lux database queries ignore anything below about 100ish give or take, +/-.

Or…! Use a separate Pi (A Zero W would do), just for the Dallas sensors.
Seems a bit overkill though.