`clue.color` causes future reads of `clue.proximity` to lag

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
evstar
 
Posts: 13
Joined: Wed Jun 02, 2021 9:41 pm

`clue.color` causes future reads of `clue.proximity` to lag

Post by evstar »

The example code demonstrates a clue.proximity reader program. Capacitive touch 0 calls clue.color, after, all subsequent clue.proximity reads cause lag.

Code: Select all

import board
from displayio import Group
from adafruit_clue import clue
from adafruit_display_text import label
from terminalio import FONT

class ColorTest:
    labelText = None

    def __init__(self):
        self.labelText = label.Label(FONT, text="0")
        self.labelText.scale = 5
        self.labelText.x = self.labelText.y = 100
        group = Group()
        group.append(self.labelText)
        board.DISPLAY.show(group)

    def main(self):
        while True:
            if clue.touch_0: colorRead = clue.color
            self.labelText.text = str(clue.proximity)

ColorTest().main()

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

Re: `clue.color` causes future reads of `clue.proximity` to

Post by dastels »

There seems to be some oddness in the APDS9960 class that might explain what you're seeing. I've added an issue related to it: https://github.com/adafruit/Adafruit_Ci ... /issues/30.

Dave

User avatar
evstar
 
Posts: 13
Joined: Wed Jun 02, 2021 9:41 pm

Re: `clue.color` causes future reads of `clue.proximity` to

Post by evstar »

Thanks for the help, Dave! Looking forward to the outcome.

User avatar
evstar
 
Posts: 13
Joined: Wed Jun 02, 2021 9:41 pm

Re: `clue.color` causes future reads of `clue.proximity` to

Post by evstar »

After reading the GitHub repo page you linked, I've learned that for now I can use a combination of the following lines to get around the lag:

Code: Select all

from adafruit_apds9960.apds9960 import APDS9960
apds = APDS9960(board.I2C()) 
apds.enable_color = True
while not apds.color_data_ready: pass
colorRead = self.apds.color_data[3]
apds.enable_color = False

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

Re: `clue.color` causes future reads of `clue.proximity` to

Post by dastels »

Does that work? I saw nothing that indicates it would. Also, you have an extra self in there. The Clue class creates it's own APDS9960 object, and creating a second one might cause problems.

Dave

User avatar
evstar
 
Posts: 13
Joined: Wed Jun 02, 2021 9:41 pm

Re: `clue.color` causes future reads of `clue.proximity` to

Post by evstar »

Yes it does work! And yes my mistake leaving that self. in. I'll be using my own APDS9960 object for now so it should be okay. Here is a full no-lag example:

Code: Select all

import board
from displayio import Group
from adafruit_clue import clue
from adafruit_display_text import label
from terminalio import FONT
from adafruit_apds9960.apds9960 import APDS9960
import time

class ColorTest:
    proximityLabel = None
    lightLabel = None
    apds = APDS9960(board.I2C())

    def __init__(self):
        self.proximityLabel = label.Label(FONT, text="00")
        self.proximityLabel.scale = 5
        self.proximityLabel.x = self.proximityLabel.y = 100
        self.lightLabel = label.Label(FONT, text="00")
        self.lightLabel.scale = 5
        self.lightLabel.x = self.lightLabel.y = 60
        group = Group()
        group.append(self.proximityLabel)
        group.append(self.lightLabel)
        board.DISPLAY.show(group)
        self.apds.enable_proximity = True

    def main(self):
        while True:
            if clue.touch_0:
                self.apds.enable_color = True
                while not self.apds.color_data_ready: pass
                self.lightLabel.text = str(self.apds.color_data[3])
                self.apds.enable_color = False
            self.proximityLabel.text = str(self.apds.proximity)

ColorTest().main()

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

Re: `clue.color` causes future reads of `clue.proximity` to

Post by dastels »

Huh. I'm glad, yet puzzled.

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

Return to “CLUE Board”