0

When I set GPIO pin for input and read the value, I get high and low continuously. Doesn't matter which pin I set. I couldn't even light a led yet.

This is happening when I connect 40 pin ribbon connector cable. Everything turns normal when I don't connect it. What is the reason? Is it cable?

Edit: I changed side of the cable and added some pictures. Still same. I also tried with PUD_DOWN. This time it is stable 0 but I have no movement input what so ever.

Second edit: Okay, My breadboard has two seperate part on power and ground lines. As you can see from picture I am trying to get ground and power from other side which is not connected to raspberry pi :) So problem solved thanks everybody.

[![enter image description here][1]][1]

enter image description here

enter image description here

hunterTR
  • 1
  • 3
  • 1
    We will need to see pics of all the connections and the code you are using. However, the first thing I would suspect is that you have the ribbon cable installed backwards. The colored stripe goes at the end of the board closest to the SD card. – Steve Robillard Feb 01 '17 at 19:51
  • 1
    If there's nothing attached to the input and you read it, you're reading a floating pin which has no fixed value. I'm not completely sure that's what's happening, as I can't see your connections. How's everything hooked up? – goobering Feb 01 '17 at 21:24
  • Actually I am trying to get an input from pir sensor. At first I thought I was getting this high and low value from sensor but It turns out If I change it to empty pin it does the same thing with same pattern. I have tried pull down. Yeah it makes the pin stable 0 but this time I don't get any input from pir sensor. I will share pic and code when I go home. – hunterTR Feb 02 '17 at 06:59
  • added some pictures of my pin setup. Changed side of the cable as you said. – hunterTR Feb 02 '17 at 17:23

1 Answers1

2

GPIO inputs are floating (varying between 0 and 1) until a known voltage is applied.

Radio interference on the ribbon cable will generate lots of spurious activity.

You need to set a default voltage on the GPIO. The simplest way is to enable the internal pull-up or pull-down. With a pull-up the GPIO should be stable as 1, with a pull-down the GPIO should be stable as a 0.

You can use the wiringPi gpio utility to set the default pulls (see its documentation).

My pigs utility also lets you set the pulls.

See http://abyz.me.uk/rpi/pigpio/pigs.html#PUD

pigs pud 4 d # set internal pull-down on GPIO4

pigs pud 4 u # set internal pull-up on GPIO4

pigs pud 4 o # switch off internal pulls on GPIO4
joan
  • 71,024
  • 5
  • 73
  • 106
  • Joan doesn't the fact that after removing the ribbon cable it works as expected argue against this as the cause? – Steve Robillard Feb 01 '17 at 20:56
  • @SteveRobillard I suppose so. The ribbon cable acts as an aerial which makes the problem much more visible. Without the cable a GPIO might be stable for hours, with a cable you can get hundreds of level changes a second. – joan Feb 01 '17 at 21:01
  • GPIO inputs are NOT floating; as you well know the default state for all pins has a pull. However connecting an antenna to the high impedance input will often override the pull. – Milliways Feb 01 '17 at 23:02
  • @Milliways The pulls can be switched off by software, the defaults apply at power-up. – joan Feb 01 '17 at 23:24
  • Actually I am trying to get an input from pir sensor. At first I thought I was getting this high and low value from sensor but It turns out If I change it to empty pin it does the same thing with same pattern.

    I have tried pull down. Yeah it makes the pin stable 0 but this time I don't get any input from pir sensor. I will share pic and code when I go home.

    – hunterTR Feb 02 '17 at 06:59
  • @hunterTR I am having the exact same problem. I also have exactly the same arrangement, have you found a solution? Did this answer worked as expected? –  Nov 24 '18 at 19:45
  • @ChristosK. I put it in the main post as second edit. It was pretty stupid but here is the answer :) Second edit: Okay, My breadboard has two seperate part on power and ground lines. As you can see from picture I am trying to get ground and power from other side which is not connected to raspberry pi :) So problem solved thanks everybody. – hunterTR Jan 11 '19 at 20:05