Trinket M0 will not light up more than 85 Neopixels

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dcdanko
 
Posts: 5
Joined: Mon Mar 29, 2021 12:48 am

Trinket M0 will not light up more than 85 Neopixels

Post by dcdanko »

I've been trying to run neopixel strips using the trinket M0 but I haven't been able to get more than 85 pixels to turn on.

I've tried this with both 30 and 60 pixel/meter strips and several different trinket m0s (all purchased within the last two months) all with the same result. I can control the first 85 pixels just fine (different colors brightness levels etc) but cannot control the 86th pixel or beyond.

I believe this issue may be related to this thread viewtopic.php?f=8&t=152524

My code is a lightly modified version of the demo code. Any fix for this?

Code: Select all

# Trinket IO demo
# Welcome to CircuitPython 3.1.1 :)

import board

import adafruit_dotstar as dotstar
import neopixel

# One pixel connected internally!
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)


# NeoPixel strip (of 16 LEDs) connected on D4
NUMPIXELS = 85
neopixels = neopixel.NeoPixel(board.D4, NUMPIXELS, brightness=0.1, auto_write=False)


######################### MAIN LOOP ##############################

while True:
  dot[0] = (255, 0, 255)

  for p in range(NUMPIXELS):
    if p % 3 == 0:
      neopixels[p] = (255, 0, 0)
    if p % 3 == 1:
      neopixels[p] = (0, 255, 0)
    if p % 3 == 2:
      neopixels[p] = (0, 0, 255)

  neopixels[NUMPIXELS - 1] = (255, 255, 255)
  neopixels.show()

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dastels »

How are you powering the NeoPixel strip?

Dave

User avatar
dcdanko
 
Posts: 5
Joined: Mon Mar 29, 2021 12:48 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dcdanko »

Via the Trinket M0 (wired to 3V and gnd). I've tried powering the trinkets with both USB and battery. Same result both ways.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dastels »

You might need an external power source for the pixels. If it's a 5v source, you'll need to use a level shifter on the data signal as well.

I notice that the strip length in the code is set to 85. What happens if that's bigger? Do the first 85 still work as before... or do none work?

Dave

User avatar
dcdanko
 
Posts: 5
Joined: Mon Mar 29, 2021 12:48 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dcdanko »

Not sure the power would be the issue? I can run 85 pixels on white with 100% brightness but I can't run 86 pixels one color on 10% brightness.

If I make the number of pixels bigger than 85 the program does nothing at all. In other words it's not as if the first 85 work as I expect and it just stops at 86, nothing works at all.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dastels »

You might be hitting the memory limit of the Trinket. Do you have a board with more ram that you can try going beyond 85 pixels?

Dave

User avatar
pkclsoft
 
Posts: 12
Joined: Thu May 06, 2021 6:36 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by pkclsoft »

It sounds like you might indeed be running out of memory. It compiles OK with 86? Each pixel takes some space. When you compile it should tell you how much memory you're using and will warn you if it's more than will fit.

I found that after updating my libraries recently, a pixel project for a Gemma V2 that compiled and ran 12 months ago, no longer compiled because it was too big by a few bytes. I had to go through my code and optimise it down so that it would fit again. I'm guessing the new library version was chewing up more space.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dastels »

pkclsoft wrote:When you compile it should tell you how much memory you're using and will warn you if it's more than will fit.
DCDANKO posted CircuitPython code which is even more memory intensive.

Regardless, the memory usage reflects static memory use whereas the NeoPixel buffer is allocated dynamically. So even if everything compiles, links, and uploads ok it can still fail to allocate the buffer. With the C++ NeoPixel library that causes it to not use any pixels.

Dave

User avatar
dcdanko
 
Posts: 5
Joined: Mon Mar 29, 2021 12:48 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dcdanko »

Could be a memory issue. I don't have another board to test with, any other way I can check?

Got to say that would be BANNED though as there's no pixel limit mentioned in any of the Trinket M0 product pages and 85 pixels is really not a lot.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dastels »

You can check available memory with:

Code: Select all

>>> import gc
>>> print(gc.mem_free())
2048144
gc is a builtin module so it doesn't take additional memory (or at least not much), however calls to free_mem will, so use BANNED to get the information you want. E.g. print the result before and after creating the Neopixel object.

As for the possibility of 85 being the limit... if it is memory related it will depend on how much code/data there is.

Dave

User avatar
dcdanko
 
Posts: 5
Joined: Mon Mar 29, 2021 12:48 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by dcdanko »

Basic question. How do I print output from this thing? It doesn't look like there's any sort of stdout file I can read from? Am I missing something here?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket M0 will not light up more than 85 Neopixels

Post by adafruit_support_bill »

Got to say that would be BANNED though as there's no pixel limit mentioned in any of the Trinket M0 product pages and 85 pixels is really not a lot.
Programmed via the Arduino IDE, there is sufficient RAM for several thousand of pixels. Python by nature is a lot more RAM intensive, so you will run out much sooner.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”