Go Down

Topic: LCD line 1 wont display when SDcard not inserted (Read 1 time) previous topic - next topic


just thought i'd post this as it caused me some headscratching on one of my current projects after putting all the sections of project together and happy with the fact it all worked on the bench (atmega328 & LCD @ ett sdcard mini board @ sensors) and just tweaking the sketch here and there

next i pulled out the sdcard to read it on excel, came back kept tweaking etc ( NO sdcard inserted ) and found that line 1 of my LCD  didnt work anymore.... and the headscratching began :~

so i tested everything just about

arduino boards, lcds, new lcd code (just to test the lcd) lcd worked fine back to the project still no line 1 on LCD

walked away muttering @#$@%@# :0

came back 'ohh i better put that SDcard back in before i lose it or the kids steal it'

so i put the SDcard back in and line 1 on LCD started working again! :smiley-surprise:

hope this curious little problem helps someone out sometime :)


What type of LCD and how is it connected to arduino?
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


Have you considered the possibility that you have connected something incorrectly or that there is some problem with your code and the difference in function of the LCD in the presence or absence of the SD card is a result of this discrepancy?



@ liudr

lcd is stock Standard HD44780 LCD chipset type (16x2)(ive got 4 or 5 different brands and they all did the same thing)

and connected (parallel interface) as per any of the tutorials about the arduino  (ie it worked fine in the tutorials and i didnt change anything when i came to do my project)

@ floresta
i thought i might have connected (or disconnected something by accident) so i pulled it all apart and put it back together section by section and tested as i went along and worked fine till i got to hook up the sdcard board (with no card) and there it was again, put the card in and it worked (put card in /out a few times and same problem)

i did some googling but nothing came up that i could find as per same or similar issue, so i posted it, so that it might help someone else , could work on code a bit more maybe but going over my head to sort out as a newbie and first project (so i'll leave it for now)

but it all works now so im happy.... only time sdcard will be out is when a new one going in and that wont cause me any problems

im addicted to arduino now, cant stop thinking of things i could do, project 4 lookout!


Dec 23, 2011, 03:16 pm Last Edit: Dec 23, 2011, 07:14 pm by floresta Reason: 1
but it all works now so im happy

You shouldn't be happy.  You have not resolved the source of your malfunction, and it is a malfunction, so you never know when it or a related one might crop up again.

...so that it might help someone else...

How could this possibly help someone else when they have no idea what you have done.  You have not specified which pins you are using for your LCD interface, you have not specified anything about your SD card interface, and we have no idea of the program code.

... but going over my head to sort out as a newbie ...

We are not newbies but we can't sort out the unknown.



I hunch is pin conflict. You said you used a typical tutorial code so what are the pins in the LiquidCr
ystal LCD command? What is the link to the ad card shield so we can read it? Like florets said you didn't solve any problem so you should not be happy. Knowing how to do things with arduino requires fixing problems you encounter.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


ok here you go  (error being only time lcd not display on line 1 is when sdcard not inserted)

sdcard from here http://futurlec.com/Mini_SC.shtml datasheet attached

arduino brd     atmega 238             ett card pins     sd desc
10                     16                   ss           1          cd/dat3
11                     17                  mosi          2           cmd
12                     18                  miso          7            dat0
13                     19                  sck           5            clk
3.3vdc                             vcc 3.3v           4         vcc 3.3v
gnd             22 & 8               gnd          3 & 6           gnd

lcd(4, 5, 6, 7, 8, 9); // changed these pin to suit SD card

Code: [Select]
// water_meter_v1.3
// 17-12-2011
// changed LCD pin to allow for SD card use and changed toggle sw pins
// added RTC to serial monitor
// added sd logging  date/time/house/block/tank
// added **** CHANGEOVER ****
int calpulse = 240; // pulses calibration is 240 .....24 for testing
int pulsePin = 2;  // water meter pulse pin 2
unsigned long highCounter = 0;
unsigned long duration = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long timeNow = 0;
unsigned long lastTime = 0;
int pulscount = 0;
unsigned long litre = 0;
unsigned long klitre = 25000;  // 25 for testing normal 25k-30k
int pulcunt = 0;
const int meterhouse = 14;// the number of toggle pin14 is analogue 0
const int meterblock = 3;// the number of toggle pin
// ************************
unsigned long housecount = 536464;
unsigned long blockcount = 675797;
unsigned long tankcount = 0;

// variables will change:
int houseState = 0;         // variable for reading the toggle status
int blockState = 0;
int tankState = 0;
// ***********************************
// Global Variables

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
  return ( (val/10*16) + (val%10) );
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
  return ( (val/16*10) + (val%16) );

// ***********************
#include <SD.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address

File myFile;

#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 5, 6, 7, 8, 9); // changed these pin to suit SD card

void setup() {
   pinMode(pulsePin, INPUT);
  // enable the 20K pull-up resistor to
  // steer the input pin to a HIGH reading.
   digitalWrite(pulsePin, HIGH);
  // *******************
  // initialize the toggle pin as an input:
   pinMode(meterhouse, INPUT);
  // initialize the toggle pin as an input:
   pinMode(meterblock, INPUT);
  // ********************

   Serial.println("Water Meter - Version 1.3");
   Serial.println("Initializing SD card...");
   pinMode(10, OUTPUT);

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");
  // *****************************************************************
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Water Meter ");
  lcd.setCursor(0, 1);
  lcd.print("ver 1.3");

void loop() {
  // get data and print it to serial monitor
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) { // pulse has changed
    timeNow = millis();
    duration = timeNow - lastTime;
    pulscount = pulse + pulscount;
    pulcunt = pulscount;
    if ( pulcunt>=calpulse ) {//litre = litre++; //every 240 pulses is 1 litre increment count
    pulscount = 0; // reset counter
    //Serial.print(pulscount);    //uncomment for calibration of calpulse
    //Serial.print(", ");         //   ditto
    //Serial.println(litre);      //   ditto
    // read the state of the toggle switch value:
  houseState = digitalRead(meterhouse);
  blockState = digitalRead(meterblock);
  // check if the toggle switch is changed
  // if it is, the buttonState is HIGH:
  if (houseState == HIGH) {     
      Serial.println("House ON, "); 
      if (pulcunt>=calpulse) { housecount = housecount++;
        Serial.print(housecount); // did have ln
        printdatetime();           // ##################################
        lcd.print("House Use(L)");
        lcd.setCursor(0, 1);
  // ******************************************
  if (blockState == HIGH) {
      Serial.println("Block ON, ");
      if (pulcunt>=calpulse)   { blockcount = blockcount++;
        lcd.print("Block Use(L)");
        lcd.setCursor(0, 1);
  if (houseState == LOW && blockState == LOW) {
      Serial.println("Tank ON, "); 
      if (pulcunt>=calpulse) {tankcount = tankcount++;
       lcd.print("Tank Use(L)");   
       lcd.setCursor(0, 1);
       //changeover();  // not needed here
    lastPulse = pulse;
    lastTime = timeNow;
    if (pulse == HIGH) highCounter++;

// ds1307 stuff
// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
  // Reset the register pointer

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  second     = bcdToDec(Wire.receive() & 0x7f);
  minute     = bcdToDec(Wire.receive());
  hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());

void printdatetime()
// display time date to serial monitor
  Serial.print(" ");
  Serial.print(hour, DEC);
  if (minute<10) {
    Serial.print("0"); // add a leading zero if minute <10
  Serial.print(minute, DEC);
  if (second<10) {
    Serial.print("0"); // add a leading zero if second <10
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(dayOfMonth, DEC);
  Serial.print(month, DEC);
  Serial.println(year, DEC);

void logtosdcard()
myFile = SD.open("h2olog.csv", FILE_WRITE);
  if (myFile) {
    myFile.print(dayOfMonth, DEC);
    myFile.print(month, DEC);
    myFile.print(year, DEC);
      if (hour<10) {
    myFile.print("0"); // add a leading zero if hour <10
    myFile.print(hour, DEC);
      if (minute<10) {
    myFile.print("0"); // add a leading zero if minute <10
    myFile.print(minute, DEC);
      if (second<10) {
    myFile.print("0"); // add a leading zero if second <10
    // close the file:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening h2olog.csv");

void changeover()
litre = litre++;
        if (litre >= klitre) {
          Serial.println("*** CHANGEOVER ***");
          lcd.setCursor(9, 1);
          lcd.print("CHANGE ");
           litre = 0;


My guess is that somehow the ChipDetect pin from the SD is also connected/shorted/shared to some part of the LCD display and when the card isn't inserted the CD pin goes low and grounds something. When the card is in, CD is high and all is well.

Don't send me technical questions via Private Message.


thanks in advance for what you can sort out from the above and hope i've included everything you may need

and i am sorry if my coding is somewhat lacking in finese

toggle sw (on/centre off/on) connect to pins dig3 and dig14(anal 0)
flow sensor is this http://www.futurlec.com/Flow_Sensor.shtml connected to dig 2

ds1307 connected to analogue 4&5

basically works like this - toggle sw selects between 2 mains water meters & rain watertank, monitors litres used from each source displays on lcd, logs to sdcard, and gives a (changeover)warning every 25Klitres of water when on mains supply ( so i get to pay the cheap{cough cough} water rates

Go Up