Can I connect several components on same digital pins?

Hello everyone,
I would appreciate if you can help me with my questions,

I have a project that I want to try to connect the below components to Arduino UNO R3:

  • TFT ST7735 (Will connect to Digital pins 8, 9, 10, 11, 13)
  • SD card module (Will connect to Digital pins 4, 11, 12, and 13)
  • Ultrasonic HC-SR04 (Will connect to Digital pins 11 and 12)
  • Motor shield L293D

Before that, I tried to connect the SD card module, Ultrasonic, and Motor shield at the same time to Arduino UNO R3 and it was successful.

It should be noted that Analog pins (A4 and A5) will connect to an RTC module and also A0, A1, A2, and A3 will connect to different sensors.

  1. Do you think it makes a problem for the board to keep these components connected at the same time to digital pins?

  2. I just want to know that can I add the TFT also to this project?

  3. Can I use A4 and A5 at the same time for an RTC module and a BME280 (Temperature, Humidity, and Pressure) sensor?

Thanks a lot,
Milad

You clearly need to get wise to busses - I2c and SPI, and also what you are holding in your hand.. If you were already, you would not be asking these questions.

Not in order, the SD card is an SPI device and you have already demonstrated it works and you are doing the right thing.

If HC-SR04 is also an SPI device, it may share with SD, but requires it's own CS pin, not pin 4.

The RTC is an I2C device and goes on the I2C bus, pins A4,A5, and it may share with other I2C devices.

Pins A0>A3 may be used as digital or analogue.

  1. Incoherent

  2. IF the ST7735 is an SPI device, it may share the bus with SD. If not SPI you should be able to put it on "non-bus" pins, like 2,3,5,6,7,8,9

  3. IF the BME280 is an I2C device, it can share with RTC.

I'm not sure you really have a problem, but you need to know which pins the motor shield actually uses. The SPI and I2C pins are most probably just pass-through.

Thank you so much Nick_Pyner,

Sorry,
But I didn't add the ST7735 yet. Today I read something about it and I thought maybe it makes a problem for the Arduino board if I try to connect several components to the same digital pins. So, I asked this question.

Thanks a lot for your time and your reply, It was very helpful for me.

Cheers,
Milad

I don't know anything about ST7735, but I believe it is commonly used on Arduino and should not be a problem.

I doubt the the SD card worked with the HC-SR04 on pins 11/12 as this conflicts with the shared hardware SPI pins 11/12/13.

The ST7735 uses hardware SPI so your pin selection is fine but the HC-SR04 cannot remain on pins 11/12, it needs its own dedicated digital pins. You also need a PWM pin for the L298. The possibles that remain are pins 3, 5 and 6.

This may help with pin selections:

https://forum.arduino.cc/index.php?action=dlattach;topic=146315.0;attach=90365

Pin 10 SS is the secret here for SPI.
If you have multiple SPI devices, each one needs its own SS (Select) pin.
You also need to specify those different pins in your libraries or code.

I2C devices have unique addresses- scan the bus to find them, then use those addresses in your code.
Worst case you could need an I2C multiplexer (unlikely).

Reading the initial description, no code, no wiring attached, I wonder which libraries OP is using.
woodoo.h?
wizard.h?
magic.h?

Just to give some more details on what @WattsThat said. The reason why the HC-SR04 can't share pins 11 and 12 is because it's not an SPI device. You can share the SPI bus between multiple SPI devices. But if you're using pins 11, 12, 13 for SPI communication, you can't have any non-SPI devices connected to those pins.