loboris / MicroPython_ESP32_psRAM_LoBo

MicroPython for ESP32 with psRAM support
Other
825 stars 342 forks source link

how to configure APA106 LED #231

Open capedra opened 5 years ago

capedra commented 5 years ago

Hello, At the same time that this is an issue, it's also a tutorial for making the APA106 LED work with this release of MicroPython:

from machine import Pin, Neopixel
apa106_pin = Pin(22)
apa106 = Neopixel(pin=apa106_pin, pixels=1, type=Neopixel.TYPE_RGB)
T1H = 1360; T1L=350; T0H=350; T0L=1360; Treset=50000 #APA106 timings
timings = ((T1H,T1L), (T0H, T0L), Treset)
apa106.timings(timings)
apa106.color_order('RGB')
apa106.set(1, Neopixel.BLUE) #test blue color

Now, if you're using static colors, you can notice this: GRAY=YELLOW; GREEN=OFF; PURPLE=RED; BLACK=OFF; MAROON=RED; TEAL=OFF; GRAY=RED; OLIVE=RED; SILVER=MAGENTA; NAVY=GREEN;

MAGENTA=OK; RED=OK; BLUE=OK; LIME=OK; CYAN=SOSO

Maybe this issue that happens with these colors is because of this timings issue which can be shown below:

>>> timings
((1360, 350), (350, 1360), 50000)
>>> apa106.timings(timings)
((350, 1350), (1350, 350), 50000)
>>> apa106
Neopixel(Pin=22, Pixels: 1, bit/pix=24, RMTChannel=7, PixBufLen=4, Color order: 'RGB'
         Timings (ns): T1H=350, T1L=1350, T0H=1350, T0L=350, Treset=50000
)

It basically shows that T1L != 1360 and also T0H != 1360, because the library doesn't let me assign these values correctly.

loboris commented 5 years ago

The 10 ns difference is well within the +- 150 ns tolerance.

If 5V is used for powering APA106, a level shifter may be required on data pin.

capedra commented 5 years ago

The 10 ns difference is well within the +- 150 ns tolerance.

If 5V is used for powering APA106, a level shifter may be required on data pin.

Any data pin works at 3V3 on ESP32. I'm currently using 5V from ESP32 to power up the APA106. I will test with a diode later. But what level shifter are you talking about? Maybe this one: https://www.adafruit.com/product/1787 ?

capedra commented 5 years ago

Adafruit's Neopixel library works perfectly fine on Arduino framework.

loboris commented 5 years ago

Any data pin works at 3V3 on ESP32. I'm currently using 5V from ESP32 to power up the APA106. I will test with a diode later. But what level shifter are you talking about? Maybe this one: https://www.adafruit.com/product/1787 ?

As ESP32 High pin state is 3.3 V it may be insuficient to be detected as high level on APA106 if it is powered from 5V (minimal high level is usually specified as 0.7 * Vdd, for Vdd=5V it is 3.5V). In this case any level shifting circuit (3.3V -> 5V) can be used between ESP32 pin and APA106 data pin. You may try to power the APA106 from 3.3V. Most WS2812B works well with 3.3V power (but its power supply range is specified as 3.5 - 5.3V).

Adafruit's Neopixel library works perfectly fine on Arduino framework.

I'm not shure how is it relevant for the issue.

capedra commented 5 years ago

@loboris The LED turns on with 3V3 but the colors are still wrong. GREEN, for example, should be 65280 but it shows this:

>>> Neopixel.GREEN
32768
loboris commented 5 years ago

This is the value of the Neopixel.GREEN constant, Neopixel.LIME is defined as 65280. You can see the values of all defined colors here. You can give the color as a number, you don't need to use the defined constants only. Color value is defined as (red_value * 65536) + (green_value * 256) + blue_value, or as hexadecimal value: 0xRRGGBB.