interface both the SD CARD MODULE and LCD display to arduino ?

Hello Friends,

First, I'm a newbie to arduino so any help is highly appreciated ! :slight_smile:

My project is a simple voltage / current monitor device with ACS 758 sensor . Basically the sensed voltage / current is to be shown in a 16x2 LCD . Also making a data log into a SD card is essential .

I tested the circuit with ONLY with the SD CARD MODULE and another time ONLY with the LCD MODULE . BOTH WORKED . But i haven't tried connecting both at same time as I have a problem .

So I have the LCD and SD CARD MODULE ; but my problem is both modules use the same pins ( pin 11, pin 12, pin 4 ) ?

Please help me to proceed .

Many Thanks,
Dileesha.

According to arduino site, the pin configuration for LCD is as below ,

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

LINK : http://arduino.cc/en/Tutorial/LiquidCrystal

According to SD CARD MODULE site, the pin configuration for SDCARD MODULE is as below ,

MODULE PINOUT:

PIN 1: GND ---> Arduino GND
PIN 2: +3.3V ---> Arduino 3V
PIN 3: +5V ---> Arduino 5V
PIN 4: CS ---> Arduino DIO 4
PIN 5: MOSI ---> Arduino DIO 11
PIN 6: SCLK ---> Arduino DIO 13
PIN 7: MISO ---> Arduino DIO 12
PIN 8: GND ---> N/A

You may copy, alter and reuse this code in any way you like but please leave
reference to HobbyComponents.com in your comments if you redistribute this code. */

LINK : Official Hobby Components Online Store | Buy Electronic Kits, Components, Boards, Shields, Modules

As the SD card needs the SPI, can you move the LCD to other pins, do you have a shield or wires?

I'm sure the LCD code can be modified to change the pins ( unless its SPI also ).

EDIT: Just had a look at the LiquidCrystal library, the pins are set in the constructor so it should be an easy fix if you have spare pins ( and aren't using a shield )

You only need to change pins 4, 11, and 12 according to your pinout lists.

@pYro_65

Many thanks for your idea sir .

First i must say, I'm using wires to connect the LCD to arduino ; and I use 4 bit mode . And it's a normal 16x2 LCD DISPLAY so I think it doesn't use that SPI thing.
( LMB162AFC / datasheet here http://www.datasheet.co.kr/datasheet-html/L/M/B/LMB162AFC-2_Shenzhen.pdf.html )

I'm a newbie to arduino and coding, could you please tell me how to edit the library file in the appropriate way ?

  1. what file i should edit ? .h file or what ?
  2. can i edit it using text editor or arduino IDE ?
  3. should i only change the pins to some other pins ?

Thanks,
Dileesha.

SOLVED ! :slight_smile:

It was really a simple edit I needed to do, but of course I figured that out after the explanation by @pYro_65 . So thank goes to him .

If there are newbies like me looking for help on this ; what i did was , :smiley:

SD CARD MODULE USES below pins and I think we should not change them .

PIN 1: GND ---> Arduino GND
PIN 2: +3.3V ---> Arduino 3V
PIN 3: +5V ---> Arduino 5V
PIN 4: CS ---> Arduino DIO 4
PIN 5: MOSI ---> Arduino DIO 11
PIN 6: SCLK ---> Arduino DIO 13
PIN 7: MISO ---> Arduino DIO 12
PIN 8: GND ---> N/A

And the LCD uses below pins and what I did was I changed them .

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

PROBLEM WAS : both uses pin 4, pin 11, pin 12 same time .

SOLUTION : edit liquid crystal example in arduino IDE .

/*
LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD
and shows the time.

The circuit:

  • LCD RS pin to digital pin 12 // :wink: change this to any digital pin you have left with no connection ; i used pin 8
  • LCD Enable pin to digital pin 11 // :wink: change this to any digital pin you have left with no connection ; i used pin 7
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4 // :wink: change this to any digital pin you have left with no connection ; i used pin 6
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // :wink: then also change the " 12 " , " 11 " , " 4 " to the pin numbers you've given ; mine is(8, 7, 5, 6, 3, 2)

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

That's all . It worked !

Thanks,
Dileesha.

Good post, Leaving the fix is nice. I'm sure someone will eventually find this thread looking for the same answer.

Great! This resolved my problem.
Tanks!!!

Thank you for posting your fix - I've tried to figure out wether I could change the digital pins of the LCD on Arduino for a while. Now I'm certain :slight_smile:

Thank you so much for posting your solution.

thank you so much for posting. .

Solution is ok if you have enough pins left to be used.
If you are running out of pins another solution would be to mount an I2C backpack onto the lcd display. I2C needs only 2 wires (SCA and SCK) which use pins A4 and A5 on an UNO/Nano.

Each I2C device comes with its own unique address, so you can hook a lot of more I2C devices in parallel, using only 2 dedicated I/O pins in total.

awesome! It solved my problem too Dileesha.

You Rock! tks!

Hi!

I've done Dileesha's solution of changing the LCD pins but my SD card still doesn't work. Are there other solutions for this?

ksan0626: you have provided no information for us to work with. no pin number assignment list, no code. we don't do ESP and we don't do miracles.

SPI requires 4 pins:
MISO
MOSI
SCK
CS

MISO, MOSI & SCK are busses: they are shared by all SPI devices. one Arduino pin can service more than one module
CS, Chip Select, is: 1 card, 1 pin. if you have more than one SPI device, each one gets its own CS pin
that CS pin is set up as a constant at the start of the program:

const int chipSelect =10;

and set to OUTPUT in void setup()

pinMode(chipSelect, OUTPUT);

If you have more than one SPI device you must assign each device one CS pin:

const int SDchipSelect=10;
const int LCDchipSelect=17;

and both must be set to output in void setup()

pinMode(SDchipSelect, OUTPUT);
pinMode(LCDchipSelect,OUTPUT);