1

Why we need to mention the pin is for input or output via pinMode. Can I simply use digitalRead or digitalWrite without setup the pinMode in before? In other words, if I set a pin as the output, can I read it after writing to make sure digitalWrite properly?

2

All pins are input by default, so if you're just reading it, you probably won't need to set the mode. That said, you really should explicitly set the mode as you can't guarantee what state it might currently be in.

digitalRead() should work regardless of whether the pin is in input or output, as the GPLEVn register is independent.

0

I'm quoting 'joan' from this page:

https://www.raspberrypi.org/forums/viewtopic.php?f=72&t=118402

"You can't do both. The latest call is the one in effect. You can read the level of a gpio regardless of its mode. Presumably the gpio edge detect interrupt hardware works regardless of the mode as well."

To what depth your applications needs are, this page might help you more: https://www.raspberrypi.org/forums/viewtopic.php?t=38753

and definitely this: https://sourceforge.net/projects/raspberry-gpio-python/

Also as noted pin declarations are local to each python script.

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.