using an NPN trans w/ NeoPixel library, how to filp the logic on data pin?

I just received a strip of 60 NeoPixels for a project and I have connected it to an ESP32 (3.3v microcontroller) using a NPN trans for level shifting up to 5v.

But because of the transistor the signal is inverted, so the NeoPixels are not responding.

I didn't see mention of options to invert the logic in NeoPixel library.

Can NeoPixel library be set to invert the logic somehow?

If not then are there any "purely software" approaches that could flip the data pin logic?

I am not capable of modifying the transistor circuit, this is a custom PCB.


P.S. The custom PCB I am using was also used with a RaspberryPi and NeoPixels. Maybe it was the RasbperryPi's GPIO library that allowed me to invert logic, but I know this PCB works.

Can NeoPixel library be set to invert the logic somehow?

of course it can, though i think you’ll have to do that manually within the library yourself, would be a bit of work. Does the ESP32 use the ESP8266 part ? if so looking at the extern ‘C’

  for(t = time0;; t = time0) {
    if(pix & mask) t = time1;                             // Bit high duration
    while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
    GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask);       // Set high
    startTime = c;                                        // Save start time
    while(((c = _getCycleCount()) - startTime) < t);      // Wait high duration
    GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);       // Set low
    if(!(mask >>= 1)) {                                   // Next bit/byte
      if(p >= end) break;
      pix  = *p++;
      mask = 0x80;
    }
  }

the solution seems obvious.
Otherwise just look up the code that is responsible for the sending of the data.
Copy the library with a new name, change the include references & Header and make your own modified version. But Built-in it isn’t. Maybe there is other libraries that do have it built-in.

(deleted)

I don't have an ESP32 to test on, but this looks promising.

https://esp32.com/viewtopic.php?t=9041#p37797

I think the best and easiest way to do that is to invert the GPIO output signal in esp32.

Refer to func_out_sel_cfg register in components/soc/esp32/include/soc/gpio_struct.h. For example, if you want to invert GPIO18, you can use the following code to do that, after initializing light driver.

GPIO.func_out_sel_cfg[18].inv_sel = 1;  // invert the output of GPIO matrix.

oqibidipo: I don't have an ESP32 to test on, but this looks promising.

https://esp32.com/viewtopic.php?t=9041#p37797

Cool! But how do I use it?

GPIO.func_out_sel_cfg[18].inv_sel = 1;  // invert the output of GPIO matrix.

When I add the line I get "GPIO does not name a type"

Put it in setup(), not in global scope.

oqibidipo: Put it in setup(), not in global scope.

It worked!

Thanks!

But again - as spycatcher said - Why use a transistor at all...

You're only driving the [u]first[/u] neopixel - they daisy-chain - so the cpu will only 'see' the first chip.

The issue you'll find soon is the power supply to drive 60 RGB neopipxels... up to 3.6A on the LED supply rails if all the RGB are full-on !

lastchancename: But again - as spycatcher said - Why use a transistor at all...

You're only driving the [u]first[/u] neopixel - they daisy-chain - so the cpu will only 'see' the first chip.

The issue you'll find soon is the power supply to drive 60 RGB neopipxels... up to 3.6A on the LED supply rails if all the RGB are full-on !

I currently use a 5v 5amp power supply, and with all 60 RGBW pixels at 100% I see the supply voltage is still 5.0vdc.

When I attach the data pin direct to the 3.3v logic pin, I see flickering on random neopixels.

I was told they will do that if 3.3v logic is used. I assumed (was told) that a level shifted is required.

On my last project (the raspberry pi) it did the exact same thing (flickering). Then when I used a single BJT level shifter, the problem went away.

It would be nice if neopixels were 3.3v compatible. But I think that only works if the supply voltage is lowered..?

I currently use a 5v 5amp power supply, and with all 60 RGBW pixels at 100% I see the supply voltage is still 5.0vdc.

Yes, but how many amps is it drawing?

There is no such thing as a "NeoPixel" strip, by the way. "NeoPixel" was a term coined by AdaFruit, I think, as a generic term for many different types of addressable strips, or at least that is the way the term is used today.

Your RGBW strip could require up to 80mA per led, so 60 of them could draw 4800mA, which is very close to the capacity of your PSU. Ideally you want to keep below ~80% of your psu's capacity.

lastchancename: You're only driving the [u]first[/u] neopixel - they daisy-chain - so the cpu will only 'see' the first chip.

The CPU does not see anything ! the first chip responds to the first 24-bits, removes those from the signal and forwards the rest.

lastchancename: But again - as spycatcher said - Why use a transistor at all...

well many WS281x chips depend on a near 5v logic-high level, with a sharp edge (they are edge triggered) I actually use a TTL non-inverter (or 2 TTL-inverters)

The CPU does not see anything ! the first chip responds to the first 24-bits, removes those from the signal and forwards the rest.

You’re absolutely correct. I was talking about something else altogether. The Arduino can’t see anything! https://en.m.wikipedia.org/wiki/Fan-out

I am sure I do not totally understand your constraints, but I googled

“3.3 5 level shifter non-inverting” no quotes

and saw several plausible single active device circuits that might be fitted in where you now have the transistor.

HTH

a7

megaBlocks: I was told they will do that if 3.3v logic is used. I assumed (was told) that a level shifted is required.

I think that's true. If you power the LEDs with 3.3V, they'll accept 3.3V input logic levels -- and operate with slightly reduced maximum brightness. But with Vcc=5, they may not "work" with 3.3V inputs.

Something like this might have been a better choice for level shifter: http://www.ti.com/product/SN74AHCT1G125. With Vcc = 5.0, the maximum required input HIGH level is only 2V and the output will swing almost the full 5V. It's small, maybe you can "dead bug" one onto your PWB.

PaulRB: There is no such thing as a "NeoPixel" strip, by the way. "NeoPixel" was a term coined by AdaFruit,

"NeoPixel" is Adafruit's brand name for single-wire WS2812B-type devices. The RGBW "NeoPixels" incorporates an extra white LED and are SK6812RGBW-type. BTW, "DotStar" is Adafruit's brand name for two-wire APA102-type devices.

I think that's true. If you power the LEDs with 3.3V, they'll accept 3.3V input logic levels -- and operate with slightly reduced maximum brightness. But with Vcc=5, they may not "work" with 3.3V inputs.

Not just reduced brightness, but probably a different color shade, the blue component will light up considerably less than the red & green.