Analog as Digital Pins?

Hi Guys,

Hopefully just a quick one; I am using an Arduino Nano for my project, I have the following attached;

Pins 11, 12, 13 - 2x MAX7219 daisy chained to drive 11x 7 segment displays
Pins 8, 7, 6, 5 - 2x 74HC165's daisy chained to read buttons
Pins Pins 4, 3, 2 - 2x 74HC595's daisy chained to drive 16 LED's

This leaves me with digital pins 9 and 10 free, as well as RX0 and TX1, and all of the analog pins. I want to use an SD card module which will require 4 pins.

My Question: Can I use the Analog pins as digital pins to drive some of these modules? or do RX0 and TX1 act as digital pins?

I'm happy to start the reading to see the 'how' this would work, but don't want to waste my time digging if it's not possible. I understand that if using analog as digital I may need to reshuffle the pin allocations potentially (for MISO and MOSI compatibility).

Besides A6 and A7 on a 328p, all pins are also digital pins.

A SD card should go to the hardware SPI (11,12,13 again on a 328p),
so it only needs one additional pin.

Hi Whadall, thanks for the quick reply. I intend to attached this to 11, 12 and 13, for MOSI, MISO and CLK, doesn't this also require an SS pin though, so I will need 2 additional pins? I'm hoping I can just move the data pins from the shift registers to the analog pins (one is currently in 13), then move 11 and 12 to free pin 9 and 10 making room for the SD module

Where do you get the 2 from?

Besides that, if you use SPI to drive the 7219's, the SD card would just also connect to SPI.
The usage of MISO for the 7219 does not really make sense to me.

If you misuse the SPI pins for non-SPI, you will have to move them to other pins.

I only have 2 pins free at the moment, which is 9 and 10, and the SD card will require 4 pins to be connected, hence the 2 additional pins.

I didn't realise you could have multiple components connected to the SPI pins. I'm fairly new to the Arduino, so I am using the digital pins as a basic input/output, I haven't learned what the different types of pins there are yet as there hasn't seemed to be a need. I'm happy to read up on this and learn about it rather than asking a million questions, but with the sheer amount of information online (and a lot of it contradicting at that), I want to make sure I'm at least on the right track before researching.

So you should learn about the SPI interface.

(there are links to other information inside that page)

Another bus that can be shared is the I2C bus.

Thanks Whandall, I'll have a read!

The SPI interface acts a lot like a 74HC165 and 74HC595 in parallel. They share an Enable/Select/Latch line and they share a clock line. When the Enable/Select/Latch line is LOW, every clock on the clock line shifts a bit out of the 74HC165 to the data input line and shifts a bit from the data output line into the 74HC595. When the Enable/Select/Latch line is HIGH the shift register output should get off the bus, so you may need a tri-state driver to enforce that.

Because SPI devices act like shift registers, you can connect most shift registers (MAX7219, 74HC165, and 74HC595) to the SPI bus and you only need one additional pin per device for the Enable/Select/Latch.

You could do something like:
All devices share MOSI, MISO, and SCLK, then each has its own Enable/Latch/Select pin:
Pin 10: 2x MAX7219 daisy chained
Pin 8: 2x 74HC165's daisy chained
Pin 7: 2x 74HC595's daisy chained
Pin 4: SD Card
That uses 7 pins, total. It leaves Pins 9, 6, 5, and 3 for PWM. It leaves Pins 3 and 2 for external interrupts. It leace Pins 0 and 1 for Serial. And it leaves A0-A5 for analogRead or Wire.

You can add more devices to each chain without needing more pins... Just send and/or receive more bytes.

1 Like

Thanks John, I've been looking into this and never knew it was possible. I'll have a play around today and see if I can get this working

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