How to connect I2C at nodeMCU



  • Hey there,

    I use a nodeMCU as ESP8266 gateway and wanted to add a few sensors to it to avoid using a sensor node right next to the gateway. I first tried with a temp sensor Si7021. But how to connect it to? Vin and GND is obvious, but SDA and SCL...
    Somewhere I found to connect them to D1 and D2, but the NRF is already at D2 with its CE pin. Is it possible to define them freely to other GPIOs without interfering with MySensors lib? I though about using GPIO09 and 10, as they are free and near to my Si7021.



  • I found out some part via google, but still some trouble. Maybe someone can help:
    I have the SDA and SCL connected to GPIO9 and GPIO10 of my nodeMCU (labeled SD2 and SD3). When uploading my normal ESP8266OTA sketch everything works fine and gateway is running. I added the Wire.begin(9,10) at the beginning of setup to set the pins used for I2C.

    void setup() {
      Wire.begin(9, 10);
      //sensor.begin();
      ArduinoOTA.onStart([]() {
        Serial.println("ArduinoOTA start");
      });
      ArduinoOTA.onEnd([]() {
        Serial.println("\nArduinoOTA end");
      });
      ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
      });
      ArduinoOTA.onError([](ota_error_t error) {
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
        else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
        else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
        else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
        else if (error == OTA_END_ERROR) Serial.println("End Failed");
      });
      ArduinoOTA.begin();
      Serial.println("Ready");
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());
    
      //    if (!bmp.begin())
      //    {
      //      Serial.println("Could not find a valid BMP085 sensor, check wiring!");
      //      while (1) {}
      //    }
      //metric = getConfig().isMetric;
    

    But as soon as I enable the sensor.begin() or bmp.begin() it's not working anymore. I get resets with the following message in serial monitor:

     ×Åü1¤ñþ0;255;3;0;9;Starting gateway (RNNGE-, 2.0.0-beta)
    0;255;3;0;9;Radio init successful.
    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 5
    cnt 
    
    connected with WiFi, channel 1
    ip:192.168.38.19,mask:255.255.255.0,gw:192.168.38.1
    .IP: 192.168.38.19
    Ready
    IP address: 192.168.38.19
    ü!m!„þæÊõþ0;255;3;0;9;Starting gateway (RNNGE-, 2.0.0-beta)
    

    When using the BMP085test example sketch from the library I get

     ets Jan  8 2013,rst cause:4, boot mode:(3,7)
    
    wdt reset
    load 0x4010f000, len 1264, room 16 
    tail 0
    chksum 0x0f
    csum 0x0f
    ~ld
    

    Does anyone knows if that is a problem of incompatible library or any other hint how to solve?


Log in to reply
 

Suggested Topics

  • 87
  • 8
  • 9
  • 1
  • 7
  • 5

10
Online

11.2k
Users

11.1k
Topics

112.5k
Posts