user35160: I have a project where I want to connect a number of SPI devices, and I'm running out of Slave Select pins (SPI) on the Arduino. So I thought that I could use something like an MCP23S17 to get additional pins and use those as SS pins, but most libraries require to pass the pins when initialising, and it seems that I can't pass the MCP's pins as a function/class argument (or can I?). For example:
U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /*cs*/ 12, /*dc*/ 4, /*rst*/ 6);

So my question is: How can I get more SS pins? Thank you

user31105: A maybe dirty solution is to change all the libraries. Everywhere the SS pin is used, instead call a function and set it yourself (by using the MCP23S17). 
To make this a bit better, define a class that contains this functionality to abstract it from the changed library classes.
Example:
As initialization of the library a function or class constructor will be used, e.g.
MCP23S17(void);

This you will use like:
MCP23S17 my_component = MCP23S17();

You need to change this to:
MCP23S17(int ss_pin);

And change the related code, store it in a class variable and use it everywhere in the library instead of the fixed SS pin number.
Than you can constructor your own instance by:
MCP23S17 my_component = MCP23S17(4);

Where 4 is the SS pin number

user4143: I would suggest adding a layer of abstraction in your whole design.
Use the ESP8266 as the main system controller, then farm out sensor communications to one or more other "active" expansion devices. 
Rather than just using an expander for the SS pins you are using the "expander" for all the communication.
By "expander" I basically mean some other microcontroller (maybe an ATMega328P for example) which receives an instruction to sample a sensor then goes off and gathers the data that is wanted and sends it back to the master ESP8266 controller.
How you arrange that communication is up to you, but maybe I2C would be a good way to go.  You could even make the sensor data gathering completely autonomous so that the ESP8266 just then requests the latest data from the slave(s).
It means:

You don't have to change any libraries
You get distributed processing, sharing the work out
The ability to communicate with an almost infinite number of sensors


user30198: My solution would be to keep it simple. Use real pins for every SPI SS. Buy an other Arduino board with more pins if you need more pins.
What else is connected to your Arduino board ? Perhaps it is easier to reduce those pins. Almost all analog pins can be digital pins as well. You could use external ADC modules. Perhaps replacing 1-Wire or DHT11 or DTH22 with I2C sensors. Using a I2C display. There are many options to use buttons and leds with a few pins. And so on.

35160: <p>I have a project where I want to connect a number of SPI devices, and I'm running out of Slave Select pins (SPI) on the Arduino. So I thought that I could use something like an MCP23S17 to get additional pins and use those as SS pins, but most libraries require to pass the pins when initialising, and it seems that I can't pass the MCP's pins as a function/class argument (or can I?). For example:</p>

<pre><code>U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /*cs*/ 12, /*dc*/ 4, /*rst*/ 6);
</code></pre>

<p>So my question is: How can I get more SS pins? Thank you</p>
 31105: <p>A maybe dirty solution is to change all the libraries. Everywhere the SS pin is used, instead call a function and set it yourself (by using the MCP23S17). </p>

<p>To make this a bit better, define a class that contains this functionality to abstract it from the changed library classes.</p>

<p>Example:</p>

<p>As initialization of the library a function or class constructor will be used, e.g.</p>

<pre><code>MCP23S17(void);
</code></pre>

<p>This you will use like:</p>

<pre><code>MCP23S17 my_component = MCP23S17();
</code></pre>

<p>You need to change this to:</p>

<pre><code>MCP23S17(int ss_pin);
</code></pre>

<p>And change the related code, store it in a class variable and use it everywhere in the library instead of the fixed SS pin number.</p>

<p>Than you can constructor your own instance by:</p>

<pre><code>MCP23S17 my_component = MCP23S17(4);
</code></pre>

<p>Where 4 is the SS pin number</p>
 4143: <p>I would suggest adding a layer of abstraction in your whole design.</p>

<p>Use the ESP8266 as the main system controller, then farm out sensor communications to one or more other "active" expansion devices. </p>

<p>Rather than just using an expander for the SS pins you are using the "expander" for all the communication.</p>

<p>By "expander" I basically mean some other microcontroller (maybe an ATMega328P for example) which receives an instruction to sample a sensor then goes off and gathers the data that is wanted and sends it back to the master ESP8266 controller.</p>

<p>How you arrange that communication is up to you, but maybe I2C would be a good way to go.  You could even make the sensor data gathering completely autonomous so that the ESP8266 just then requests the latest data from the slave(s).</p>

<p>It means:</p>

<ul>
<li>You don't have to change any libraries</li>
<li>You get distributed processing, sharing the work out</li>
<li>The ability to communicate with an almost infinite number of sensors</li>
</ul>
 30198: <p>My solution would be to keep it simple. Use real pins for every SPI SS. Buy an other Arduino board with more pins if you need more pins.</p>

<p>What else is connected to your Arduino board ? Perhaps it is easier to reduce those pins. Almost all analog pins can be digital pins as well. You could use external ADC modules. Perhaps replacing 1-Wire or DHT11 or DTH22 with I2C sensors. Using a I2C display. There are many options to use buttons and leds with a few pins. And so on.</p>
