problem with multiple SPI to Arduiuno Nano

Hai, Im new at this forum pls correct me if Im wrong. First of all this is my project CanSat which is a can size satellite for a telemetry mission. For this project I,ll be using HTU21 , BMP280,GPS module, SD card module and LORA.

when i try to compile all the codding together there is no error for the codding but the sdCard will fail. and sometime the bmp will fail even though I not changing any of the connection or the codding…
I think the connection is fine but maybe there is something i have to add at my codding in order to use multiple slave connection for arduino nano.

BMP, LORA and SD card are connecting using spi connection.
HTU using I2C onnection.

here are my connection…

LORA => Arduino SD Card => Arduino BMP280 => Arduino
3.3v => 3.3v vcc => 5v vcc => 3.3v
MoSi => D11 MoSi => D11 SDA => D11
MiSo => D12 MiSo => D12 SDD => D12
SCK => D13 SCK => D13 SCL => D13
NSS => D10 csb => D7
RST => D9
DiO => D2

HTU => Arduino GPS => Arduino
Vin => 5v TX => D4
SCL => A5 RX => D3
SDA =>A4

and this is my codding

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include "Adafruit_HTU21DF.h"
#include <SD.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LoRa.h>

#define BMP_SCK 13 
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 8
#define SD_CS 7
#define LORA_CS 10
#define RXPin 4
#define TXPin 3

Adafruit_BMP280 bmP(BMP_CS);
Adafruit_HTU21DF htu = Adafruit_HTU21DF();

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);

void disp(float temp,float pres,float alt,float himu,float lati,float longi);
void save(float temp,float pres,float alt,float himu,float lati, float longi);
void lora(float temp,float pres,float alt,float himu,float lati, float longi);

File myFile;

void disp(float temp,float pres,float alt,float himu, float lati,float longi){
  
    Serial.print(temp);
    Serial.print("    |  ");
    
    Serial.print(pres);
    Serial.print(" |  ");
    
    Serial.print(alt);
    Serial.print("   |  ");

    Serial.print(himu);
    Serial.print("  |");

    Serial.print(lati);
    Serial.print("  |");

    Serial.print(longi);
    Serial.println("  |");
  
  }

void save(float temp,float pres,float alt,float himu,float lati, float longi){

    myFile = SD.open("lagi.txt", FILE_WRITE);
  
    myFile.print(temp);
    myFile.print("    |  ");
    
    myFile.print(pres);
    myFile.print(" |  ");
    
    myFile.print(alt);
    myFile.print("   |  ");

    myFile.print(himu);
    myFile.print("  |");

    myFile.print(lati);
    myFile.print("  |");

    myFile.print(longi);
    myFile.println("  |");
    
    myFile.close();
  }

  void lora(float temp,float pres,float alt,float himu,float lati, float longi){

    LoRa.beginPacket();
    LoRa.print(temp);
    LoRa.print(";");
    LoRa.print(pres);
    LoRa.print(";");
    LoRa.print(alt);
    LoRa.print(";");
    LoRa.print(himu);
    LoRa.print(";");
    LoRa.print(lati);
    LoRa.print(";");
    LoRa.print(longi);
    LoRa.endPacket();           
    }

void setup() {

  Serial.begin(9600);
  ss.begin(9600);
  while (!Serial);
  SPI.begin();

  Serial.println("Initializing all sensor. . .");
  
  if (!bmP.begin()) {
    Serial.println("BME280 error!");
    while (1); 
    }
    
   if (!htu.begin()) {
    Serial.println("Couldn't find HTU sensor!");
    while (1);
      }

  pinMode(LORA_CS, OUTPUT);
  digitalWrite(LORA_CS, HIGH);
  
    if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  
  pinMode( BMP_CS, OUTPUT);
  digitalWrite(BMP_CS , HIGH);
  
  if(!SD.begin(SD_CS)){
     Serial.println("SD Card fail ! ! !");
     while(1);
    }

  Serial.println("All sensor is ok");
  if(SD.exists("lagi.txt")){
    SD.remove("lagi.txt");
    }
    
     myFile = SD.open("lagi.txt", FILE_WRITE);
     if(myFile){
     myFile.println(" Temperature| Preasure | Altitude | Himudity");
     myFile.println("");
     myFile.close();
       }
      else{
        Serial.println("Error opening file");
        while(1);
        }
Serial.println("Temperature| Preasure | Altitude | Himudity|");
}

void loop() {

    float pres = bmP.readPressure() / 100.0F;
    float alt = bmP.readAltitude(1013.25);
    float temp = htu.readTemperature();
    float himu =   htu.readHumidity();
    float lati, longi;

    if (!gps.location.isValid())
  { lati = 0.00;
    longi = 0.00;
  }
  else
  {
   lati =  gps.location.lat();
  longi =  gps.location.lng();
  }
  
    disp(temp, pres,alt,himu,lati,longi);
    save(temp,pres,alt,himu,lati,longi);
    lora(temp,pres,alt,himu,lati,longi);
    
  delay(1000);  
}

i really hope someone can help me with this :frowning: … also thanks in advance to those who read this :wink: .

You should make all SPI SS pins outputs and disable all devices before reading from a device. Else all not properly deselected devices will respond to all requests in parallel.

Why do you connect BMP280 SDD to MISO?

Better connect I2C to SCL/SDA, they are on different pins on e.g. a Mega.

You don't say which SD card module you are using. Whenever a project doesn't work as expected, and an SD card module is used, then there's a very good chance that the problem lies with the SD card module.

More specifically, the MISO signal from the SD card module.

There's several discussions on SD card modules on the forum and how to modify them to work correctly with other SPI devices.

If you can provide a link to the SD card module you have, then we may be able to tell you if the MISO signal is the issue.

Quick update: Have a look at this discussion that I've just looked at. It may solve your oroblem.

The BMP280 is an I2C device (SDA/SCL) and not an SPI device (MISO/MOSI/SCLK/SS). If it was an SPI device it would have a Slave Select pin so it could share the SPI bus.

If we're talking about a Bosch BMP280 digital pressure sensor, then the datasheet I just saw said it supported both interfaces, but not simultaneously.

markd833:
If we're talking about a Bosch BMP280 digital pressure sensor, then the datasheet I just saw said it supported both interfaces, but not simultaneously.

If the OP is using the SPI interface it would be necessary to connect a Slave Select signal. If it's the module that has 6 pins (VCC, GND, SCL, SDA, CSB, SDO) then my guess is they should be wired:
VCC -> +3.3V
GND -> GND
SCL -> SCLK
SDA -> MOSI
CSB -> chosen Slave Select pin
SDO -> MISO
There is likely also a solder jumper to select between I2C/TWI/Wire and SPI. Since the pins are labeled with I2C/TWI/Wire labels I expect that is the default and the OP will have to change the jumper. This will probably involve cutting a trace between two pads and adding a jumper between two other pads. The OP will also need a library that can use the SPI interface. Since all of the examples that I saw use the I2C/TWI/Wire interface, finding such a library may not be trivial.
I would switch to I2C/TWI/Wire.