0

I am currently testing my application on an Arduino, and I experience floating pin issues. My program reads the pin status of input pins, which are configured as

pinMode(5, INPUT);
digitalWrite(5, HIGH);

but still they tend to float sometimes.

Will this be solved when I connect the pin directly to a GPIO pin on a RPI? Specifically when the application running on the RPI is not active yet (thus the GPIO pin will not actively high or low yet).

Both the PI and and Arduino will be powered at the same time, but the application on the Arduino will be active much faster than the application on the RPI.

So my concern is that while the RPI is still booting and loading the app, the Arduino might still 'suffer' from floating pins, which gives undesirable output to the things my Arduino controls.

Or, will the fact that the RPI and Arduino both have power, share the same ground, will result in a stable input on the Arduino?

PS: not an expert on electronics, hence the question. I can't test this yet as I don't have all the hardware of this project.

migrated from electronics.stackexchange.com Aug 20 '18 at 18:20

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

3

You need to enable the internal pull-up resistors which are designed to prevent undefined input states on unconnected inputs.

Change

pinMode(5, INPUT);

to

pinMode(5, INPUT_PULLUP);

For more information on this see Arduino digital pins.

  • 1
    I would add, for OP's sake, that what they are doing used to be the way to configure internal pull up prior to arduino 1.0.1 , but this does not work in newer versions of the SDK which added the INPUT_PULLUP configuration. There are probably many tutorials and example projects still using the old pattern. – crasic Aug 19 '18 at 21:20
  • Thanks. I don't know if I ever knew that. – Transistor Aug 19 '18 at 21:23
  • Thanks for the correct way of doing this. I the meantime I learned that I can also create a pulldown resistor incredibly easy! I connected a 22k resistor to ground and connected the input on my arduino to that resistor. I also connected my RPI output to that resistor. That works perfectly, no floating behavior at all. I will also give your solution a try as it even simpler. So thanks for helping out! – bas Aug 21 '18 at 19:12
  • Good work. Most designs use the internal pull-ups as it saves the additional components. Some micros have the option of a pull-down as well. Thanks for the feedback. – Transistor Aug 21 '18 at 19:14
1

Does a pin (input pin arduino) still float when connected to GPIO on RPI?

Yes. Connecting one floating pin to another floating pin doesn't make either one of them stop floating. If anything, the fact that there's now a long wire connecting them (and picking up RF) will probably make the behavior of the pins even less predictable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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