Pages: [1] 2   Go Down
Author Topic: Ethernet Shield (SD Slot) & LCD combined problems  (Read 2189 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all.
So I am working on a project, with a number of functions.
I have encountered a problem where when I use the LCDDisplay() function and the LogData() function together, the data does not get recorded in the SD card.
I've tested them both seperatly in my main code and they both work, but when using them together they don't.
I am not sure what the problem is but any help would be greatly appreciated.
I am using the Adruino Mega and the Adruino Ethernet shield. The LCD screen is a serLCD.

Code:
#include <SD.h>

// for measuring time.
unsigned long time;
unsigned long timer=0;
unsigned long seconds;

// On the Ethernet Shield, CS is pin 4.
const int chipSelect = 4;

// Variable for reading the pushbutton status
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int Button;

// Variables for calculated values to be displayed on LCD
float celcius;
float ph;
float oxygen;
float yeast;

// Variables for raw sensor inputs
int tempRaw = 0;
int pHRaw = 0;
int Turbidity = 0;
int yeastRaw = 0;

// Variables for temperature sensor and calculations
int i = 0;
int n;
int sample = 30;
float tempRawArray[30];
float averagetempRaw;
float sumtempRaw;
float referenceVoltage;
float volts;
float voltDivisor;
float millivolts;
float kelvin;
int x;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  referenceVoltage = 5000;
 
  // initialize the pushbutton pins (24,26,28,30) as inputs:
  pinMode(24, INPUT);
  pinMode(26, INPUT);
  pinMode(30, INPUT);
  pinMode(32, INPUT);
 
  // Ethernet Shield Initialization
  int analogPin = 2;
 
    Serial.print("Initializing SD card...");

  pinMode(53, OUTPUT);
 
  // see if the card is present and can be initialized:
  SD.begin(chipSelect);

}

void loop()
{
//Timer for data logging every 10 seconds
    time = millis();

  if(time == (timer+10000)){

  timer = millis();
  seconds = time/1000;
  LogData();

    }

 
 buttonStateFunction();
 //LCDDisplay();
  phSense();
 TemperatureSense();

 



}



//////////////////////////////////////
// Temperature Sensor Functions
/////////////////////////////////////

void TemperatureSense() {
 
    tempRaw = analogRead(A0);   
 

  //Arduino analogReads in a value 0-1024
  voltDivisor = 1024/referenceVoltage;
  kelvin = millivolts/10;
  volts = millivolts / 1000;
  celcius = kelvin - 273.15;

}

void TempControl (){
  int TempInput = analogRead(A0);
      if(TempInput > 560){
    digitalWrite(13, HIGH);
  }
  else
  {
    digitalWrite(13, LOW);
  }
}

//////////////////////////////////////
// p.H. Sensor Functions
/////////////////////////////////////

void phSense(){
 
  pHRaw = analogRead(A1);
 
  }

//////////////////////////////////////
// Conductance Functions
/////////////////////////////////////

void yeast1Sense(){
 
  Turbidity = analogRead(A2);
 
  }

//////////////////////////////////////
// Turbidity Sensor Functions
/////////////////////////////////////

void yeast2Sense(){
 
  yeastRaw = analogRead(A3);
 
  }

//////////////////////////////////////
// Buttons Functions
/////////////////////////////////////

void buttonStateFunction() { //Check which button is being pushed

  // Check if buttons have been pushed
  int buttonState1 = digitalRead(24);
  int buttonState2 = digitalRead(26);
  int buttonState3 = digitalRead(30);
  int buttonState4 = digitalRead(32);

  // Check which button has been pushed and assign a variable to it
if (buttonState1 == HIGH) {
  Button = 1;
    }
else if(buttonState2 == HIGH) {
  Button = 2;
    }
else if(buttonState3 == HIGH) {
  Button = 3;
    }
else if(buttonState4 == HIGH) {
  Button = 4;
    }

}

//////////////////////////////////////
// Data Logging
/////////////////////////////////////

void LogData()
{
  // make a string for assembling the data to log:
  // Temperature
  String dataString1 = "";
  dataString1 += String(tempRaw);
 
  // p.H.
  String dataString2 = "";
  dataString2 += String(pHRaw);
 
  // Yeast 1
  String dataString3 = "";
  dataString3 += String(Turbidity);
 
  // Yeast 2
  String dataString4 = "";
  dataString4 += String(yeastRaw);
 
  // Timer
  String dataString5 = "";
  dataString5 += String(seconds);
 
  // 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("TempData.txt", FILE_WRITE);
    dataFile.print("Temperature = ");
    dataFile.println(dataString1);
    dataFile.close();
   
  File dataFile1 = SD.open("pHData.txt", FILE_WRITE);
    dataFile1.print("pH = ");
    dataFile1.println(dataString2);
    dataFile1.close();
   
  File dataFile2 = SD.open("TurbidityData.txt", FILE_WRITE);
    dataFile2.print("Turbidity = ");
    dataFile2.println(dataString3);
    dataFile2.close();
   
  File dataFile3 = SD.open("YeastData.txt", FILE_WRITE);
    dataFile2.print("Yeast Levels = ");
    dataFile2.println(seconds);
    dataFile2.close();

}

//////////////////////////////////////
// SerLCD Functions
/////////////////////////////////////

void LCDDisplay() { //Decide what to display on the LCD

switch (Button) {
  case 1:
 // clearLCD();
  selectLineOne();
    Serial.print("Temperature    ");
  selectLineTwo(); 
    Serial.print(tempRaw);
    Serial.print(" ");
    Serial.print("Celcius        ");
   break;
 
  case 2:
  //clearLCD();
  selectLineOne();
    Serial.print("p.H.            ");
  selectLineTwo(); 
    Serial.print(pHRaw);
    Serial.print("                ");
    break;
   
  case 3:
  //clearLCD();
  selectLineOne();
    Serial.print("Turbidity       ");
  selectLineTwo(); 
    Serial.print(Turbidity);
    Serial.print("               ");
  break;
 
  case 4:
  selectLineOne();
    Serial.print("Volume Fraction");
  selectLineTwo(); 
    Serial.print("Of Yeast");
    Serial.print(" ");
    Serial.print(Turbidity);
    Serial.print("               ");
  break;

  default:
  selectLineOne();
    Serial.print("Please select");
  selectLineTwo(); 
    Serial.print("what to display");
    delay(4000);
    clearLCD();
  selectLineOne();
    Serial.print("Button 1 for");
  selectLineTwo();
    Serial.print("Temperature");
    delay(3000);
    clearLCD();
  selectLineOne();
    Serial.print("Button 2 for");
  selectLineTwo();
    Serial.print("p.H. levels");
    delay(3000);
    clearLCD(); 
  selectLineOne();
    Serial.print("Button 3 for");
  selectLineTwo();
    Serial.print("Turbidity");
    delay(3000);
    clearLCD();
  selectLineOne();
    Serial.print("Button 4 for");
  selectLineTwo();
    Serial.print("Yeast Levels"); 
  delay(3000);
  //clearLCD(); 
  break;
  } 
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+128), BYTE);    //position
}else if (position<32){Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+48+128), BYTE);    //position
} else { goTo(0); }
}

void clearLCD(){
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(0x01, BYTE);   //clear command.
}

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 601
Posts: 48566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  // Ethernet Shield Initialization
  int analogPin = 2;
The relationship between the code and the comment escapes me. The variable is a local variable that goes out of scope before it is referenced. Why is it here?

Code:
void loop()
{
//Timer for data logging every 10 seconds
    time = millis();

  if(time == (timer+10000)){

  timer = millis();
  seconds = time/1000;
  LogData();

    }

 
 buttonStateFunction();
 //LCDDisplay();
  phSense();
 TemperatureSense();

 



}
would certainly, in my opinion, look better with a  little Tools + Auto format attention.
Code:
void loop()
{
//Timer for data logging every 10 seconds
   time = millis();
   if(time == (timer+10000))
   {
      timer = millis();
      seconds = time/1000;
      LogData();
   }

   buttonStateFunction();
   //LCDDisplay();
   phSense();
   TemperatureSense();
}
Now, if we look at this code, there are some problems. First, subtraction involving variables that can roll over is guaranteed. Addition is not. So,
Code:
   if(time == (timer+10000))
should be
Code:
   if(time - timer == 10000)
Having made that change, you can see the second and third problems. The names time and timer do not convey what those variables actually represent.

More importantly, the difference between time and timer must equal exactly 10000 to trigger logging. If there is any kind of hiccup, and the difference becomes 10001 (which can happen, as millis() will not return every possible value between 0 and 100000, even if all loop does is call millis()), nothing will ever be logged again. So, the operator should be >=, not ==.

The 4th problem is that millis() is called again, if it is time to log. It shouldn't be. The value stored in time is what should be assigned to timer.

See, aren't you glad you asked for a code review? You didn't? Oh well.

Quote
I am using the Adruino Mega and the Adruino Ethernet shield. The LCD screen is a serLCD.
So, why is the LCD connected to the only serial port that you can get debug information from? Move it to another serial port, use SerialN where N is 1, 2, or 3 to talk to it, and talk to the PC using Serial, to debug the issue.

Quote
I've tested them both seperatly in my main code and they both work, but when using them together they don't.
You haven't told us exactly what "doesn't work" means. Nothing appears on the LCD? Something appears, but in the wrong place? Something appears, but it isn't what you intended?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the response, let me try to clarify a few things.

Quote
The relationship between the code and the comment escapes me. The variable is a local variable that goes out of scope before it is referenced. Why is it here?
That was something I had been testing earlier that I had forgotten to remove.

Quote
So, why is the LCD connected to the only serial port that you can get debug information from? Move it to another serial port, use SerialN where N is 1, 2, or 3 to talk to it, and talk to the PC using Serial, to debug the issue
serLCD requires 3 parameters from the microcontroller. The TX port, ground and 5V. So, if i am not mistaken it is not connected to a serial port.

Quote
You haven't told us exactly what "doesn't work" means. Nothing appears on the LCD? Something appears, but in the wrong place? Something appears, but it isn't what you intended?
I apologize, my problem may have sounded ambiguous so let me clarify it.
As you can see in the main loop, the "LCDDisplay()" function has been commented out. When that function is commented out and nothing is displayed on the LCD screen, the "LogData()" function works perfectly. It records the data incoming from the sensors (A0 to A3) at 10 second intervals into four files.
However, when the "LCDDisplay()" function as added back into the code, the "LogData()" function stops working. In other words, no files are created in the SD card and nothing is recorded, but the "LCDDisplay()" function works perfectly.

Situation 1:
LogData function ON, LCDDisplay function OFF = LogData function works perfectly, LCDDisplay function is off.

Situation 2:
LogData function ON, LCDDisplay function ON = LogData does not work at all, LCDDIsplay function works perfectly.

Again, I apologize for any confusion smiley
Please let me know if you need any further clarification.
Any help is greatly appreciated.
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am still unable to fix this problem.
Does anyone have any suggestions?
Again, any help would be greatly appreciated!
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 601
Posts: 48566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
serLCD requires 3 parameters from the microcontroller. The TX port, ground and 5V. So, if i am not mistaken it is not connected to a serial port.
Then, why are you using Serial to talk to it?
Code:
void clearLCD(){
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(0x01, BYTE);   //clear command.
}

Exactly which pins IS the LCD connected to?

If the LCD were not connected to the Serial instance's pins, you could use Serial.print() statements to debug your code. Since you say you have a Mega, there are three other serial ports that you could connect your serial LCD to.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The LCD RX pin is connected to the TX (Transmit) pin on the Adruino.
The Adruino's ground and 3.3V pin is connected to a bread board.
And the VDD pin and GND pin on the LCD is connected to the ground and 3.3V on the bread board.
For reference, this is the datasheet of the LCD I am currently using:
http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF
« Last Edit: February 27, 2012, 05:32:27 pm by Mopinion » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 601
Posts: 48566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am using the Adruino Mega and the Adruino Ethernet shield. The LCD screen is a serLCD.
The Mega has 4, count them 4, hardware serial ports.

Quote
The LCD RX pin is connected to the TX (Transmit) pin on the Adruino.
Which is the Serial instance's TX pin.

Quote
So, if i am not mistaken it is not connected to a serial port.
You are. It IS connected to the Serial port.

Move it to another TX pin, and use that pin's SerialN instance to talk to the LCD. Then, you can use Serial to talk to the Serial Monitor on the PC and debug your program.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still no luck smiley-sad

I've tried replacing all of my Serial.print statements with Serial1.print statements and connected the TX1 (Pin 18) on the Adruino to the RX pin on the LCD.
The LCD screen still works fine but no files are created in the SD card...

I am not sure how else or where to begin debugging at this point.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would check the SD.begin function to see if it is working.

Code:
void setup()
{
   Serial.begin(9600);

   // disable w5100 SPI so it won't trash up the SD SPI
   pinMode(10,OUTPUT);
   digitalWrite(10,HIGH);

   if(SD.begin(4) == 0)
   {
      Serial.println("SD fail");
   }
   else
   {
      Serial.println("SD ok");
   }

   // rest of setup
}

What does the serial monitor show? fail or ok?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It shows "SD ok"
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And still nothing in the files? Then check to see if they are being opened ok.

In your LogData function:

Code:
  File dataFile = SD.open("TempData.txt", FILE_WRITE);
  if(!dataFile)
  {
    Serial.println("Data open error");
  }
  else
  {
    Serial.println("Data open ok");
  }

Do the same for all the file opens. What does the serial monitor say about those?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing prints out. So, I guess for some reason it just skips through the datalog code.
Here is a more updated code WITH the code that you have provided to check if the files are being opened.
Again, this code works with the LCDDisplay function and the datalog function separately.
But together, only the LCDDIsplay function works.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
#include <SD.h>

// for measuring time.
unsigned long time;
unsigned long timer=0;
unsigned long seconds;

// On the Ethernet Shield, CS is pin 4.
const int chipSelect = 4;

// Variable for reading the pushbutton status
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int Button;

// Variables for calculated values to be displayed on LCD
float celcius;
float ph;
float oxygen;
float yeast;

// Variable to store data
int Celcius;

// Variables for raw sensor inputs
int tempRaw = 0;
int pHRaw = 0;
int Turbidity = 0;
int yeastRaw = 0;

// Variables for temperature sensor and calculations

int i = 0;
int n;

int sample = 30;
float rawArray[30];
float averageRaw;
float sumRaw;
float referenceVoltage;
float volts;
float voltDivisor;
float millivolts;
float kelvin;



void setup() {
  // initialize serial communications at 9600 bps:
  Serial1.begin(9600);
  Serial.begin(9600);


  referenceVoltage = 3335;
  
  // initialize the pushbutton pins (24,26,28,30) as inputs:
  pinMode(24, INPUT);
  pinMode(26, INPUT);
  pinMode(30, INPUT);
  pinMode(32, INPUT);
  
  // Ethernet Shield Initialization
  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(53, 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.");

  // For magnetic stirrer and cooler
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
}


void loop()
{
//Timer for data logging every 10 seconds
    time = millis();

  if(time == (timer+10000)){

  timer = millis();
  seconds = time/1000;
  LogData();

    }

  
 buttonStateFunction();
 LCDDisplay();
// phSense();
 TemperatureSense();
// turbiditySense();
// yeastSense();
 //TempControl();
// Stirrer();

}

//////////////////////////////////////
// Magnetic Stirrer
/////////////////////////////////////


void Stirrer() {
  digitalWrite(14, HIGH);   // set the LED on
  delay(5000);              // wait for a second
  digitalWrite(14, LOW);    // set the LED off
  delay(5000);              // wait for a second
}


//////////////////////////////////////
// Temperature Sensor Functions
/////////////////////////////////////

void TemperatureSense() {
  
    tempRaw = analogRead(A0);    
  

  //calc 1- averaged over 30 samples
  rawArray[i] = tempRaw;
  for (int i = 0; i < 30; i++)
    sumRaw = sumRaw + rawArray[i];
  //////////////////////////
  averageRaw = sumRaw/sample;
  //Arduino analogReads in a value 0-1024
  voltDivisor = 1024/referenceVoltage;
  millivolts = averageRaw/voltDivisor;
  kelvin = millivolts/10;
  volts = millivolts / 1000;
  celcius = kelvin - 273.15;
  
  //calc 2- instant
  millivolts = tempRaw/voltDivisor;
  kelvin = millivolts/10;
  // convert to kelvin:   [°C] = [K] − 273.15
  celcius = kelvin - 273.15;
  

  i++;
  if (i >= sample) {
    i = 0;
  }
  sumRaw = 0;

  // wait n milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  n = 200;
  
  Celcius = celcius;

}

void TempControl (){
      if(celcius > 27){
    digitalWrite(13, HIGH);
  }
  else
  {
    digitalWrite(13, LOW);
  }
}

//////////////////////////////////////
// p.H. Sensor Functions
/////////////////////////////////////

void phSense(){
 
  pHRaw = analogRead(A1);
  
  }

//////////////////////////////////////
// Conductance Functions
/////////////////////////////////////

void turbiditySense(){
 
  Turbidity = analogRead(A2);
  
  }

//////////////////////////////////////
// Turbidity Sensor Functions
/////////////////////////////////////

void yeastSense(){
 
  yeastRaw = analogRead(A3);
  
  }

//////////////////////////////////////
// Buttons Functions
/////////////////////////////////////

void buttonStateFunction() { //Check which button is being pushed

  // Check if buttons have been pushed
  int buttonState1 = digitalRead(24);
  int buttonState2 = digitalRead(26);
  int buttonState3 = digitalRead(30);
  int buttonState4 = digitalRead(32);

  // Check which button has been pushed and assign a variable to it
if (buttonState1 == HIGH) {
  Button = 1;
    }
else if(buttonState2 == HIGH) {
  Button = 2;
    }
else if(buttonState3 == HIGH) {
  Button = 3;
    }
else if(buttonState4 == HIGH) {
  Button = 4;
    }

}

//////////////////////////////////////
// Data Logging
/////////////////////////////////////

void LogData()
{
  // make a string for assembling the data to log:
  // Temperature
  String dataString1 = "";
  dataString1 += String(Celcius);
  
  // p.H.
  String dataString2 = "";
  dataString2 += String(pHRaw);
  
  // Yeast 1
  String dataString3 = "";
  dataString3 += String(Turbidity);
  
  // Yeast 2
  String dataString4 = "";
  dataString4 += String(yeastRaw);
  
  // Timer
  String dataString5 = "";
  dataString5 += String(seconds);
  
  // 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("TempData.txt", FILE_WRITE);
    if(!dataFile)
  {
    Serial.println("Data open error");
  }
  else
  {
    Serial.println("Data open ok");
  }
    dataFile.print("Time (in seconds) = ");
    dataFile.println(dataString5);
    dataFile.print("Temperature = ");
    dataFile.println(dataString1);
    dataFile.println("--------------------------------");
    dataFile.close();
    
  File dataFile1 = SD.open("pHData.txt", FILE_WRITE);
    dataFile.print("Time (in seconds) = ");
    dataFile.println(dataString5);
    dataFile1.print("pH = ");
    dataFile1.println(dataString2);
    dataFile.println("--------------------------------");
    dataFile1.close();
    
  File dataFile2 = SD.open("TurbData.txt", FILE_WRITE);
    dataFile.print("Time (in seconds) = ");
    dataFile.println(dataString5);
    dataFile2.print("Turbidity = ");
    dataFile2.println(dataString3);
    dataFile.println("--------------------------------");
    dataFile2.close();
    
  File dataFile3 = SD.open("YeasData.txt", FILE_WRITE);
    dataFile.print("Time (in seconds) = ");
    dataFile.println(dataString5);
    dataFile2.print("Yeast Levels = ");
    dataFile2.println(dataString4);
    dataFile.println("--------------------------------");
    dataFile2.close();

}

//////////////////////////////////////
// SerLCD Functions
/////////////////////////////////////

void LCDDisplay() { //Decide what to display on the LCD

switch (Button) {
  case 1:
 // clearLCD();
  selectLineOne();
    Serial1.print("Temperature    ");
  selectLineTwo();  
    Serial1.print(celcius);
    Serial1.print(" ");
    Serial1.print("Celcius        ");
   break;
  
  case 2:
  //clearLCD();
  selectLineOne();
    Serial1.print("p.H.            ");
  selectLineTwo();  
    Serial1.print(pHRaw);
    Serial1.print("                ");
    break;
    
  case 3:
  //clearLCD();
  selectLineOne();
    Serial1.print("Turbidity       ");
  selectLineTwo();  
    Serial1.print(Turbidity);
    Serial1.print("               ");
  break;
  
  case 4:
  selectLineOne();
    Serial1.print("Volume Fraction");
  selectLineTwo();  
    Serial1.print("Of Yeast");
    Serial1.print(" ");
    Serial1.print(Turbidity);
    Serial1.print("               ");
  break;

  default:
  selectLineOne();
    Serial1.print("Please select");
  selectLineTwo();  
    Serial1.print("what to display");
    delay(4000);
    clearLCD();
  selectLineOne();
    Serial1.print("Button 1 for");
  selectLineTwo();
    Serial1.print("Temperature");
    delay(3000);
    clearLCD();
  selectLineOne();
    Serial1.print("Button 2 for");
  selectLineTwo();
    Serial1.print("p.H. levels");
    delay(3000);
    clearLCD();  
  selectLineOne();
    Serial1.print("Button 3 for");
  selectLineTwo();
    Serial1.print("Turbidity");
    delay(3000);
    clearLCD();
  selectLineOne();
    Serial1.print("Button 4 for");
  selectLineTwo();
    Serial1.print("Yeast Levels");  
  delay(3000);
  //clearLCD();
  break;
  }  
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial1.print(0xFE, BYTE);   //command flag
   Serial1.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial1.print(0xFE, BYTE);   //command flag
   Serial1.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial1.print(0xFE, BYTE);   //command flag
              Serial1.print((position+128), BYTE);    //position
}else if (position<32){Serial1.print(0xFE, BYTE);   //command flag
              Serial1.print((position+48+128), BYTE);    //position
} else { goTo(0); }
}

void clearLCD(){
   Serial1.print(0xFE, BYTE);   //command flag
   Serial1.print(0x01, BYTE);   //clear command.
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is your new code? Where in the setup are you disabling the w5100 SPI interface? Or are you just counting on luck that it won't step all over your SD files?

However, have you considered that with the additional processing times required, you might not be hitting EXACTLY at (timer + 10000). Try this:
Code:
  if(time > (timer+10000)){

  timer = millis();
  seconds = time/1000;
  Serial.println("Logging data");
  LogData();

    }
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That worked! Thanks alot!
I'm not sure what the problem was but that seemed to do the trick.
Initially, when just using the datalog function it had been recording exactly every 10 seconds but for some reason, although this works its seems to be recording every 16-17 seconds:

Time (in seconds) = 16
Temperature = 25
--------------------------------
Time (in seconds) = 33
Temperature = 25
--------------------------------
Time (in seconds) = 50
Temperature = 25
--------------------------------
Time (in seconds) = 67
Temperature = 25
--------------------------------
Time (in seconds) = 84
Temperature = 26
--------------------------------
Time (in seconds) = 101
Temperature = 25
--------------------------------

Quote
That is your new code? Where in the setup are you disabling the w5100 SPI interface? Or are you just counting on luck that it won't step all over your SD files?

I am confused by this statement. Can you elaborate please?
Thanks again!
Logged

Pages: [1] 2   Go Up
Jump to: