Neopixel error

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
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Neopixel error

Post by ctmorrison »

My program is relatively simple and runs on a QT PY (ESP32-S2)

I've included the neopixel library with

Code: Select all

import neopixel
The library is version 6.3.3. Note--I've just updated to 6.3.4, but haven't a clue if that will address this issue

In the early part of the program, I instantiate a pixel object with

Code: Select all

pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1)
After a few other unrelated statements I have a the statement

Code: Select all

pixels.fill((0, 0, 0))
The program goes into deep sleep at the end a wakes up in 15 seconds.

After a few hours (many runs of the program), the program fails on the above statement with the error code

Code: Select all

Traceback (most recent call last):
  File "code.py", line 101, in <module>
  File "neopixel.py", line 180, in _transmit
RuntimeError: Input/output error
Any thoughts on how to avoid this would be appreciated.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Neopixel error

Post by mikeysklar »

It looks like you have a straight forward example using only the onboard NeoPixel.

Is it being powered from the USB-C. Is there anything else connected?

Can you post your full code in CODE tags and the details of your CircuitPython release (eg. stable-7.3.2 / library-bundle-2220812).

There is also a bootloader update available (June 23rd). Related links below.

https://circuitpython.org/board/adafruit_qtpy_esp32s2/
https://circuitpython.org/libraries

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Neopixel error

Post by ctmorrison »

Here's the whole program. I am powering it via USB for now, but will be powering it by battery. I also have a VL53L1X ToF sensor connected via STEMMA.

Code: Select all

# Garage Vehicle Space Detection

import alarm
import time
import board
import adafruit_vl53l1x
import neopixel
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn

# This is the latching relay
unoccupied = DigitalInOut(board.A0)
unoccupied.direction = Direction.OUTPUT
occupied = DigitalInOut(board.A1)
occupied.direction = Direction.OUTPUT

# This is the button used to put the device into setup mode
setup = DigitalInOut(board.A2)
setup.direction = Direction.INPUT
setup.pull = Pull.DOWN
# read value with setup.value, knowing it has a pullup
# We'll use this to know the state of the relay
occupiedStatus = DigitalInOut(board.SDA)
occupiedStatus.direction = Direction.INPUT

# This is the potentiometer input
pot = AnalogIn(board.A3)
tripPoint = pot.value * 400 / 65536

# Length of time in seconds to sleep between checks
sleepPeriod = 60
# Length of time in seconds to turn on neopixel to indicate if space is occupied or not
spaceStatusPeriod = 0.5
# Amount of time to energize the relay (in seconds)
energizeTime = 0.25

# We're using the Stemma interface to connect to the sensor
i2c = board.STEMMA_I2C()

# This code works with the VL53L1CX ToF sensor
vl53 = adafruit_vl53l1x.VL53L1X(i2c)

# The onboard neopixel will be used for visual signalling
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1)

# OPTIONAL: can set non-default values
vl53.distance_mode = 2
vl53.timing_budget = 100

print("Garage Space Detection")
print("Version 20220812.1")
print("--------------------")
model_id, module_type, mask_rev = vl53.model_info
print("Model ID: 0x{:0X}".format(model_id))
print("Module Type: 0x{:0X}".format(module_type))
print("Mask Revision: 0x{:0X}".format(mask_rev))
print("Distance Mode: ", end="")
if vl53.distance_mode == 1:
    print("SHORT")
elif vl53.distance_mode == 2:
    print("LONG")
else:
    print("UNKNOWN")
print("Timing Budget: {}".format(vl53.timing_budget))
print("Sleep period: {}".format(sleepPeriod))
print("Trip point: {}".format(tripPoint))
print("Space status period: {}".format(spaceStatusPeriod))
print("--------------------")
vl53.start_ranging()

# Attempt to read a distance
while vl53.data_ready is not True:
    print("not ready")
    time.sleep(0.5)

print("Sensor is ready to read")
distance = vl53.distance

while setup.value is True:
    # the Setup button is being pressed and we need to set the  occupied distance
    # the occupied distance should be just above the floor
    # this assumes the space is EMPTY!
    print("In setup mode")
    tripPoint = pot.value * 400 / 65536
    # check to see if sensed distance is
    print("Floor: {}".format(distance))
    print("tripPoint: {}".format(tripPoint))
    if tripPoint > distance:
        print("tripPoint is beyond floor - adjust to lower value")
        pixels.fill((255, 0, 0))
    else:
        print("tripPoint is above floor - make sure it's close to floor")
        pixels.fill((0, 255, 0))
    time.sleep(1)

print("Setup finished")
pixels.fill((0, 0, 0))

# Read the distance to the nearest object
distance = vl53.distance

# test for no distance read to avoid error
while distance is None:
    distance = vl53.distance
    pixels.fill((0, 0, 255))
    time.sleep(0.1)
pixels.fill((0, 0, 0))

# here's where we check to see if there's a vehicle detected above the threshold
if distance < tripPoint:
    print("Distance: {} cm -> vehicle sensed".format(distance))
    pixels.fill((255, 0, 0))
    if occupiedStatus.value is False:
        # we only energize if we need to -- it was previously unoccupied
        occupied.value = True
        time.sleep(energizeTime)
        occupied.value = False
    time.sleep(spaceStatusPeriod)
else:
    print("Distance: {} cm -> no vehicle sensed".format(distance))
    pixels.fill((0, 255, 0))
    if occupiedStatus.value is True:
        # we only energize if we need to -- it was previously occupied
        unoccupied.value = True
        time.sleep(energizeTime)
        occupied.value = False
    time.sleep(spaceStatusPeriod)
vl53.clear_interrupt()

# Set up the sleep period for the amount of time specified in sleepPeriod
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleepPeriod)
# Exit the program and then deep sleep until the alarm wakes usage
print("Going into Deep Sleep")
alarm.exit_and_deep_sleep_until_alarms(time_alarm)
# Does not get here...program starts at the beginning after sleep

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Neopixel error

Post by ctmorrison »

BTW, the QT PY is running 7.3.2 and the library bundle is 20220812

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Neopixel error

Post by ctmorrison »

I thought I'd give CircuitPython a try--my first foray into CircuitPython. I need this to be a reliable application, so I'll likely just rewrite it in Arduino.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neopixel error

Post by adafruit2 »

thats a wierd one, what if you put a try/except around that line, so you dont error/crash out - just go back into deep sleep.
does it continue to fail after or is it a 'one time thing every 15 minutes'

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Neopixel error

Post by ctmorrison »

I haven't used that construct before. Should I merely use

Code: Select all

except Exception:
or something else? The only reason I asked is that Mu complained about a "bare" except. I changed it to simply

Code: Select all

print("Setup finished")
try:
    pixels.fill((0, 0, 0))
except:
    print("*******************************pixels.fill ((0, 0, 0)) failed")
and I'll see what happens

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neopixel error

Post by adafruit2 »

yep looks good!

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

Return to “Adafruit CircuitPython”