ValueError: NEOPIXEL in Use

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

ValueError: NEOPIXEL in Use

Post by teltech84 »

Hello,

I've got a strange error pop up when I run the following code but I don't know why. can anyone help me out?
I want the code to download a json file, loop through the number of items in the json file and iterate the quote and author location.

It's giving me an error:
Traceback (most recent call last):
File "code.py", line 45, in <module>
File "code.py", line 30, in main
File "adafruit_pyportal/__init__.py", line 152, in __init__
File "adafruit_pyportal/network.py", line 92, in __init__
File "neopixel.py", line 149, in __init__
ValueError: NEOPIXEL in use

Sample JSON file is:
[{"text":"testtext1","author":"author1"},
{"text":"testtext2","author":"author2"}]

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal

textrow = 0
authorrow = 0

def main(textrow, authorrow):
    

    # Set up where we'll be fetching data from
    DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
    QUOTE_LOCATION = [textrow, 'text']
    AUTHOR_LOCATION = [authorrow, 'author']

    # the current working directory (where this file is)
    cwd = ("/"+__file__).rsplit('/', 1)[0]

    pyportal = PyPortal(url=DATA_SOURCE,
                        json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                        status_neopixel=board.NEOPIXEL,
                        default_bg=cwd+"/quote_background.bmp",
                        text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                        text_position=((20, 120),  # quote location
                                    (5, 210)), # author location
                        text_color=(0xFFFFFF,  # quote text color
                                    0x8080FF), # author text color
                        text_wrap=(35, # characters to wrap for quote
                                0), # no wrap for author
                        text_maxlen=(180, 30), # max text size for quote & author
                    )

    # speed up projects with lots of text by preloading the font!
    pyportal.preload_font()
    value = pyportal.fetch()
    textrow += 1
    authorrow += 1
    print("Response is", value)
    
i = 0

while i < 10:
    textrow = 0
    authorrow = 0
    main(textrow, authorrow)
    i +=1
    
#except (ValueError, RuntimeError) as e:
#     print("Some error occured, retrying! -", e)

time.sleep(5)

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: ValueError: NEOPIXEL in Use

Post by tannewt »

PyPortal is being created multiple times because the main() call is in the while loop.

You'll want to do it once before your loop and then change the text in the loop.

User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

Re: ValueError: NEOPIXEL in Use

Post by teltech84 »

How do I change the text in the loop? what is the function that I need to call?

User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

Re: ValueError: NEOPIXEL in Use

Post by teltech84 »

I got it to work.

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal
import json



i = 0
 
#Set up where we'll be fetching data from
DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
QUOTE_LOCATION = [i , 'entryContent']
AUTHOR_LOCATION = [i , 'entryDate']

#the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
var = (QUOTE_LOCATION, AUTHOR_LOCATION)
pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                    #status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/quote_background.bmp",
                    text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                    text_position=((20, 120),  # quote location
                                (5, 210)), # author location
                    text_color=(0xFFFFFF,  # quote text color
                                0x8080FF), # author text color
                    text_wrap=(35, # characters to wrap for quote
                            0), # no wrap for author
                    text_maxlen=(180, 30), # max text size for quote & author
                )
pyportal.preload_font()


def main(i):
    
    pyportal.json_path=([ i,
                        'entryContent'],
                        [ i,
                        'entryDate'],
                        )
    # speed up projects with lots of text by preloading the font!
    value = pyportal.fetch()
    print("Response is", value)


while True:
    try:
        main(i)
        i = i + 1
        time.sleep(5)
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
    time.sleep(5)

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

Return to “Adafruit CircuitPython”