NodeMCU multiple i2c dont working.

Hello guys;
I’m new in this module. I’m working a project. I try so many ways but i can’t do anything. Can u help me?
The project is Data Logger. I have sd card module,rtc ds 1307, mcp9808(i2c temp) and 16x2 lcd.
I want to do run together. I can do in arduino but i can’t do in nodemcu.

The problem is how can i run i2c modules together. Sometimes one module working and other modules not working.

My code;
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10 (for Adafruit Feather 32u4)

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include “RTClib.h”
#include “Adafruit_MCP9808.h”
#include <LiquidCrystal_PCF8574.h>

RTC_DS1307 RTC; // define the Real Time Clock object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808(); // define the MCP9808 object
LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

const int chipSelect = 10;
File logfile;
int show;

void setup() {
int error;
// Open serial communications and wait for port to open:

while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
Serial.println(“Dose: check for LCD”);

// See
Wire.begin(D3, D4);
error = Wire.endTransmission();
Serial.print("Error: ");

if (error == 0) {
Serial.println(": LCD found.");

} else {
Serial.println(": LCD not found.");
} // if

lcd.begin(16, 2); // initialize the lcd
show = 0;
Serial.print("SD Kart Yükleniyor… ");

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Kart Hatası”);
// don’t do anything more:
Serial.println(“Kart Yüklendi.”);

// Open the file to write the .csv legends.
logfile =“data.txt”, FILE_WRITE);
logfile.println(“Tarih/Saat, Sıcaklık (°C,°F)”);
Wire.begin(D1, D2);
if (!tempsensor.begin(0x18)) {
Serial.println(“Sıcaklık Sensörü Algılanamadı”);
while (1);

// connect to RTC
Wire.begin(D3, D4);
if (!RTC.begin()) {
logfile.println(“Zaman Sensörü Algılanamadı”);

RTC.adjust(DateTime(F(DATE), F(TIME)));

void loop() {

if (show == 0)
lcd.home(); lcd.clear();

// fetch the time
DateTime now =;
// get the temperature
float c = tempsensor.readTempC();
float f = tempsensor.readTempF();
// set up buffer for date and time
char dateBuffer[100];

// Open the file. Note that only one file can be open at a time,
// so you have to close this one before opening another.
File logfile =“data.txt”, FILE_WRITE);

if (logfile) {
sprintf(dateBuffer, “%02d-%02d-%02d %02d:%02d:%02d, “,, now.month(), now.year(), now.hour(), now.minute(), now.second());

logfile.print(c, 3); logfile.print("°C\t ve ");
logfile.print(f, 3); logfile.println(“°F.”);

Serial.print(c, 3); Serial.print("°C\t ve ");
Serial.print(f, 3); Serial.println(“°F.”);

lcd.setCursor(10, 0);
lcd.print((char)223); // degrees character
lcd.setCursor(10, 1);
lcd.print((char)223); // degrees character
lcd.setCursor(0, 0);
lcd.print(, DEC);
lcd.print(now.month(), DEC);
lcd.print(now.year(), DEC);
lcd.setCursor(0, 1);
if (now.hour() < 10) lcd.print(“0”); // add zero
lcd.print(now.hour(), DEC); // Print hour
if (now.minute() < 10) lcd.print(“0”); // add zero
lcd.print(now.minute(), DEC); // Print minute
if (now.second() < 10) lcd.print(“0”); // add zero
lcd.print(now.second(), DEC); // Print second

else {
Serial.println(“Data Açma Hatası”);

} }

When you connect all the I2C devices and run the I2C scanner sketch, what is returned in serial monitor?

A schematic of the project can be helpful.

Read the how to use this forum-please read stickies to see how to properly post code and some advice on how to get the most from the forum.