0

When I used to program PICs, there was a way to set the pins to input and output, at the same time. Can this be done on the Arduino? I see the pinmode documentation, but nothing about being an IO port.

  • Ok, please explain this better. I think you just forgot the "set the pins to Input AND OUTPUT, at the same time". If so, please explain what you mean by "input and output". You want to set the value and then read the same value? – frarugi87 Jan 11 '16 at 14:26
  • Or do you want to set a group of pins at the same time using a mask? If so, check here: arduino.cc/en/Reference/PortManipulation – BobT Jan 11 '16 at 14:50
  • Are you asking if you can do something like creating a memory interface or the control register of a hardware device where you would both read and write data? – dlu Jan 11 '16 at 17:09
3

No there is no function that lets you set all the pins to either input or output at the same time, but it wouldn't take much to write one.

No, you can't set an Arduino's pin as bidirectional. If you are running out of pins look at IO expanders or multiple Arduinos.

Hope that helps, if not please feel free to clarify what it is you would like to know and we'll try and help.

  • I’m not running out of pins, I’m using a piezo electric wafer as a sensor, but after it senses an impact, I'd like it to then mimic the impact (in sound). Sure, I can use 2 peizo electric wafers to do that, but if there were a way to only use, one, I would be very interested. maybe I can toggle the pin mode. I'll look into that. – j0h Jan 11 '16 at 18:38
  • 1
    Surely you want the pin to be an input, and once you get an impact turn it into an output. – Nick Gammon Jan 12 '16 at 5:31
  • 1
    @j0h like Nick says you can alter the mode of a pin at runtime (i.e. in the loop function). Would that be enough to achieve what you want? Of course it will meant there is a period where you won't be able to receive new signals. Could you use two pins and run the input through a transistor that is normally closed unless the output pin is sending out a signal (to prevent a feed back loop)? – Code Gorilla Jan 12 '16 at 11:04
  • yeah, I looked at how a 3 pin ultra sonic sensor works, using the ping function from USsensor.ino, and realized that the pinmode is being changed. Its a fix. Thanks guys! – j0h Jan 12 '16 at 16:57

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