Buenas
Tengo un problema con el sensor bmp280, a ver si alguno me puede decir que estoy haciendo mal
Lo primero que he hecho es cambiar la dirección en el archivo “bmp280.h” a 0x76,
Luego he probado primero con conexion spi y me dice que no reconoce el dispositivo:
#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);
while ( !Serial ) delay(100); // wait for native usb
Serial.println(F("BMP280 test"));
unsigned status;
status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
//status = bmp.begin();
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
/* 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);
}
salida serial:
foto conexiones:
Como no me funcionaba he probado con el i2c y si que me funciona:
#include <SPI.h>
#include <Wire.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);
while ( !Serial ) delay(100); // wait for native usb
Serial.println(F("BMP280 test"));
unsigned status;
//status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
status = bmp.begin();
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
/* 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);
}
salida serial:
conexiones:
El PROBLEMA me viene al incluir en el programa el resto de periféricos: añado pantalla oled I2C y dht22 :
#include <Adafruit_BMP280.h> //para el mmodulo bmp280
#include <Adafruit_SSD1306.h> //para pantalla oled
#include <Adafruit_GFX.h> //para pantalla oled
#include <Wire.h> //para I2C (pantalla oled y bmp)
#include <LowPower.h> //para el modo sleep
#include <DHT.h> //para senson temp y hum
#include <GFButton.h> //biblioteca manejo botones
#include <SPI.h> //para conexion spi
//definimos las constantes
#define DHTPIN 4 //pin conectado del dht
#define DHTTYPE DHT22 //modelo del dht
#define ANCHO_PANTALLA 128 // ancho pantalla OLED
#define ALTO_PANTALLA 64 // alto pantalla OLED
const int wakeUpPin = 2; //para despertar arduino hay que conectar el boton al pin 2 o 3
//declaramos los vectores para t, h y p
int dim=12;
float temp[12]={0,0,0,0,0,0,0,0,0,0,0,0};
float hum[12]={0,0,0,0,0,0,0,0,0,0,0,0};
float pre[12]={0,0,0,0,0,0,0,0,0,0,0,0};
float t;
float p;
float h;
float hic;
volatile bool despierto = false; // variable para la interrupcion
//declaramos los perifericos
Adafruit_BMP280 bmp; //el bmp280-->bmp
Adafruit_SSD1306 oled(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, -1); //la pantalla oled-->oled
DHT dht(DHTPIN, DHTTYPE); //el dht22-->dht
void setup() {
Serial.begin(9600);
pinMode(wakeUpPin, INPUT); // Configure wake up pin as input.
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Iniciar pantalla OLED en la dirección 0x3C
oled.cp437(true); //Activar página de código 437 para los simbolos
dht.begin(); // Iniciar el sensor DHT
bmp.begin(); // Iniciar el sensor bmp
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. */
oled.clearDisplay();
oled.setTextSize(3);
// Color del texto
oled.setTextColor(WHITE);
oled.setCursor(8, 32);
oled.println("hhola ");
oled.display();
delay(2000);
}
void loop() {
//leemos los datos
t=dht.readTemperature();
h = dht.readHumidity();
hic = dht.computeHeatIndex(t, h);
p = bmp.readPressure()/100; // almacena en variable el valor de presion divido por 100 para covertirlo a hectopascales
//mostramos datos en serial
Serial.println("------------------------------------------------");
Serial.print(F("Temperatura = "));
Serial.print(t);
Serial.println(" *C");
Serial.print(F("humedad = "));
Serial.print(h);
Serial.println(" %");
Serial.print(F("presion = "));
Serial.print(p);
Serial.println(" hpa");
Serial.print(F("sensacion termica = "));
Serial.print(hic);
Serial.println(" *C");
//mostramos los datos en pantalla
oled.clearDisplay(); // Limpiar buffer
oled.setTextSize(2); //tamaño de texto
oled.setTextColor(WHITE); // Color del texto
oled.setCursor(8, 0);
oled.print("T: ");
oled.println(t);
oled.setCursor(8, 16);
oled.print("H: ");
oled.println(h);
oled.setCursor(8, 32);
oled.print("P: ");
oled.println(p);
oled.setCursor(1, 48);
oled.print("Sen: ");
oled.println(hic,1);
oled.display(); //enviamos datos al oled
delay(2000);
}
salida serial:
las conexiones son iguales que en la segunda foto. mis preguntas son:
¿que tengo mal en la conexion spi para que no me reconozca el sensor?
¿por que si uso conexion i2c inicialmente me funciona pero si inicializo la pantalla oled, que tambien va por i2c pero con diferente direccion (creo), me da presiones negativas?
Gracias por vuestro tiempo!