Moris526
Posts: 56
Joined: Wed Oct 21, 2020 2:06 am

Reading pin

Thu Apr 15, 2021 9:27 pm

Hi.

Im using RAspberry to control Adafruits Neotrellis button/led board https://learn.adafruit.com/adafruit-neotrellis


Im trying to read the interupt wire on the neotrellis board with this code:

Code: Select all

import RPi.GPIO as GPIO         
 
GPIO.setmode(GPIO.BCM)         
INPUT_PIN = 4         
GPIO.setup(INPUT_PIN, GPIO.IN)         


while True:
           if (GPIO.input(INPUT_PIN) == True):
                    print('1')
           else:
                    print('0')

But I get a stream of ones from the beginning, and nothing changes when I press a button.

Any idea? Not a programmer, as you can see.

User avatar
neilgl
Posts: 3077
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Reading pin

Thu Apr 15, 2021 10:34 pm

How have you got the neotrellis connected to the pi and how is it powered?

Moris526
Posts: 56
Joined: Wed Oct 21, 2020 2:06 am

Re: Reading pin

Thu Apr 15, 2021 10:47 pm

Pi powered via Usb.

Neotrellis via 5v Power supply

interrup wire connected to GPIO 4 , an also Ground

User avatar
joan
Posts: 15560
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Reading pin

Thu Apr 15, 2021 10:56 pm

The 1-wire bus uses gpio 4. Make sure it's not enabled in /boot/config.txt

User avatar
neilgl
Posts: 3077
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Reading pin

Fri Apr 16, 2021 8:18 am

Yes and to avoid it, change to using GPIO 21 (say) . See https://pinout.xyz/
The adafruit doc says “ The pad labeled INT on the NeoTrellis board will be pulled LOW when an event the user has subscribed to is detected”
So in your code, set the GPIO (21) to have a pull-up. It will then stay at 3.3V (logic 1) until the interrupt occurs and takes it to 0V (logic 0).
Test it by temporarily disconnecting the trellis interrupt and using a wire or button/switch , take gpio21 to ground (0V).

Moris526
Posts: 56
Joined: Wed Oct 21, 2020 2:06 am

Re: Reading pin

Sun Apr 25, 2021 3:00 pm

Does this would set the GPIO (21) to have a pull-up?

Code: Select all

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) 
I can make it work with a button.

I guess is a Neotrellis thing...

User avatar
neilgl
Posts: 3077
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Reading pin

Sun Apr 25, 2021 9:29 pm

It does. And you have GPIO.setmode(GPIO.BCM)

Moris526
Posts: 56
Joined: Wed Oct 21, 2020 2:06 am

Re: Reading pin

Mon Apr 26, 2021 2:28 pm

Thank you

User avatar
Mia1011
Posts: 22
Joined: Sun Apr 11, 2021 9:38 am

Re: Reading pin

Mon Apr 26, 2021 4:41 pm

neilgl wrote:
Fri Apr 16, 2021 8:18 am
Yes and to avoid it, change to using GPIO 21 (say) . See https://pinout.xyz/
The adafruit doc says “ The pad labeled INT on the NeoTrellis board will be pulled LOW when an event the user has subscribed to is detected”
So in your code, set the GPIO (21) to have a pull-up. It will then stay at 3.3V (logic 1) until the interrupt occurs and takes it to 0V (logic 0).
Test it by temporarily disconnecting the trellis interrupt and using a wire or button/switch , take gpio21 to ground (0V).
Thanks for this useful for me

Return to “Beginners”