Forum >Replies by onur-karaagac
userhead onur-karaagac
Replies (5)
  • You Reply:
    paul.jeffress wrote:
    Fri Apr 02, 2021 4:01 am
    Hi,
    I too have had an issue trying to use SEN0390 with another I2C device, SEN0385 (SHT31 temp + humidity). Here is what I found and noted for future reference.
    ---------------------------
    I ran the i2c_scanner (with both sensors connected to my M4’s SDA/SCL) and confirmed the SHT31 is by default on 0x44 and the Ambient Light is 0x4A. So that’s all cool.

    I have got my project working though and it was two issues that needed to be addressed, and they are somewhat related.

    1. Typos in the DFRobot Library
    I too had another look at the DFRobot library for the Ambient Light Sensor (GitHub - DFRobot/DFRobot_B_LUX_V30B) and noticed a couple of errors in their code.In that library in DFRobot_B_LUX_V30B.cpp they seem to very manually toggle or bit bang the I2C protocol onto the pins. Seems odd but anyway, in two of the functions they incorrectly reference the pins, they use “SDA” instead of “_SDA”, so they are messing with pins referenced outside their library. So to fix that you need to change any instance of “SDA” in their library to “_SDA”.This alone did not fix the issue, see item 2 below.
    2. Keep the Ambient Light Sensor on dedicated SDA/SCL pins
    The DFRobot library has the ability to let the user specify which pins are used for SDA and SCL (as it seems intent on bit banging the I2C Proto).For example you can tell it to use pin 6 for SCL and pin 5 for SDA with the following (ignore the 13 for now)DFRobot_B_LUX_V30B myLux(13,6,5);If you do that, and wire it there appropriately, then everything works. I can read from the SHT31 and the Ambient light sensor in the same sketch. I’m sure just a better library for the Ambient Light Sensor would allow it to coexist on the main I2C but that’s beyond my skill level.
    Thanks,Paul
    Note: I have the Ambient Light Sensors SDA and SCL connected to pins 5 & 6 respectively on my Feather M4 now, and have the SHT31 still using the built in SDA/SCL pins.
    Thank you. Your suggestion worked.
  • You Reply: I removed all other parts from arduino and I run the example code. Sensor started to reading. after that I added 16x2 i2C lcd screen to arduino. but sensor value returned to "-1" again. even I removed the cables of LCD sensor value did not changed. I think reason is about i2C communication. because when i added just any library ehich uses i2C connection sensor value chances to "-1".

    here is code

    #include <DFRobot_B_LUX_V30B.h>
    DFRobot_B_LUX_V30B myLux(13);

    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 16, 2);

    void setup() {
    Serial.begin(9600);
    myLux.begin();
    lcd.init();
    lcd.begin(16, 2);
    lcd.backlight();
    }

    void loop() {
    Serial.print("value: ");
    Serial.print(myLux.lightStrengthLux());
    Serial.println(" (lux).");
    delay(1000);
    lcd.setCursor(0, 0);
    lcd.print("Lux :");
    lcd.print(myLux.lightStrengthLux(), 2);
    delay(2000);
    }
  • You Reply: I think the problem is 13 pin because the datalogger uses 13(SCK) pin. The Ambient Light Sensor chip is set to 13 pins, SCL and SDA adopt default configuration.
    DFRobot_B_LUX_V30B myLux(13), i am changing 13 here but the problem is not solved. if this is the problem how can it be fixed?

    Also, I realized that when I run the Wire.begin(); command, the Ambient Light sensor does not operate.
  • You Reply: when you run

    08:32:18.856 -> Initializing SD card...card initialized.
    08:32:19.828 -> value: -1.00 (lux).
    08:32:20.847 -> value: -1.00 (lux).
    08:32:21.870 -> value: -1.00 (lux).
    08:32:22.850 -> value: -1.00 (lux).
  • You Reply: //------------------------------------------------------------------------RTC--------------------
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include "RTClib.h"

    RTC_DS1307 rtc;
    char daysOfTheWeek[7][12] = {"Pzr", "Pzt", "Sal", "Car", "Per", "Cum", "Cts"};

    // On the Ethernet Shield, CS is pin 4. Note that even if it's not
    // used as the CS pin, the hardware CS pin (10 on most Arduino boards,
    // 53 on the Mega) must be left as an output or the SD library
    // functions will not work.

    const int chipSelect = 10; //specific to Arduino UNO

    DateTime now;
    File dataFile;
    //-----------------------------------------------------------------------------------------------

    #include <DFRobot_B_LUX_V30B.h>
    DFRobot_B_LUX_V30B myLux(13);//The sensor chip is set to 13 pins, SCL and SDA adopt default configuration


    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    myLux.begin();

    //----------------------------------------------------RTC----------------------------------------
    Wire.begin();
    rtc.begin();
    if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // uncomment it & upload to set the time, date and start run the RTC!
    rtc.adjust(DateTime(__DATE__, __TIME__));
    }

    //-----------------------------------------------------------------------------------------------
    //-------------------------------------------------------DATALOG---------------------------------
    Serial.print("Initializing SD card...");
    // make sure that the default chip select pin is set to
    // output, even if you don't use it:
    pinMode(chipSelect, OUTPUT);

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
    }
    Serial.println("card initialized.");
    // Open up the file we're going to log to!
    dataFile = SD.open("datalog.txt", FILE_WRITE);
    // will create the file if it doesn't exist
    if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we can't write data
    while (1) ;
    }


    //-----------------------------------------------------------------------------------------------

    //----------------------------------------------------RTC----------------------------------------
    now = rtc.now();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1); // Wait forever since we can't log timestamp
    }
    //-----------------------------------------------------------------------------------------------

    }

    void loop() {
    now = rtc.now();


    dataFile.print(now.year(), DEC);
    dataFile.print('/');
    dataFile.print(now.month(), DEC);
    dataFile.print('/');
    dataFile.print(now.day(), DEC);
    dataFile.print(" (");
    dataFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
    dataFile.print(") ");
    dataFile.print(now.hour(), DEC);
    dataFile.print(':');
    dataFile.print(now.minute(), DEC);
    dataFile.print(")");
    dataFile.print(now.second(), DEC);

    dataFile.print("*Lux:*");
    dataFile.print(myLux.lightStrengthLux(), 1);




    dataFile.close ();
    dataFile.flush();



    // put your main code here, to run repeatedly:
    Serial.print("value: ");
    Serial.print(myLux.lightStrengthLux());
    Serial.println(" (lux).");
    delay(1000);
    }