-->
Page 1 of 1

Is there a conflict between I2C and ESP8266WiFi, PubSubClien

PostPosted: Wed Jul 24, 2019 9:05 am
by AverageGuy
I can't get it on one line. I'm running an MQTT client on an ESP8266 with some relays and sensors. I have a TSL2561 light detector that runs stand alone fine, however, if I integrate it with my MQTT app, it returns an invalid number. From the info call:
Code: Select all------------------------------------
Sensor:       TSL2561
Driver Ver:   1
Unique ID:    12345
Max Value:    17000.00 lux
Min Value:    1.00 lux
Resolution:   1.00 lux
------------------------------------

------------------------------------
Gain:         Auto
Timing:       13 ms
------------------------------------

but the output from the
Code: Select all        sensors_event_t event;
        tsl.getEvent(&event);

        /* Display the results (light is measured in lux) */
        if (event.light)
        {
            Serial.print(event.light); Serial.println(" lux");
            lastLight=event.light;
        }

is
65536.00 lux

Since the I2C is bit-banged, I'm wondering if an interrupt from the web activity is interfering in reading the sensor? The test sketch for the light sensor runs with a few modifications without fail.
Code: Select allLight Sensor Test

D4 and D3 2 0
------------------------------------
Sensor:       TSL2561
Driver Ver:   1
Unique ID:    12345
Max Value:    17000.00 lux
Min Value:    1.00 lux
Resolution:   1.00 lux
------------------------------------

------------------------------------
Gain:         Auto
Timing:       13 ms
------------------------------------

78.00 lux
77.00 lux
77.00 lux
75.00 lux
75.00 lux
75.00 lux

I copied the relevant code from the test sketch into my MQTT sketch.

Any ideas?
Thanks,
Jim.

Re: Is there a conflict between I2C and ESP8266WiFi, PubSubC

PostPosted: Sat Jul 27, 2019 10:43 am
by AverageGuy
I discovered that the sensor read started failing after this line of code:
Code: Select all    WiFi.begin((char*)ssid, wifi_password);
 


Does I2c not work with wifi? Or is wifi secretly using D3 and/or D4 ports?
Here's the code:
Code: Select allTwoWire newWire = TwoWire();
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
...
float getLight(Adafruit_TSL2561_Unified tsl)
{
        unsigned long lastLight=0;
        for(int i=0;i<5;++i) {
            sensors_event_t event;
            tsl.getEvent(&event);

            /* Display the results (light is measured in lux) */
            if (event.light)
            {
                Serial.print(event.light); Serial.println(" lux");
                lastLight=event.light;
            }
            else
            {
                /* If event.light = 0 lux the sensor is probably saturated
                   and no reliable data could be generated! */
                Serial.println("Sensor overload");
            }

            char lightOut[8];
            sprintf(lightOut,"%ld",lastLight);
            Serial.print("Light ");
            Serial.println(lightOut);
            delay(2000);
        }
}
...
void setup() {
    Serial.begin(115200);
    newWire.begin(D4,D3);
    if(!tsl.begin(&newWire))
    {
        /* There was a problem detecting the TSL2561 ... check your connections */
        Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
        //while(1);
    } else {
        /* Display some basic information on this sensor */
        displaySensorDetails();

        /* Setup the sensor gain and integration time */
        configureSensor();
        getLight(tsl);
        delay(2000);


    }


Jim.