Hello. I've just bought a BME280 sensor. The sensor works fine with Arduino Uno, but when I try using it on the Nano, it does not work.
I know that the sensor works, because it works on Uno. I have burned the bootloader to the Nano card, and the code is uploading and running on card. I've also tried other codes, and all of them works on my Nano card.
The wiring I've used on the Nano and Uno is identical, and I've used this diagram as a help:
Vcc --> 3V3
GND --> GND
SDI --> digital pin 11 (MOSI)
SCK --> digital pin 13 (SPI-clock)
CSB --> digital pin 10 (Chip select)
SDO --> digital pin 12 (MISO)
This is the code I'm running (Adafruit example code for BME280):
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
//Adafruit_BME280 bme; // I2C
Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
Serial.println(F("BME280 test"));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
// Convert temperature to Fahrenheit
/*Serial.print("Temperature = ");
Serial.print(1.8 * bme.readTemperature() + 32);
Serial.println(" *F");*/
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}
When I run the program it prints "Could not find a valid BME280 sensor, check wiring!"
Therefore, I have tried to wire the sensor differently, for example connecting SCK and SDI to analog pin 4 and 5. None of the wiring I've tried works. I have also checked that there is power going through the different cables.
This is frustrating. Does anyone have any clue and tips for what I should do?