Two SPI Devices, 1 pin


I’m running very short of pins on my project (6 pwm channels for fans, 6 tach channels for fans, Analog Buttons, LCD, 1 wire bus, and probably something I’m forgetting)

Does anyone see a reason I couldn’t save a pin by using an inverter (SN74AHC1G04DBVT) on the CS pin to select between LCD and SD over SPI?

Or will it not work at all?


The SPI bus is not a good standard, and you shouldn't not do funny things with it.
Can you add a shift register for the display ? Or use a I2C I/O expander.
One or two shift registers is the most simple.

Can you show us the use of all the pins ? and for which Arduino board ?

Well... if you must know. You can use the SD CS in a normal way, and use the display without programming a chip select (it is selected when the SD card is not selected). But the smallest glitch in hardware or software could cause the serial SPI data for the display running out of sync. I would not go there.

You can combine a part of the wires for the display to read the buttons. You can use analog inputs as digital pins. There are a few possibilities before using a shift registers.

The SD card is not the best device to try that with. To get it to release the MISO line, you must send an additional byte over the SPI bus after setting the SS HIGH. With your logic, that would send that extra byte to the LCD. That could cause problems.

Read this thread, especially the part starting at reply #9 by fat16lib.

I'm using a Lenardo clone

SPI is hardware
0 - serial
1 - serial
2 - LCD CS
3 - Fan PWM
4 - LCD DC
5 - Fan PWM
6 - Fan PWM
7 - LCD Reset
8 - One wire bus (thermometers)
9 - Fan PWM
10 - Fan PWM
11 - Fan PWM
12 - Fan TACH
13 - Lcd backlight PWM

A5 Analog Button

I have pondered using a multiplexer to read the fan tach - I also pondered using DS2423's for the tach but they don't exist any more.

I could use an ATTiny13 for the tach also but truth be told I only need to check every now and then to make sure the fans are actually spinning so as to sound an alarm.

Do you use the serial port at RX pin 0 and TX pin 1 ? Because the serial communication to the computer does not use that on a Leonardo board.

So you use all the pins plus the ICSP header for the SPI bus ? That is pretty much everything :o

When you want to have a more flexible setup, I would not move the tach inputs to a mux, but move the PWM outputs to a dedicated chip:

You can use them also for the backlight PWM, so 7 pwm are done with that chip, and you need the I2C pins (digital pin 2 and 3 for a Arduino Leonardo).

It is probably not possible to use the Display Reset, CS, backlight for something else. Perhaps the DC can be used for something else. But perhaps not the analog signal from the buttons, since I don't know what the display would do with an analog level at the DC pin.

Do you have a SD module with level shifter ? Because the SD card needs 3.3V SPI bus, and I assume that the display uses a 5V SPI bus.

The Arduino Pro Mini uses the smd version of the ATmega328P, with A6 and A7. That are two more pins, but it has only 6 PWM outputs (Leonardo has 8 PWM outputs), but if you need the serial monitor you have 2 pins less (RX and TX). You could of course also upgrade to an Arduino Mega 2560.

Well, I don't yet have anything on pins 0 and 1 but I do have plans to - want to hook a ESP8266 module up to it.

The reason I was pondering muxing the tach is I can just wander across the road and get a 74HC151 from Jaycar for $2 - here in Queensland, our parts shopping choice is limited :smiley:

Also, truth be told I could sacrifice the LCDs backlight PWM and just have a push button (or use a DS2413) to turn it on and off - it's more about reducing the light level at bed time, off works as well as dim for that. I couldn't use that pin for a CS but I could move one of the fans up there (it's pulsed during bootloading)

Ideally, I'd get one of these - MAX31790/MAX31785 - it does 90% of the work for me, but I'm not ready to deal with TQFN packages

This clone board is switchable, the whole thing is running 3.3v - saving me a level shifter :slight_smile:

Actually, I wonder if I can't use the DS2413 to be my CS for the SD card...

(Why DS2413, well, because I have a couple here, no waiting or cost involved :D)

…want to hook a ESP8266 module up to it…

Sure, why not, we all want that :stuck_out_tongue:

The chip select for the SD is in the library. So please don’t be tempted to use something extra like the DS2413 for the SD. That I/O expander is also very slow with its OneWire and it doesn’t have normal outputs, but open-drain outputs.

The 74HC151 as input mux will create more problems than it is solving. You could miss a pulse while the Leonardo is busy with the OneWire.

Is that pwm chip with I2C from Adafruit not okay? They also give a library for it.

I think you want too much. I suggest to just use pin 0 and 1. That way you can continue with this project.
Start with the ESP8266 on a new Arduino board.
When you want to add the ESP8266 to this project, you also have to use such an pwm chip with I2C. I think there is no other way.