Inexplicable behavior of (i guess) the SPI bus...

Hello there!

I am trying to use a BME280 sensor (pressure,temperature and humidity sensor) and store it's data into a text file that exists in an SD card. But i have come across many and different problems.
First of all, i am using a WeMos D1 mini as my microcontroller, the no-brand bme280 sesnsor (https://www.ebay.com/itm/GY-BME280-3-3-BME280-Atmospheric-Pressure-Humidity-Sensor-Mo
dule-Arduino-SPI-IIC-/361970198224) and the no-brand SD card shield for the wemos d1 mini.
I am trying to connect those two to the wemos as 2 slaves that i will supposedly switch between by pulling each select pin to LOW when i need it. But, I cannot seem to be able to get the SD to initialize. Ofcourse i have tested them separately and they work like charm.
I am connecting them like this:

WEMOS PINS SD SHIELD PINS BME280 PINS
D1 D5 (CLK) SCK
D2 D7 (MOSI) SDA(MOSI)
D3 - CSB
D4 D6 (MISO) SDO(MISO)
D8 D8 (CS) -

I am powering them both with 3.3V (which is the working voltage for both)

I am completely lost at this point, any help would be MUCH appreciated.

My code is like this

#include "SdFat.h"
SdFat SD;
#define BME_SCK D1
#define BME_MISO D4
#define BME_MOSI D2
#define BME_CS D3

#define SD_CS 8
File myFile;
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;

void setup() {
pinMode(3, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(115200);

digitalWrite(3, LOW);
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
int temp = bme.readTemperature();
digitalWrite(3, HIGH);
Serial.print("Initializing SD card...");
digitalWrite(8, LOW);

if (!SD.begin(SD_CS,SPI_HALF_SPEED)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

myFile = SD.open("test1.txt", FILE_WRITE);

if (myFile) {
myFile.println(temp);
myFile.close();
Serial.println("done.");
} else {
Serial.println("error opening test1.txt");
}
// re-open the file for reading:
myFile = SD.open("test1.txt");
if (myFile) {
Serial.println("test1.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else {
Serial.println("error opening test1.txt");
}
}

void loop() {
// nothing happens after setup
}

  1. get SD card working without sensors
  2. get sensors working without SD card
  3. combine

like i said i have tested them separately and they work. the combo is not working however.

But, I cannot seem to be able to get the SD to initialize. Ofcourse i have tested them separately and they work like charm.

Sounds like you bought an SD card adapter that doesn't correctly behave as an SPI device. Many of the ultra-cheap Chinese devices don't put MISO into tri-state if CS is pulled HIGH. Get a better SD card adapter, you might have to pay a little more for it.