hello,
I want to build a weather station using an esp 32 Devkitc v4. the part with the wind meter wind vane and rain meter work ok (mostly ) .I want to add the rtc ds3231 via I2C, work OK, and I want add temperature and pressure (humidity too but obviously aliexpress don't know the difference between bmp and bme ;-( ), the ds3231 and the bmp280 are on the same I2C pins (gpio 21 and 22 as per the pinout.
the pb is I can get the bmp working with the bmx280MI library and the simple example ino file:
// BMx280_I2C.ino
//
// shows how to use the BMP280 / BMx280 library with the sensor connected using I2C.
//
// Copyright (c) 2018 Gregor Christandl
//
// connect the AS3935 to the Arduino like this:
//
// Arduino - BMP280 / BME280
// 3.3V ---- VCC
// GND ----- GND
// SDA ----- SDA
// SCL ----- SCL
// some BMP280/BME280 modules break out the CSB and SDO pins as well:
// 5V ------ CSB (enables the I2C interface)
// GND ----- SDO (I2C Address 0x76)
// 5V ------ SDO (I2C Address 0x77)
// other pins can be left unconnected.
#include <Arduino.h>
#include <Wire.h>
#include <BMx280I2C.h>
#define I2C_ADDRESS 0x76
//create a BMx280I2C object using the I2C interface with I2C Address 0x76
BMx280I2C bmx280(I2C_ADDRESS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//wait for serial connection to open (only necessary on some boards)
while (!Serial);
Wire.begin();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
if (!bmx280.begin())
{
Serial.println("begin() failed. check your BMx280 Interface and I2C Address.");
while (1);
}
if (bmx280.isBME280())
{
Serial.println("sensor is a BME280");
}
else
{
Serial.println("sensor is a BMP280");
}
//reset sensor to default parameters.
bmx280.resetToDefaults();
//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (bmx280.isBME280())
bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
//start a measurement
if (!bmx280.measure())
{
Serial.println("could not start measurement, is a measurement already running?");
return;
}
//wait for the measurement to finish
do
{
delay(100);
} while (!bmx280.hasValue());
Serial.print("Pressure: "); Serial.println(bmx280.getPressure());
Serial.print("Pressure (64 bit): "); Serial.println(bmx280.getPressure64());
Serial.print("Temperature: "); Serial.println(bmx280.getTemperature());
//important: measurement data is read from the sensor in function hasValue() only.
//make sure to call get*() functions only after hasValue() has returned true.
if (bmx280.isBME280())
{
Serial.print("Humidity: ");
Serial.println(bmx280.getHumidity());
}
}
work ok , I get the normal value....
Pressure: 102373.00
Pressure (64 bit): 102370.33
Temperature: 23.88
but when I use the code in my code
#include <Wire.h>
#include <DS3231.h>
#include <Arduino.h>
#include <BMx280I2C.h>
DS3231 myRTC;
#define I2C_ADDRESS 0x76
BMx280I2C bmx280(I2C_ADDRESS);
bool century = false;
bool h12Flag;
bool pmFlag;
float tempe=0;
float press=0;
// pour le Macch +19.7HPa pour compensation altitude
const int gir = 34;
const int pluiv = 39;
const int anemo = 36;
unsigned long time1=0;
unsigned long time2=0;
unsigned long time3=0;
float rafale=0;
unsigned long vent=0;
float vent1=0;
float vent2=0;
unsigned long nbmesure=0;
float ventmoyen=0;
float pluvio=0.2794; //mm eau par impulsion
long pluie=0;
float pluie2=0;
float pluieh24=0;
unsigned long girouette=0;
char dirvent[]=" n ";
int heure ;
int sec;
int year;
int moid;
int jour;
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(100000);
bmx280.resetToDefaults();
attachInterrupt(digitalPinToInterrupt(anemo), interruptVent, RISING);
attachInterrupt(digitalPinToInterrupt(pluiv), interruptPluie, RISING);
time2=millis();
time3= millis();
}
// interruptVent
void interruptVent(){
vent=vent+1;
}
//interruptPluie
void interruptPluie(){
pluie=pluie+1;
}
void loop() {
// put your main code here, to run repeatedly:
time1= millis();
if (time1-time2>3000){
time2=millis();
vent1=(3.14*0.07*2*vent)/3*3.6; //
if (vent1>rafale) rafale=vent1;
nbmesure++;
vent2=vent2+vent1;
Serial.print ("vent :");
Serial.println(vent1);
Serial.print ("pluie :");
Serial.println (pluie);
vent=0;
}
// toutes les minutes
if (time1-time3>20000){
//calcul vent moyen et rafale sur 1 minute
ventmoyen=vent2/nbmesure;
Serial.print("vent moyen :");
Serial.println(ventmoyen);
Serial.print ("rafale :");
Serial.println(rafale);
vent2=0;
rafale=0;
nbmesure=0;
time3=millis();
//pluviometre
pluie2=(pluie*pluvio);
pluieh24=pluieh24+pluie2;
Serial.print("mm de pluie :");
Serial.println(pluie2);
Serial.print("24h :");
Serial.println(pluieh24);
pluie=0;
pluie2=0;
// inserer remise à zero pluieh24 si heure >0h00 et <0h02
//girouette
girouette=analogRead(gir);
//if (girouette> && girouette < ) dirvent=" N ";
//if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
//if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
//if (girouette> && girouette < ) dirvent=" N ";
// if (girouette> && girouette < ) dirvent=" N ";
//if (girouette> && girouette < ) dirvent=" N ";
//if (girouette> && girouette < ) dirvent=" N ";
Serial.print ("Vent de :");
Serial.println (girouette);
if (!bmx280.measure())
{
Serial.println("could not start measurement, is a measurement already running?");
return;
}
while (!bmx280.hasValue());
Serial.print("Pressure: ");
Serial.println(bmx280.getPressure());
Serial.print("Temperature: ");
Serial.println(bmx280.getTemperature());
Serial.print(myRTC.getYear(), DEC);
Serial.print("-");
Serial.print(myRTC.getMonth(century), DEC);
Serial.print("-");
Serial.print(myRTC.getDate(), DEC);
Serial.print(" ");
Serial.print(myRTC.getHour(h12Flag, pmFlag), DEC); //24-hr
Serial.print(":");
Serial.println(myRTC.getMinute(), DEC);
}
}
I get :
Pressure: nan
Temperature: nan
0-1-1 0:23
So the ds3231 give the date /hour (the I2C is working )
but I can't get the temperature and pressure from the bmp.
I tried different library with the same result.
as it work with the same wiring and the test sketch, and not in mine, obviously there is something in my code.
I tried with no interrupt , but no chance
I'm a rather beginner in arduino, my last programming was in turbo pascal and Dbase4 (less than 60 can't know
sorry for the bad english, french school 40 years ago
thank you for any tip.