0

Loose Buttons on Circuit Playground Express?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Loose Buttons on Circuit Playground Express?

by Bevantaylor25 on Wed Mar 24, 2021 4:34 pm

I recently got the circuit playground express advanced pack, and I was learning how to use the onboard buttons to trigger the NeoPixels, but I found that the button "A" (pin D4) does not consistently return the values that I expect; sometimes "buttonA.value" returns "True", even when the button is not depressed, and I can turn my lights on just by brushing the button, I don't have to actually depress it until it clicks like I think I should. It seems that moving it around can sometimes trigger it, so I wonder if the contacts inside the button are just loose? I had the same problem with both circuit playground expresses that came in the kit, but one was worse (more sensitive) than the other. I also had a similar problem with the "B" button, so maybe it's me?

Bevantaylor25
 
Posts: 4
Joined: Wed Mar 24, 2021 4:21 pm

Re: Loose Buttons on Circuit Playground Express?

by adafruit_support_carter on Wed Mar 24, 2021 5:09 pm

It may be software related. What code are you running to print out button values?

adafruit_support_carter
 
Posts: 20679
Joined: Tue Nov 29, 2016 2:45 pm

Re: Loose Buttons on Circuit Playground Express?

by Bevantaylor25 on Wed Mar 24, 2021 5:40 pm

My test code looks like this:
Code: Select all | TOGGLE FULL SIZE
import time
import board
from digitalio import DigitalInOut, Direction, Pull
import neopixel

pixel_pin = board.D8
num_pixels = 10

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False)

buttonA = DigitalInOut(board.D4)
buttonA.direction = Direction.INPUT

buttonB = DigitalInOut(board.D5)
buttonB.direction = Direction.INPUT

switch7 = DigitalInOut(board.D7)
switch7.direction = Direction.INPUT

WHITE = (100,100,100)
OFF = (0,0,0)

def lighton(pixelnumber):
    pixels[pixelnumber] = WHITE
    pixels.show()
   

def lightoff(pixelnumber):
    pixels[pixelnumber] = OFF
    pixels.show()

while True:
   
    if buttonA.value == True:
        lighton(0)
        #print(buttonA.value)
    else:
        lightoff(0)
        #print(buttonA.value)
   
    if buttonB.value == True:
        lighton(9)
        print(buttonB.value)
    else:
        lightoff(9)
        print(buttonB.value)
       
    if switch7.value == True:
        lighton(4)
        #print(switch7.value)
    else:
        lightoff(4)
        #print(switch7.value)
       
    time.sleep(0.1)   


I get a similar effect on both buttons, sometimes it sticks "True", or turns "True" when I touch the board but don't click the button down. I added some code to test the switch too, and it has a similar problem; neither position returns "True" all the time as I would expect, but if I tap on it lightly with my finger the light will flick on and off and it will return "True" erratically. Just to note, I have commented out some of the print statements to isolate each DI on the console, but I ran it with each set of print statements active one at a time.
Last edited by adafruit_support_carter on Wed Mar 24, 2021 5:42 pm, edited 1 time in total.
Reason: add [code] tags

Bevantaylor25
 
Posts: 4
Joined: Wed Mar 24, 2021 4:21 pm

Re: Loose Buttons on Circuit Playground Express?

by adafruit_support_carter on Wed Mar 24, 2021 5:50 pm

Thanks for the code. The general issue here relates to having floating inputs. Some info here:
https://learn.adafruit.com/circuit-play ... ing-inputs

You configure for INPUT, but do not set any pull values:
Code: Select all | TOGGLE FULL SIZE
buttonA = DigitalInOut(board.D4)
buttonA.direction = Direction.INPUT


For the buttons, you'll want to enable pull DOWNs.
For the slide switch, you'll want to enable pull UP.

You could also use the dedicated Circuit Playground library which takes care of all that for you:
https://learn.adafruit.com/circuitpytho ... nd-express

adafruit_support_carter
 
Posts: 20679
Joined: Tue Nov 29, 2016 2:45 pm

Re: Loose Buttons on Circuit Playground Express?

by Bevantaylor25 on Wed Mar 24, 2021 6:06 pm

Ok, that's worked perfectly! Thank you!

Bevantaylor25
 
Posts: 4
Joined: Wed Mar 24, 2021 4:21 pm

Please be positive and constructive with your questions and comments.