Go Down

Topic: No display on lcd while logging on sd card (atmega 328+DS1307+LCD+SD+LM35) (Read 2 times) previous topic - next topic

polluxstyx

I am new user of arduino and I am using arduino with atmega 328, readings from LM35 and DS1307 will be outputed to a 16x2 LCD and at the same time to log the data( datetime+temp reading), the problem that I encountered is that I am unable to the ( datetime+temp reading) to the LCD display, as part of the troubleshooting to check if LCD is working...I disable the all the sketch that have something to do with the sd card logging by putting //...... then the LCD works perfectly without the SD logging.

The LCD connection:                                         The RTC connection:
* LCD RS pin to digital pin 12                              *RTC clock to analog pin 5
* LCD Enable pin to digital pin 11                       *RTC clock to analog pin 4
* 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

The SD connection:                                           The LM 35 connection:
*SD CLK to digital pin 13                                      *LM35 to analog pin 0
*SD DO to digital pin 12
*SD DI to  digitalpin 11
*SD CS to  digitalpin 10


this is my sketch:


#include <LiquidCrystal.h>
#include <SD.h>
#include <Wire.h>
#include <DS1307.h>


const int chipSelect = 4;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pin = 0; // analog pin
int tempc = 0; // temperature variable
char dateTime[20];
int RTCValues[7];


void setup()
{
  Serial.begin(9600);
      DS1307.begin();
      lcd.begin(16, 2);
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
 
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    return;
  }
Serial.println("card initialized.");
File dataFile = SD.open("datalog.csv", FILE_WRITE);
dataFile.print("DATE");
dataFile.print(",");
dataFile.print("TEMP");
dataFile.println(",");

  } 


void loop()
{
  tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
 
  DS1307.getDate(RTCValues);
 
 
 
   lcd.setCursor(0, 0);
   sprintf(dateTime, "20%02d-%02d-%02d ", RTCValues[0],
            RTCValues[1], RTCValues[2]);
   lcd.print(dateTime);   
   lcd.setCursor(0, 1);
   sprintf(dateTime, "%02d:%02d:%02d", RTCValues[4], RTCValues[5],
           RTCValues[6]);
   lcd.print(dateTime);


 
  lcd.setCursor(11, 1);
  lcd.print(tempc); 
  lcd.setCursor(13, 1);
  lcd.print((char)223);
  lcd.setCursor(14, 1);
  lcd.print("C");

   
  String dataString = "";
 
  File dataFile = SD.open("datalog.csv", FILE_WRITE);

      sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d", RTCValues[0],
            RTCValues[1], RTCValues[2], RTCValues[4], RTCValues[5],
            RTCValues[6]);
   
    dataString += String(dateTime);
    dataFile.print(dataString);
    dataFile.print(",");
    dataFile.println(tempc);
    dataFile.close();

Serial.print(dataString);
Serial.print("------>");
Serial.println(tempc,DEC);
  delay(5000);
   
}

cyclegadget


  There may be more than one problem but, here is one that will stop you in your tracks.

You state your CS chip select pin for the SD card is 10.
Code: [Select]
*SD CS to  digitalpin 10

However, here you define the chipselect pin as 4.
Code: [Select]
const int chipSelect = 4;

If you continue to have problems post your next results.

polluxstyx

@cyclegadget

Sorry for the mistake, I stated before that *SD CS to  digitalpin 10, actually it is connected to digital pin 4, I run the arduino SD test sketch below and it successfully create a log data, this means that const int chipSelect = 4; is ok to use. I also tried to change it to const int chipSelect = 10; but the result is
---->SD card failed to initialize.

I also suspected the LCD connection which is LiquidCrystal lcd(12, 11, 5, 4, 3, 2); there might be conflict to the digital pin 4, I tried to change the declaration to LiquidCrystal lcd(12, 11, 6, 5, 3, 2);
and change the LCD pin connection on the hardware but the same problem still exist, the LCD screen was filled with #3's,
the LCD screen outputs like this.....

3333333333333333
3333333333333333



#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
 
  // make a string for assembling the data to log:
  String dataString = "Hello World";
 
  // 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 dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println("Hello World");
    dataFile.close();
    // print to the serial port too:
//    Serial.println(dataString);
  } 
  // if the file isn't open, pop up an error:
//  else {
//    Serial.println("error opening datalog.txt");
//  }

}

void loop()
{
}

cyclegadget


Your SPI pins are 10,11,12,13 and 4 for your SD card. You need A4 and A5 for your DS1307.

I would recommend using what you have left for the LCD so that you do not interfere with the SPI pins.

polluxstyx

@cyclegadget


I already connected DS1307 to A4 and A5, I also tried your reccomendation but the problem still exist, the LCD was filled with 3's characters

cyclegadget


I am not sure what to do next but, one idea would be to comment out all of your lcd.print lines except one. One the one you keep have it print "Hello" and see if the LCD changes result.

If it is not a programming error, I am at a loss.

SurferTim

Quote
I already connected DS1307 to A4 and A5, I also tried your reccomendation but the problem still exist, the LCD was filled with 3's characters


Did you move the LCD connections so they are not connected to digital pins 10-13? What pins are you using now?


robot797

control the lcd with 595's  that you only need 3 wires
that way you can choose what 3 pins you want to use and you can piggyback 128 595's


aicanduit

LiquidCrystal lcd(12, 11, 6, 5, 3, 2);

I think LCD DX must be consecutive.

Can you try with this configuration : ?

The LCD connection:     
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9                 
* LCD D4 pin to digital pin 7
* LCD D5 pin to digital pin 6
* LCD D6 pin to digital pin 5
* LCD D7 pin to digital pin 4

The SD connection:             
*SD CLK to digital pin 13     
*SD DO to digital pin 12
*SD DI to  digitalpin 11
*SD CS to  digitalpin 10

So, use:
LiquidCrystal lcd(8, 9, 7, 6, 5, 4, 3);

and:

const int chipSelect = 10;



Regards.

Go Up