[Solved]- SPI and use A4 (MISO) as Digital Input

I use SPI to drive a Ledstrip, however I only use the CLK (A3) and MOSI (A5). Is it possible to use the other pins (A2 (SS) and A4 (MISO)) for other purposes?

I have now a button on A4, however when using SPI the button keeps reading 0. So I suppose it’s because I’m using SPI.

When I don’t use SPI the pin reads out it’s values correctly.

@kasper, the hardware SPI may be setting A4 to INPUT so I would say NO, you can’t use A4 with hardware SPI enabled.

1 Like

And what about the A2 (SS) pin?

@kasper, SPI.begin() will, by default, set A2 as an OUTPUT pin even if you don’t use it. Using SPI.begin(user CS pin) will set the pin you specify as CS as OUTPUT, leaving A2 unchanged. So in the first case, you need to set A2 after the begin() call and the other case, you can set before or after.


Clear! Thank you for the fast response.

1 Like

Thanks for the great help @peekay123!

1 Like

Sorry to re-open this. I’m doing my hardware design. I read different opinions about what to do with unused pins. I’d like to have the hardware as stable as possible (regarding EMC, EMI).

Some suggest to configure them as outputs and adding an external pull-down. Some as inputs with an external pull-down. There is also some information about the Startup default for different pins (a short LOW as I understood right).

I was wondering what is the correct thing to do with the SPI pins. Right now I configure them like that (from what I understood SPI.begin does it in that way as well).

I don’t use SPI2 right now but might use it in the future (but my hardware design needs to be ready for it).

pinMode(A2, OUTPUT);  // unused SPI SS will be set as output
pinMode(A3, OUTPUT);  // SPI SCK
pinMode(A4, INPUT);   // unused SPI MISO
pinMode(A5, OUTPUT);  // SPI MOSI

pinMode(D2, OUTPUT);  // unused SPI2 MOSI
pinMode(D3, INPUT);   // unused (SPI2 MISO)
pinMode(D4, OUTPUT);  // unused SPI2 SCK
pinMode(D5, OUTPUT);  // unused SPI2 SS