Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Neopixels: pixels[0] = (val,val,val)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 2:11 pm

Hi,

I was wondering, when trying to set a Neopixel to show a certain colour, what mode should I expect the GPIO pin to be in?
Currently, using the line of code
Code: Select all | TOGGLE FULL SIZE
pixels[0] = (val,val,val)
places the GPIO pin in question into ALT0 mode ( I think usually for SPI or I2C use) instead of general OUTPUT mode. I only ask because it is currently not working at all.

I would love to be able to see the library code being run for this command, if anyone knows where I might find that?

I appreciate any and all help!
Thanks in advance

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by tannewt on Tue Jul 28, 2020 2:26 pm

What board/microcontroller are you on? The library ultimately calls `neopixel_write`. Here it is for SAMD: https://github.com/adafruit/circuitpyth ... __init__.c

It is in a similar spot for other ports.

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 3:22 pm

Hi @tannewt,

Thanks so much for your quick reply!

Sorry, I should have mentioned, I am using a Rasbperry Pi 3b but I'm running Ubuntu Mate 18.04.4 instead of Raspian.

I know CircuitPython is working as I have run simple tests to toggle the GPIO (in OUTPUT mode) high and low successfully. Maybe it is not successfully producing a PWM signal on the pin.

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by Foamyguy on Tue Jul 28, 2020 3:36 pm

On a Raspberry Pi running under Blinka compatibility layer I think these libraries would be responsible for handling the neopixels:

https://github.com/adafruit/Adafruit_Ci ... Pypixelbuf

https://github.com/adafruit/Adafruit_Ci ... n_NeoPixel

Can you post the full code you are attempting to use? and if possible a picture of your circuit?

Foamyguy
 
Posts: 36
Joined: Mon May 26, 2014 4:24 pm

Re: Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 3:50 pm

Thanks @Foamyguy,

The code in its entirety:
Code: Select all | TOGGLE FULL SIZE
import time
import board
import neopixel

pixels = neopixel.NeoPixel(board.D12, 1)
pixels[0] = 0xfa0000
print("pixels[0] value: " + str(pixels[0]))


The circuit simply connects an external 5V to the NeoPixel and the sn74ahct125n logic level shifter. The Pi's GPIO goes to the logic level shifter and the resulting shifted line goes to the data in of the NeoPixel. All grounds are common. - Sorry, a picture isn't available at the moment but I'm pretty confident the physical circuit is correct (though stranger things have happened)

Thanks for the links!

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by Foamyguy on Tue Jul 28, 2020 4:18 pm

I don't have any experience using the level shifter. But I have successfully driven a few Neopixels directly from the pi without level shifting like this: https://learn.adafruit.com/neopixels-on ... -3006456-6

I used pin D18, but I don't know if that matters. I think I just copied it from the sample code.

Maybe try setting the color as a tuple instead of a hex number. I'm not sure whether it supports both or not. But all of the example code I found is using tuple's like this:

Code: Select all | TOGGLE FULL SIZE
pixels[0] = (255,0,0)

Foamyguy
 
Posts: 36
Joined: Mon May 26, 2014 4:24 pm

Re: Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 4:33 pm

Thanks @Foamyguy, I've tried every combination of with/without level shifter, multiple (compatible) GPIO pins as well as sending the colour as both a tuple and a hex number (as far as I know - both are supported).

Were you using Raspbian? I think my issue stems from using Ubuntu Mate (necessary for my application) - my unfounded suspicions are that the GPIO pin isn't in the correct mode for some reason.

Thanks anyways!

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by MakerMelissa on Tue Jul 28, 2020 4:45 pm

It's possible that the PWM isn't working properly with Ubuntu Mate. It was designed to work on Raspbian (now Raspberry Pi OS) and was updated by a community member to work with Ubuntu somewhat recently, but it hasn't been thoroughly tested. It's possible that you may be the first one to try that combination. Is there a reason for Ubuntu instead of Raspberry Pi OS?

Melissa

MakerMelissa
 
Posts: 154
Joined: Wed Jun 05, 2013 2:10 am

Re: Neopixels: pixels[0] = (val,val,val)

by MakerMelissa on Tue Jul 28, 2020 4:47 pm

Since Ubuntu is necessary for your application, you may want to take a look at trying the neopixel_spi library. See: https://learn.adafruit.com/circuitpytho ... -using-spi

MakerMelissa
 
Posts: 154
Joined: Wed Jun 05, 2013 2:10 am

Re: Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 6:16 pm

Hi @MakerMelissa,

Thanks so much for the info and suggestion! I am using Ubuntu because it makes it a lot easier to use ROS on the Raspberry Pi with our Robots (https://www.trossenrobotics.com/).

I managed to get everything working with the following code, using the rpi_ws281x library (https://github.com/richardghirst/rpi_ws281x) which seems to be OS agnostic:
Code: Select all | TOGGLE FULL SIZE
 
    import time
    from rpi_ws281x import *
   
    strip = Adafruit_NeoPixel(1, 12) # 1 = no. of LEDS, 12 = GPIO pin
    strip.begin()
    strip.setPixelColor(0,  0x0000fa)
    strip.show()

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by MakerMelissa on Tue Jul 28, 2020 6:19 pm

Oh, that's great to know. I'll open an issue regarding this and maybe take a crack at it getting it working in CircuitPython too.

MakerMelissa
 
Posts: 154
Joined: Wed Jun 05, 2013 2:10 am

Re: Neopixels: pixels[0] = (val,val,val)

by LeTo37 on Tue Jul 28, 2020 6:27 pm

Awesome! Thank you

LeTo37
 
Posts: 9
Joined: Thu Jun 14, 2018 11:23 am

Re: Neopixels: pixels[0] = (val,val,val)

by MakerMelissa on Tue Jul 28, 2020 6:29 pm

The issue is at https://github.com/adafruit/Adafruit_Blinka/issues/324 if you want to watch it.

MakerMelissa
 
Posts: 154
Joined: Wed Jun 05, 2013 2:10 am

Please be positive and constructive with your questions and comments.