Hello, I am using gy-bmp280 sensor for pressure readings which works fine when i use I2C and the bidirectional level shifter ( which i made myself by following the circuit online ) but when i switch to SPI mode it doesn't work. I am using adafruit bmp280 library.
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)
//Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
/* Default settings from datasheet. /
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, / Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. */
}
void loop() {
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
delay(2000);
I made the level shifter using this circuit.
Source - Bi-Directional MOSFET Voltage Level Converter 3.3V to 5V'
I checked the voltage levels so they are perfectly fine. So , my concern is if I2C works then why SPI is not working ??