Page 1 of 1
Dim Neopixel rings more than np = (1,1,1)
Posted: Tue Dec 21, 2021 9:10 am
by damada
Dear forum,
I've built a simple NTP clock with two Neopixel rings using the highlevel neopixel module on an ESP8266 with OLED display (NodeMCU ESP-12F).
The clock is meant as a night clock, but unfortunately, the LED strips are very bright. Even at lowest color brightness, they are still too much of a lamp:
Code: Select all
import machine
import neopixel
np_o = neopixel.NeoPixel(machine.Pin(0), 60) # D3
np_i = neopixel.NeoPixel(machine.Pin(14), 24) # D5
for i in range(np_o.n):
np_o[i] = (1,1,1)
np_o.write()
for i in range(np_i.n):
np_i[i] = (1,1,1)
np_i.write()
Half the brightness would be good, or even a third.
Is it possible to further reduce the brightness by PWM? How would I combine this with the neopixel module?
Thanks in advance
Daniel
Re: Dim Neopixel rings more than np = (1,1,1)
Posted: Fri Dec 24, 2021 1:12 pm
by Roberthh
You could try switch between a (1,1,1) (on) setting and a (0,0,0) (off) setting in a PWM fashion. Short time on, long time off. If that is done sufficiently fast, more then 25 times per second, then there should be no visible flicker.
Re: Dim Neopixel rings more than np = (1,1,1)
Posted: Tue Jan 18, 2022 1:09 pm
by damada
Dear Robert,
sorry for the late reply!
Your approach works, but only up to approx. 20Hz or so. There is considerable flicker, or at least the brightness varies considerably.
Speaking with my wife, she prefers the brighter clock rather than the flickering clock
Re: Dim Neopixel rings more than np = (1,1,1)
Posted: Wed Jan 19, 2022 7:52 am
by damada
Just for completeness, here is what I tried:
Code: Select all
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from machine import Pin
import neopixel
import esp
import utime as time
##*****************************************************************************
##*****************************************************************************
#np_o = neopixel.NeoPixel(Pin(5), 60) # D1 !!! NOK !!!
#np_i = neopixel.NeoPixel(Pin(4), 24) # D2 !!! NOK !!!
#np_i = neopixel.NeoPixel(Pin(2), 24) # D4 !!! startup blink !!!
np_o = neopixel.NeoPixel( Pin(0), 60) # D3
np_i = neopixel.NeoPixel(Pin(14), 24) # D5
for _ in range(np_o.n):
np_o[_] = (0,0,0)
np_o.write()
for _ in range(np_i.n):
np_i[_] = (0,0,0)
np_i.write()
##*****************************************************************************
##*****************************************************************************
'''
https://forum.micropython.org/viewtopic.php?f=16&t=11670
'''
##=============================================================================
def freq_test1():
for freq in (25, 50, 60, 100): # Hz
print("\n>>>>> %i Hz ..." % freq)
period = 1./freq # s
period *= 1000 # ms
for dutyfactor in (1,2,3,4,5):
print("\n >> 1/%i" % dutyfactor)
time_on = period/(dutyfactor+1)
time_off = period/(dutyfactor+1) * dutyfactor
ts_start = time.time()
while time.time() - ts_start < 3:
## 1) single pixel
np_i[0] = (0,0,0)
## 2) all pixels
for i in range(np_i.n):
np_i[i] = (0,0,0)
## 1)+2)
np_i.write()
time.sleep_ms(int(time_off))
## 1) single pixel
np_i[0] = (1,1,1)
## 2) all pixels
for i in range(np_i.n):
np_i[i] = (1,1,1)
## 1)+2)
np_i.write()
time.sleep_ms(int(time_on))
time.sleep_ms(1000)
freq_test1()
##*****************************************************************************
##*****************************************************************************
'''
https://github.com/Achimh3011/micropython/blob/master/esp8266/modules/neopixel.py
https://docs.micropython.org/en/latest/esp8266/quickref.html#neopixel-driver
'''
pin = Pin(14, Pin.OUT)
is800khz = True
bpp = 3
n = 24
buf0 = bytearray(n * bpp)
buf1 = bytearray((1,1,1) * n)
##=============================================================================
def freq_test2():
for freq in (10, 25, 50, 60, 100, 200): # Hz
print("\n>>>>> %i Hz ..." % freq)
period = 1./freq # s
period *= 1000 # ms
for dutyfactor in (1,2,3,4,5):
print("\n >> 1/%i" % dutyfactor)
time_on = period/(dutyfactor+1)
time_off = period/(dutyfactor+1) * dutyfactor
ts_start = time.time()
while time.time() - ts_start < 3:
esp.neopixel_write(pin, buf0, is800khz)
time.sleep_ms(int(time_off))
esp.neopixel_write(pin, buf1, is800khz)
time.sleep_ms(int(time_on))
time.sleep_ms(1000)
freq_test2()
##*****************************************************************************
##*****************************************************************************
print('\n>>>> Ready.')