0

im experiencing troubles with combining a arduino sketch with BMP280 and BM1750. At this moment i have 2 sketches which need to be combined.


#include Wire.h>
#include BH1750.h>

// ADDR line LOW/open:  I2C address 0x23 (0x46 including R/W bit) [default]
// ADDR line HIGH:      I2C address 0x5C (0xB8 including R/W bit)
BH1750 sensor(LOW);

void setup()
{
  Serial.begin(115200);
  Serial.println(F("BH1750 continues measurement basic example"));

  // Initialize I2C bus
  Wire.begin();

  // Initialize sensor in continues mode, medium 1 lx resolution
  sensor.begin(ModeContinuous, ResolutionMid);

  // Start conversion
  sensor.startConversion();
}

void loop()
{
  uint16_t lux;

  // Wait for completion (blocking busy-wait delay)
  if (sensor.isConversionCompleted()) {
    // Read light
    lux = sensor.read();

    // Print light
    Serial.print(F("Light: "));
    Serial.print(lux);
    Serial.println(F(" LUX"));
  }
}

and the BMP280


#include  Wire.h>
#include SPI.h>
#include Adafruit_Sensor.h>
#include Adafruit_BMP280.h>
#include ESP8266WiFi.h>
#include BH1750.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
BH1750 lightMeter;



/**************************  
 *   S E T U P
 **************************/
void setup() {
  Serial.begin(9600);
  // Initialize the I2C bus (BH1750 library doesn't do this automatically)
  Wire.begin(D2,D1);
  // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);

  lightMeter.begin();
  Serial.println(F("BMP280 test"));
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
  }

}

  /**************************  
 *  L O O P
 **************************/
void loop() {

  uint16_t lux;

  // Wait for completion (blocking busy-wait delay)
  if (sensor.isConversionCompleted()) {
    // Read light
    lux = sensor.read();

    // Print light
    Serial.print(F("Light: "));
    Serial.print(lux);
    Serial.println(F(" LUX"));
  }
    Serial.print("T=");
    Serial.print(bme.readTemperature());
    Serial.print(" *C");

    Serial.print(" P=");
    Serial.print(bme.readPressure()/100);
    Serial.print(" hPa");

    Serial.print(" A= ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    //every 20 sec   
    delay(2000);
}

The BMP part is working fine.

  • i do have a combined script now, but it seems only the lux part is giving results. the BMP values are 0 – Sander Rozemuller Apr 28 '18 at 12:47
  • 1
    Then you'd need to edit the question to show us your current program. – Maximilian Gerhardt Apr 28 '18 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.