LCD and SD module wont work together please help fix??? ASAP


im making project collect data , print both on lcd , sd card. im using sparkfun sd module , standard lcd 16x2 screen comes along starter kit

when power arduino uno following code "welcome" message shows on screen not rest of information supposed printed in void loop() function!!

this code

code: [select]
#include <sd.h>
#include <liquidcrystal.h>

liquidcrystal lcd(12, 11, 5, 4, 3, 2);

const int chipselect = 8;  //set variables
const int buttonpin = 7;
const int piezopin = 9;
long duration;
long duration2;
long durationmicros;
long time1;
long time2;
long elapse;
int buttonpushcounter = 0;
int buttonstate = 0;
int lastbuttonstate = 0;
int steps = 0;

void setup(){
  
  serial.begin(9600);
  lcd.begin(16 , 2);
  pinmode(buttonpin , input);
  pinmode(piezopin ,output);
  pinmode(10 , output);
  lcd.print("welcome");
  delay(1000);
  lcd.clear();
  
  serial.println("initializing sd card.....");
  
  if(!sd.begin(chipselect)){ // check sd card present
    
    serial.println("card failed or not present");
    return;
  }
    serial.println("card initialized");
    sd.mkdir("datalog.csv"); // create file named datalog.csv
    
    if(sd.exists("datalog.csv")== true){ //check if file created succesfully
      
      serial.print("file created");
      serial.println();
    }
    else{
      serial.print("could not create file succesfully");
      serial.println();
    }
    
  
}

void loop(){

  buttonstate = digitalread(buttonpin);  //read current state of button pin
  
  if (buttonstate != lastbuttonstate && buttonstate == high) {    
    
    while(buttonstate != lastbuttonstate && buttonstate == high) {  //if button has changed state , pressed then..
    
      time1=millis();   //get current time in milliseconds
      durationmicros = pulsein(buttonpin,high,300000000);   // time how long button pressed in milliseconds
      duration = durationmicros/1000000;   //do correct calculation convert time in seconds
      buttonpushcounter++;   //increment counter 1
      steps=buttonpushcounter*2;  //every time button pressed count 2 steps
      
      serial.print("steps: ");   //print data in serial monitor
      serial.print(steps);
      serial.print("  duration: ");
      serial.print(duration);
      
      if(steps>20){      //if number of steps exceeds 20 then...
        
        lcd.home();
        lcd.print("i'm lost! help!");
        lcd.setcursor(1, 1);
        lcd.print("home:");
        lcd.setcursor(5,1);
        lcd.print(steps*0.7);
        lcd.setcursor(9,1);
        lcd.print("m. away");
      
        tone(8,349);
        delay(1000);
        notone(8);
        delay(3000);
        tone(3,200);
        delay(1000);
        notone(8);
        delay(3000);    //print message on lcd screen trigger sound    
  
   lcd.clear();  //clear screen
  
    }

      time2 = millis();  //get current time
      elapse=time2-time1;    //subtract previous time current time find how long between 2 button pushes
      duration2 = (elapse/1000)-duration;  //find duration between 2nd , 3rd step in seconds subtracting duration between 2 first steps.
      serial.print( " duration2: ");
      serial.print(duration2);
      serial.println();  //print relevant information in serial monitor
      
    
    file datafile = sd.open("datalog.csv" , file_write );   // check if file available if yes write it…
    if (datafile == true){
      
      datafile.print("steps: ");
      datafile.print(steps);
      datafile.print(" , ");
      datafile.print(" duration: ");
      datafile.print(duration);
      datafile.print(" , ");
      datafile.print(" duration2: ");
      datafile.print(duration2);
      datafile.println();
      datafile.close();
      
      serial.println("data logged!!!");
    }
    
    else { //  …if not pop error
      serial.println("error opening datalog.csv");
    }
    }
    
    
    
    lastbuttonstate = buttonstate;
    
  }
  
    
  }
  












i appreciate help

... lcd same setup without .csv file writing works fine when adding code needed write datalog.csv file on sd card lcd prints nothing during void loop() function


Arduino Forum > Using Arduino > Project Guidance > LCD and SD module wont work together please help fix??? ASAP


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code