0
\$\begingroup\$

My ESP8266-01 recognises the sensor TSL2561, but the readings always output 65535 for some weird reason. But as I said, when I run the I2C scanner and plug in the wire I see the sensor popping up at 0x39.

When I hook up the same sensor to an ESP8266 NodeMCU breakout and flash the same code on there it reads it out just fine. I have the wires connected as shown below without any resistors or anything in between.

| ESP8266-01 | TSL25611   |
|------------|------------|
| VCC (3.3V) | VCC (3.3V) |
| GND        | GND        |
| GPIO2      | SCL        |
| GPIO0      | SDA        |

I'm not sure what I'm doing wrong though.

My code:

#include <Wire.h>
#include <ESP8266WebServer.h>
#include <TSL2561.h>

const char *ssid = "Wouter's Place";
const char *password = "";

ESP8266WebServer server(80);
TSL2561 tsl2561(TSL2561_ADDR_FLOAT);

void handleRoot() {
  // Read illuminance
  float visible = tsl2561.getLuminosity(TSL2561_VISIBLE);
  float full = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM);
  float ir = tsl2561.getLuminosity(TSL2561_INFRARED);

  String response = "";
  response += "{\"illuminance\":{";
  response += "\"visible\":";
  response += visible;
  response += ",\"full\":";
  response += full;
  response += ",\"ir\":";
  response += ir;
  response += "}";
  response += "}";

  server.send(200, "application/json", response);
}

void setup(void)
{
  Wire.begin(0, 2);

  Serial.begin(9600);
  Serial.println();

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);

  Serial.print("Connecting to: ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(250);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected to wifi, ip: ");
  Serial.println(WiFi.localIP());

  Serial.println("Setting up TSL2561..");
  if (!tsl2561.begin())
  {
    Serial.println("Could not find TSL2561 sensor, check wiring!");
    while (1);
  }

  Serial.println("Starting server..");
  server.on("/", handleRoot);
  server.begin();
  Serial.println("Web server running!");
}

void loop()
{
  server.handleClient();
}

Resulting output:

{
  "illuminance": 
  {
    "visible": 0,
    "full": 65535
    "ir": 65535
  }
}
\$\endgroup\$
  • \$\begingroup\$ Can you post a schematic? I can't tell what you've hooked up in your video. \$\endgroup\$ – KingDuken Jan 28 at 19:59
  • \$\begingroup\$ please post the code, not a link to the code \$\endgroup\$ – jsotola Jan 28 at 20:06
  • \$\begingroup\$ Just to comment 65536 is 16 bits of all ones. Since the I2C data line idles high, this probably means the slave isn’t responding. \$\endgroup\$ – DoxyLover Jan 29 at 0:16
  • \$\begingroup\$ @DoxyLover thanks, after reading above I started thinking about it and went another time through my code only to find a quite obvious bug. \$\endgroup\$ – wouterds Jan 30 at 15:14
1
\$\begingroup\$

Found the bug after thinking a bit about what @DoxyLover mentioned! Those 2 lines of leftover code shouldn't be here. Apparently the default LED on the ESP-01 is GPIO2 (which is one of the I2C pins I'm using).

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.