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.')