Arduino Nano PIND not reflecting actual pin values

I'm attempting to use an Arduino Nano in a project where I need to read blocks of pins as quickly as possible. I know that for D0-D7 I should be able to read PIND. So in setup() I call the following to set all the pins in PIND to input:

DDRD = B00000000;

I then attempt to print PIND (along with doing a digitalRead(2)) in loop(). While that is running I use a jumper wire on my breadboard to either pull D2 to ground or to 5V. The digitalRead(2) call shows me the expected value on pin D2, but I see no changes reflected in PIND. Am I doing something obviously wrong? I used similar code on an Arduino Mega (with the appropriate PINx for that platform) and it works fine.

Any help is appreciated.

First off, how are these inputs wired ?

Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.

why don't you use pinMode()

buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.

Maybe just me but your question description is not very clear.

Do you mean PORTD , what is PIND ?

You are also only reading PIN 2 no other pins.

What exactly do you want to achieve?

Nothing at all wrong with the complete sketch you posted that demonstrates this curious problem.

Oh, wait…

a7

Undoubtedly, but it won't be obvious until you post the code, using code tags.

PIND works fine.

Sorry, it was late and I rushed to post. My mistake, all, and I appologize for that. I ended up resolving my issue this morning. Not sure what I was doing wrong but I've gotten it working now.

Thanks to the several people who decided to pile on make snarky remarks about not having posted enough information after it was already pointed out several times before. Very helpful! :stuck_out_tongue_winking_eye:

Seriously though, my mistake. Apologies all around.

The input buffer on PORTD. The data sheet has the details.

1 Like

In the future, you might get better help if you follow the posting rules of the forum.

If you are unable to supply information or answer questions, other forums might be a better fit for you.

PS
99.9% of the time, the problem lies with the user.

Yes , is the OP trying to read the buffer as one byte all 8 bits and then see which bit is high?

We will never know as the OP made the decision we did not need to see more information.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.