-1

I'm trying to read a signal coming from an Arduino through a wire attached to pin 24 of the Pi. The problem is the Pi reads high all the time.

I tried to do a pull up using GPIO.setup(24,GPIO.IN, pull_up_down = GPIO.PUD_DOWN). After that it stopped reading high, but it froze in the low state. It is also not getting to the if statement I'm testing it for. I'm not sure what to do; how do I fix this?

7
  • You're talking about your code which you didn't post. Where exactly is the if statement? Sep 7 '20 at 10:49
  • Thank you for the quick response. I'm using GPIO 17 for something else. Does it matter to use a different one?
    – user124819
    Sep 7 '20 at 10:52
  • Dmitry Grigoryev, sorry for not elaborating more. it is a long code using different classes. The 'if' statement is in the PI testing to see if the signal is high to do something.
    – user124819
    Sep 7 '20 at 10:54
  • Is this a 3.3 volt arduino, or a 5v? And normally you'd have to connect the grounds to protect against a floating ground. a 5v connection to a pi may kill the pi.
    – NomadMaker
    Sep 7 '20 at 11:39
  • the output is coming from pin 7 in arduino. what I'm doing is just testing some code in arduino, if it passes the test, I'm sending a signal to PI using pin 7 as output. Then in pi using pin 27 as input
    – user124819
    Sep 7 '20 at 11:45
2

Try connecting the wire to another Pin like Pin 11. Then run one of these:

gpiozero:

from gpiozero import Button
from time import sleep

button = Button(17) # The 11th Pin is GPIO 17

while True:
    if button.is_pressed:
        # Your code here
        
    sleep(0.2)

RPi.GPIO:

import RPi.GPIO as GPIO
from time import sleep

butPin = 17

GPIO.setmode(GPIO.BCM)
GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

try:
    while True:
        if (GPIO.input(butPin) == False): 
            # Your code here

        sleep(0.2)
except KeyboardInterrupt:
    GPIO.cleanup()

Make sure the Arduino outputs 3.3V for the output to be True and 0V for the output to be False. If it still doesn't work the problem is probably with the Arduino.

Not the answer you're looking for? Browse other questions tagged or ask your own question.