Hi
The code is my weather station to which I added the BMP280 and code to read barometic pressure. The whole thing runs on a NodeMCU and wiring, pins and code work in another setup I used for testing the BMP. Fine readings. Added to the weather station code, the BMP reads 0.00 all the time. Frustrating as I know it's good. I figure it's conflicting with something else but i can't work out what. Constructive help will be much appreciated.
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Button.h> #include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
int ventetidSekunder = 120;
const char* ssid =
const char* password =
const char* server =
String apiKey =
/* pins til BMP280
* GND til GND
* VCC, CSB og SDO alle til 3.3v
* SCL til D1
* SDA til D2
*/
#define DHTPIN 0 // D3 på NodeMCU
#define NULSTIL_PIN 2 // D4 på NodeMCU
#define MAALER_PIN 14 // D5 på NodeMCU
#define PULLUP true
#define INVERT true
#define DEBOUNCE_MS 0
int lysPin = A0; // A0 på NodeMCU
int lysStyrke = 0;
int tip = 0;
int lufttryk = 0;
float dagMaksTemp = 0;
float dagMinTemp = 0;
float fugt = 0;
float millimeter = 0;
unsigned long time_now = 0;
Button maaler(MAALER_PIN, PULLUP, INVERT, DEBOUNCE_MS);
Button nulstil(NULSTIL_PIN, PULLUP, INVERT, DEBOUNCE_MS);
DHT dht(DHTPIN, DHT22, 40);
Adafruit_BMP280 bme;
WiFiClient client;
void setup() {
Serial.begin(9600);
dht.begin();
WiFi.begin(ssid, password);
float f = dht.readTemperature(true);
float t = (((f-32)*5)/9);
dagMaksTemp = t;
dagMinTemp = dagMaksTemp;
}
void loop() {
if(millis() > time_now + ventetidSekunder * 1000){
time_now = millis();
lysStyrke = analogRead(lysPin);
// lufttryk = (bme.readPressure() / 100);
delay(15);
float fugt = dht.readHumidity();
while (fugt > 111 ) {
float fugt = dht.readHumidity();
delay(15);
}
delay(15);
float f = dht.readTemperature(true);
float t = (((f-32)*5)/9);
delay(15);
if (t > dagMaksTemp) dagMaksTemp = t;
if (t < dagMinTemp) dagMinTemp = t;
Serial.print("Temperatur = ");
Serial.print(t);
Serial.print(" Luftfugtighed = ");
Serial.print(fugt);
Serial.print(" Lysstyrke = ");
Serial.print(lysStyrke);
Serial.print(" Lufttryk = ");
Serial.print(bme.readPressure() / 100);
if (client.connect(server,80)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String((float)t);
postStr +="&field2=";
postStr += String((int)fugt);
postStr +="&field3=";
postStr += String((int)lysStyrke);
postStr +="&field4=";
postStr += String((float)millimeter,1);
postStr +="&field5=";
postStr += String((float)dagMaksTemp,1);
postStr +="&field6=";
postStr += String((float)dagMinTemp,1);
// postStr +="&field7=";
// postStr += String((int)lufttryk,1);
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
client.stop();
}
maaler.read();
if (maaler.wasPressed()) {
tip++;
delay(20);
}
millimeter = tip * 0.315;
nulstil.read();
if (nulstil.wasPressed()) {
tip = 0;
float f = dht.readTemperature(true);
float t = (((f-32)*5)/9);
dagMaksTemp = t;
dagMinTemp = dagMaksTemp;
}
}