0

`clue.color` causes future reads of `clue.proximity` to lag
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

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

by evstar on Fri Jun 18, 2021 12:38 am

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 | TOGGLE FULL SIZE
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()

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

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

by dastels on Fri Jun 18, 2021 10:58 am

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_CircuitPython_APDS9960/issues/30.

Dave

dastels
 
Posts: 7469
Joined: Tue Oct 20, 2015 3:22 pm

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

by evstar on Fri Jun 18, 2021 11:13 am

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

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

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

by evstar on Fri Jun 18, 2021 4:02 pm

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 | TOGGLE FULL SIZE
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

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

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

by dastels on Fri Jun 18, 2021 7:54 pm

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

dastels
 
Posts: 7469
Joined: Tue Oct 20, 2015 3:22 pm

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

by evstar on Fri Jun 18, 2021 8:22 pm

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 | TOGGLE FULL SIZE
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()

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

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

by dastels on Fri Jun 18, 2021 9:18 pm

Huh. I'm glad, yet puzzled.

dastels
 
Posts: 7469
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.