Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

Need help troubleshooting the Larson Scanner project
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Need help troubleshooting the Larson Scanner project

by bilagaana on Mon Jan 17, 2022 2:26 pm

I have some history of programming but all I know of electronics hardware is how to solder and follow directions. The Larson Scanner project seems very simple and straightforward in its construction but I am not able to get it to function.

I opted to use the Trinket M0 and the CircuitPython code. I have not attempted to use the Arduino version.

As seen in the attached photo, on connecting the assembled strip (minus the battery leads) and editing the original onboard main.py (I/O Demo) routine to 25 pixels, the Neopixels illuminate in a spectrum which cycles each LED through the spectrum. The Dotstar LED on the board also cycles through the spectrum.

Writing over the main,py routine with the Larson Scanner code provided in the tutorial, after editing the numpix value to 25 (the number of LEDs in my strip) and the pixpin value to board.D4 as instructed, produces a static spectrum pattern on the Neopixel strip and the Dotstar blinks apparently randomly in blue. Pressing the Reset button on the board has no effect on the display. (see the second attached screenshot of the edited routine as loaded)

If the USB connection is unplugged and reinserted, the Neopixel strip does not illuminate at all and the Dotstar on the Trinket continues to flash randomly in blue. Pressing the Reset button has no effect. Again viewing the main.py routine on the board shows it apparently correct and unchanged.

The instructions state "When you save the file, the code should start running almost immediately (if not, see notes at the bottom of this page)." However, I find no such notes regarding troubleshooting. Multiple attempts at reloading the routine do not change the above results.

Basically, the routine as provided does not seem to work correctly.

I'd appreciate any suggestions or corrections. Thanks.
Attachments
main routine as loaded 01.jpg
main routine as loaded 01.jpg (829.59 KiB) Viewed 129 times
trinket original main py demo 01.jpg
trinket original main py demo 01.jpg (711.26 KiB) Viewed 129 times

bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Re: Need help troubleshooting the Larson Scanner project

by caitlinsdad on Mon Jan 17, 2022 5:06 pm

In the lines where a color is being asssigned to the pixel strip[pos] = ([255, 48, 0])...
should be the tuplet without the square brackets
strip[pos] = (255, 48, 0)
Removing the square brackets in those lines may fix it.
I think the board dotstar blinks blue when something goes wrong when the program is running so it must be getting confused in trying to figure out what value is [255, 48, 0] equates or points to. I've seen it lit red when the USB "fuse" goes because I have too many neopixels powered up or a short with bad wiring.
I use the Mu editor which has a syntax checker and a serial monitor to show error messages.
Good luck.

caitlinsdad
 
Posts: 619
Joined: Fri Feb 24, 2012 4:23 pm

Re: Need help troubleshooting the Larson Scanner project

by bilagaana on Mon Jan 17, 2022 7:03 pm

THANK YOU!

Your suggested remedy was exactly what was needed: Removing the square brackets in lines 16-20 immediately resolved the problem.

The one remaining anomaly is the tail-end Neopixel on the far right which blinks when the animation reverses direction. I'll attach a screen grab of the frame in question, below,

I don't know Python. This is strictly monkey-see/do for me. Any thoughts as to which line in the routine is responsible and how to correct that?

I really do appreciate the help.

For the benefit of anyone else attempting this project, below is the corrected code:
Code: Select all | TOGGLE FULL SIZE
import time

import board
import neopixel

numpix = 25  # Number of NeoPixels
pixpin = board.D4  # NeoPixels pin. For Gemma M0 = D1, Trinket M0 = D4
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False)
pos = 0  # position
direction = 1  # direction of "eye"

while True:
    strip[pos - 2] = (16, 0, 0)  # Dark red
    strip[pos - 1] = (128, 0, 0)  # Medium red
    strip[pos] = (255, 48, 0)  # brightest
    strip[pos + 1] = (128, 0, 0)  # Medium red

    if (pos + 2) < numpix:
        # Dark red, do not exceed number of pixels
        strip[pos + 2] = (16, 0, 0)

    strip.write()
    time.sleep(0.03)

    # Rather than being sneaky and erasing just the tail pixel,
    # it's easier to erase it all and draw a new one next time.
    for j in range(-2, 2):
        strip[pos + j] = (0, 0, 0)
        if (pos + 2) < numpix:
            strip[pos + 2] = (0, 0, 0)

    # Bounce off ends of strip
    pos += direction
    if pos < 0:
        pos = 1
        direction = -direction
    elif pos >= (numpix - 1):
        pos = numpix - 2
        direction = -direction
Attachments
larson scanner tailend LED.jpg
larson scanner tailend LED.jpg (57.26 KiB) Viewed 115 times

bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Re: Need help troubleshooting the Larson Scanner project

by caitlinsdad on Mon Jan 17, 2022 11:07 pm

Hmm, tried your code and was getting the end of strip leds lit up too when it changed direction to restart. I'm thinking that's how the neopixels were reacting when you give it a negative index/position number in the code.
change the part below to add the if/else so it takes care of that:
Code: Select all | TOGGLE FULL SIZE
    while True:
        if pos <= 2:
            strip[pos] = (255, 48, 0)  # brightest
            strip[pos + 1] = (128, 0, 0)  # Medium red
        else:
            strip[pos - 2] = (16, 0, 0)  # Dark red
            strip[pos - 1] = (128, 0, 0)  # Medium red
            strip[pos] = (255, 48, 0)  # brightest
            strip[pos + 1] = (128, 0, 0)  # Medium red


The += method of iteration and looping is so "python/C" coding so loops are handled a little differently and you have to be aware of your neopixel position counters - use a number beyond its defined number of pixels(0 through numberofpixels-1) - sometimes the code breaks, use a negative number -??? Fun.

caitlinsdad
 
Posts: 619
Joined: Fri Feb 24, 2012 4:23 pm

Re: Need help troubleshooting the Larson Scanner project

by bilagaana on Tue Jan 18, 2022 3:12 pm

I really appreciate your taking the time to debug this code. Not for the first time, it occurs to me Adafruit tutorials would benefit from beta-testing before publication. It would save their customers much frustration. I'm using this routine as a learning experience, trying to parse the syntax and commands one line at a time and maybe get a feel for Python. It's been 35 years since I did any coding and the world has moved on, so it's a challenge.

One final (I hope) question: Which block of code in the original routine is the preceding "while True:" block (above) meant to replace? Or am I misunderstanding and this is an addition? I've tried and failed a couple times to place it correctly. It would be really helpful if you could post the entire routine as corrected.

Once again: Thanks for your efforts.

bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Re: Need help troubleshooting the Larson Scanner project

by caitlinsdad on Tue Jan 18, 2022 4:46 pm

My snippet will replace this part
Code: Select all | TOGGLE FULL SIZE
while True:
     strip[pos - 2] = (16, 0, 0) # Dark red
     strip[pos - 1] = (128, 0, 0) # Medium red
     strip[pos] = (255, 48, 0) # brightest
     strip[pos + 1] = (128, 0, 0) # Medium red


It puts in a condition to check where the position counter is at and the code takes care of not using a negative number as the neopixel index value.
The animation effect is done by "coloring in" a block of 4 adjacent neopixels and moving it along the strip. If we are looping and the pointer to the middle of the lit segment is at zero or first physical start neopixel, the original code will just "color in" the imaginary pixels that is part of that block( pos - 1 and pos - 2 give negative position values when pos is 0 ).

Remember to format code for python - indents, etc...

caitlinsdad
 
Posts: 619
Joined: Fri Feb 24, 2012 4:23 pm

Re: Need help troubleshooting the Larson Scanner project

by bilagaana on Wed Jan 19, 2022 1:34 pm

Excellent! It works exactly as intended.

The only other edit I made was to the color value in Line 19, changing "strip[pos] = (255, 48, 0) # brightest" to "strip[pos] = (255, 0, 0) # brightest".

The original line of code generated an almost white central pixel. Replacing the value 48 with a 0 gives a more appropriate red pixel.

Now to return to the tutorial and assemble the shades.

With your permission, I will forward your corrections to Adafruit and see if they will update the tutorial.

Thanks, again. It's been a learning experience for me.

bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Re: Need help troubleshooting the Larson Scanner project

by bilagaana on Wed Jan 19, 2022 7:36 pm

After much back and forth with Adafruit Tech support, it turns out the root of the problem with the initial, unmodified routine not running was due to the version of CircuitPython that was shipped with the board. I ordered and received this Trinket M0 within the last two weeks. However, the iteration onboard was 3.1.1, while the current version for which the tutorial code was written is 7.1.1.

What was needed was to download and install the newest bootloader and CircuitPython packages, and copy over the specific library modules called by the routine.

Once all that was sorted out, the routine does run. Though, the issue with the tail-end pixel flashing still occurs and caitlinsdad's fix (above) still applies.

Anyone facing the same problems can follow the links found in the thread at: viewtopic.php?f=8&t=187414&p=907577#p907577

bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Re: Need help troubleshooting the Larson Scanner project

by caitlinsdad on Thu Jan 20, 2022 12:19 am

Probable cause of the white pixel flash, if you changed the color for Brightest, note that it appears in two places, once in the if and second in the else part and that has to be changed also. Staring at code for a long time makes it easy to miss. Good times.

I think I am still running Circuitpython 5 or 6. It changes so fast, I try to keep my boards "stable" and if working, still working. Updating boards and libraries is such a chore. I do hear ya with your frustration at being new to the game. Been there.

caitlinsdad
 
Posts: 619
Joined: Fri Feb 24, 2012 4:23 pm

Re: Need help troubleshooting the Larson Scanner project

by bilagaana on Thu Jan 20, 2022 1:15 pm

Yup, that was too obvious for me to see. Changing the first instance of # brightest resolved the remaining white flash.

The cumulative end result, in working CircuitPython 7.1.1 code with the proper lib modules, is the following:

Code: Select all | TOGGLE FULL SIZE

import time

import board
import neopixel

numpix = 25  # Number of NeoPixels. CHANGE THIS VALUE TO THE NUMBER OF LEDS IN YOUR STRIP
pixpin = board.D4  # NeoPixels pin. For Gemma M0 = D1, Trinket M0 = D4
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False)
pos = 0  # position
direction = 1  # direction of "eye"

while True:
    if pos <= 2:
        strip[pos] = (255, 0, 0)  # brightest
        strip[pos + 1] = (128, 0, 0)  # Medium red
    else:
        strip[pos - 2] = (16, 0, 0)  # Dark red
        strip[pos - 1] = (128, 0, 0)  # Medium red
        strip[pos] = (255, 0, 0)  # brightest
        strip[pos + 1] = (128, 0, 0)  # Medium red

    if (pos + 2) < numpix:
        # Dark red, do not exceed number of pixels
        strip[pos + 2] = [16, 0, 0]

    strip.write()
    time.sleep(0.03)

    # Rather than being sneaky and erasing just the tail pixel,
    # it's easier to erase it all and draw a new one next time.
    for j in range(-2, 2):
        strip[pos + j] = (0, 0, 0)
        if (pos + 2) < numpix:
            strip[pos + 2] = (0, 0, 0)

    # Bounce off ends of strip
    pos += direction
    if pos < 0:
        pos = 1
        direction = -direction
    elif pos >= (numpix - 1):
        pos = numpix - 2
        direction = -direction


bilagaana
 
Posts: 27
Joined: Sun Dec 10, 2017 2:14 pm

Please be positive and constructive with your questions and comments.