CP Bluefruit with synesthesia?

Play with it! Please tell us which board you're using.
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
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

CP Bluefruit with synesthesia?

Post by pneumatic »

I've got a Circuit Playground Bluefruit (the older one), and I'm using Adafruit CircuitPython 7.3.3 on 2022-08-29

I've got some code that wants to do one thing if there is bright light, but a different thing if there is a loud sound.
However, bright lights register as high sound levels for some reason:

take this code as an example:

Code: Select all

import time

from adafruit_circuitplayground.bluefruit import cpb

while True:
    if cpb.loud_sound():
        print("Sound level {}".format(cpb.sound_level))

    if cpb.light > 100:
        print("Light level {}".format(cpb.light))

    time.sleep(0.5)
 
If I shine a bright light at it while there is silence this is the output I get:

Code: Select all

code.py output:
Sound level 231.024
Sound level 177.795
Sound level 478.971
Sound level 1096.87
Sound level 1575.9
Sound level 1826.04
Sound level 2235.47
Sound level 10361.6
Sound level 10794.2
Sound level 10250.9
Sound level 9472.67
Light level 298
Sound level 9128.71
Sound level 8716.05
Sound level 8697.88
Light level 302
Sound level 8416.74
Sound level 8695.8
Light level 50
Sound level 8979.71
Sound level 8582.29
Sound level 7360.84
Light level 224
Sound level 7396.22
I've verified that the light level does in fact react as well, but why are lights being registered as sounds?

Thanks,
Mitch

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: CP Bluefruit with synesthesia?

Post by pneumatic »

Just to rule out that my circruit could somehow be the cause, I removed all external connections to the board (other than USB), and it still behaves the same.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: CP Bluefruit with synesthesia?

Post by adafruit_support_mike »

I have no idea why the board would behave that way.

Just to verify, could you post a version that prints both light and sound levels, under conditions where the light switches on and off? Maybe seeing the covariance will suggest something.

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: CP Bluefruit with synesthesia?

Post by pneumatic »

This is really interesting... I took out the call of cpb.loud_sound() and it went away. Code now looks like:

Code: Select all

import time

from adafruit_circuitplayground.bluefruit import cpb

while True:
    print("Sound {}    Light {}".format(cpb.sound_level, cpb.light))
    time.sleep(1)
And now it behaves as expected:

Code: Select all

code.py output:
Sound 12.9617    Light 22
Sound 19.4857    Light 24
Sound 18.1896    Light 23
Sound 17.7992    Light 22
Sound 27.5308    Light 9
Sound 23.7574    Light 11
Sound 16.6557    Light 23
Sound 16.5486    Light 25
Sound 17.9611    Light 29
Sound 16.5477    Light 34
Sound 9.48288    Light 132
Sound 10.295    Light 139
Sound 16.4029    Light 190
Sound 13.4863    Light 165
Sound 17.6727    Light 207
Sound 16.7893    Light 178
Sound 10.2204    Light 192
Sound 20.6528    Light 114
Sound 18.123    Light 73
Sound 20.651    Light 101
Sound 16.3629    Light 119
I added back the call to cpb.loud_sounds(), and that didn't break it again:

Code: Select all

while True:
    if cpb.loud_sound(sound_threshold=300):
        print("Loud!")
    print("Sound {}    Light {}".format(cpb.sound_level, cpb.light))
    time.sleep(1)
So I tried the code I originally posted again and now it is behaving properly as well. Must be sunspots.

Thanks for responding. If I can make it reliably break again, I'll follow up.

-- Mitch

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: CP Bluefruit with synesthesia?

Post by adafruit_support_mike »

Ah.. one of those.

At a guess, the python interpreter got confused for a bit. There may have been a glitch in an address for one of the routines or a pair of buffers.

Glad to hear it's behaving again!

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

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”