How connect si7021 and bh1750 to arduino mini pro



  • Dear All!

    I would like to connect my si7021 and bh1750 to the same arduino mini pro 5v. These use the I2C interaface, but i dont know how should wire it.
    After the wiring, how can I read the values both of them with mysensors sketch?

    Thank you for your help in advance!

    T.


  • Mod

    @Tommas wire both sensors to A4 and A5. Then use the respective libraries to communicate with the sensors. I2c is a bus that supports multiple devices.



  • @Tommas Hardware-wise, apart from the Vcc and GND pins, both I2C pins marked SDA and SCL should be connected to the I2C pins in the arduino (A4 and A5).

    Software-wise, each library should provide a "constructor" function which returns an object with which you can then read the measurements through the appropriate function. The I2C devices have an internal address which the libraries use to access the correct device through the bus.

    Most of the devices have their I2C adress hardcoded; some allow you to modify it e.g. to avoid conflicts with other devices or to allow connecting two equal devices to the same board. In this case, the constructor will need you to pass the adress as a parameter.

    I have no experience with those two sensors but I have a node with a light sensor similar to the bh1750 (tsl2591), and a temp/hum/baro sensor similar to the si7021 (bme280). Just to give you an idea, the constructor for the bme280 (using the Adafruit library) looks like:

    Adafruit_BME280 bme;
    

    and then the lines to read the measurements look like (in "forced measure" mode):

    bme.takeForcedMeasurement(); 
    temp=float(long(bme.readTemperature()*10))/10.0;  //round to 1 decimal place
    hum=(int) bme.readHumidity();                     //Humidity in domoticz is an integer
    baro=round(bme.readPressure()/100);               //Convert from Pa to hPa (mb) and round to 1 decimal place
    

    While for the TSL2591 the constructor and readings (in IR + visible mode) are like this:

    Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
    << more code >>
      uint32_t lum = tsl.getFullLuminosity();               //getFullLuminosity in the library already enables and disables the device
      uint16_t ir, full;
      ir = lum >> 16;
      full = lum & 0xFFFF;
      visible=tsl.calculateLux(full, ir);
    

    In addition to this, you may need to initialize the sensor, set some configuration... each library is different and therefore should provide documentation explaining how it works.


Log in to reply
 

Suggested Topics

  • 87
  • 5
  • 3
  • 5
  • 10
  • 8

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts