Post topics, source code that relate to the Arduino Platform

User avatar
By AfromtheB
#74609 Hi all,

I've been looking around the web but couldn't find a solution to the issue I'm facing. What I'm trying to do is connect an I2C lcd display and an SD card reader to my Wemos D1 R2 board and get them both to work at the same time.
Wiring is as follows:
LCD <-> ESP
SDA -> D2 (SDA)
SCL -> D1 (SCL)

SD card reader <-> ESP
CS -> D8 (SS)
SCK -> D5 (SCK)
MOSI -> D7 (MOSI)
MISO -> D6 (MISO)

LCD is connected to 5V and SD card reader is connected to 3V3

When all wires are connected and I write a sketch to use the LCD display everything works fine. Another sketch that uses the SD card reader works as expected as well. But when I combine these sketches to use the display, read the card info and then display some other text the display stops responding (keeps original text) after initialising the sd card reader.

I've been looking into the SPI / SD library, but could not find any point where this library would interfere with the Wire library.

Anyone out there with a similar issue and/or possibly a solution?

Best regards,
AfromtheB

Code for the combined sketch is as follows:

Code: Select all// include the SD library:
#include <SPI.h>
#include <SD.h>

// include the wire and LCD I2C libraries:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int chipSelect = 4;

// set up variables using the SD utility library functions:
Sd2Card card;

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // initialize the LCD
  lcd.begin();
  lcd.clear();
  delay(2000);
  // Turn on the blacklight and print a message.
  lcd.backlight();
  lcd.print("Hello, world!");

  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed.");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  lcd.setCursor(0,3);
  lcd.print("Hello to you too!");
 
  Serial.println("Finished setup()");
}


void loop(void) {

}