How to use SPI for multiple devices

I want to make 4 humidity/temperature sensors that will run on batteries. They will use the mysensors project and display the values one a Nokia 5510 screen. I will use 3.3V pro minis.

For this project I will need to connect 3 SPI devices. The BME280 module, the nokia screen, and the NRF24L01+ radio. I don't have any experience with SPI but as far as I know I should be able to share pin 11, 12 and between 13 all of them, but the screen won't use 12. And why does the screen no have an SS pin? The fact that everybody seems to name these things differently only adds to the confusion.

The problem that I have is that I can find usable libaries for all this stuf but have no idea how to combine it. The sketches I find to display the BME280 output on a nokia screen use I2C for the sensor, this is not an option for me, and also not a solution, since I also need to correct the radio. I don't think I can use the Adafruit libaries because they seem to assume that the device the libary is made for is the only think connected using SPI (correct me if I am wrong).

I have some C++ knowledge, but I lack the routine. I started this knowing that it might not be as easy as just connecting some modules together and pasting some code. But at the moment I don't know what the correct route is.

Each device on the SPI bus must have a SS "slave select" or CS "chip select" input.

You need to get each part of the project working to your satisfaction before you can start thinking about putting several parts together.

For the Nokia 5510 screen, check the hookup guide and Arduino example here. SCE is the Slave Chip Enable pin. Commonly called Chip Select pin (CS pin) or Slave Select pin (SS pin) as noted by jremington. Yeah, all the SPI pins have many names.

jremington: Each device on the SPI bus must have a SS "slave select" or CS "chip select" input.

You need to get each part of the project working to your satisfaction before you can start thinking about putting several parts together.

Of course, there are some modules where the cs pin is tied low. And there are some chips that aren't quite spi ( max7219 comes to mind - i think it has one, but doesn't honor it in some.regard. I forget the details)

I have used a Nokia 5110 or ILI9341 (SPI) LoRa device (SPI) and a FRAM (SPI or I2C) on the same ARDUINO, ATMEGA328 and DUE, no problem.

I have also used a I2C BME280 sensor and I2C GPS with the same setup, so I can see why you say;

"The sketches I find to display the BME280 output on a nokia screen use I2C for the sensor, this is not an option for me, and also not a solution"

I2C and SPI are independant interfaces.

This Simple nRF24L01+ Tutorial may help. For the nRF24 any pins can be used for CE and CSN.

It is common to use pin 10 (on an Uno - I guess the mini is the same) as Slave Select but it is not essential. However Pin 10 must be set as OUTPUT to ensure the the Arduino acts as SPI master.

Choose suitable pins for each device and then write short programs to test each device on its own. Don't try to connect all the devices before you know how to get each working on its own.

Be aware that there are different SPI settings and it is possible that some of your devices require incompatible settings but that can be handled by applying the appropriate settings before trying to communicate with each device.

...R

srnet: I have used a Nokia 5110 or ILI9341 (SPI) LoRa device (SPI) and a FRAM (SPI or I2C) on the same ARDUINO, ATMEGA328 and DUE, no problem.

I have also used a I2C BME280 sensor and I2C GPS with the same setup, so I can see why you say;

"The sketches I find to display the BME280 output on a nokia screen use I2C for the sensor, this is not an option for me, and also not a solution"

I2C and SPI are independant interfaces.

The problem is that I am using a Pro mini, so A5 is not easy to use. The other issue is that I need 2 SPI devices already (the screen and the radio), so communicating with the BME280 using I2C will not solve the issue of having to use multiple SPI devices anyway.

eeweew: The problem is that I am using a Pro mini, so A5 is not easy to use. The other issue is that I need 2 SPI devices already (the screen and the radio), so communicating with the BME280 using I2C will not solve the issue of having to use multiple SPI devices anyway.

Why is using A5 with a Pro Mini 'not easy' ?

I have not had a problem using a couple of SPI and a couple of I2C devices on a Pro Mini.

Because of the location of A5. What will be the advantage of using I2C for the BME280?

Because you said;

“The sketches I find to display the BME280 output on a nokia screen use I2C for the sensor, this is not an option for me”

Since the A4, A5 pins on the Pro Mini are accessible, I was left wondering what reason there could be for them not being available.