LCD Crystal Error, possible setCursor error

.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

 map(sensorValueIn, 0, 1023, 0, 100);

If you are not concerned about the value returned my map(), it is pointless to call the function.

round (PercentageAct);

Where is this function defined?

void LCD_And_Display ();

Why do you have a function prototype in loop()?

else
 {
 }

Empty else blocks are useless.

lcd.print(sensors.getTempCByIndex(0)); // Why "byIndex"?

What happens when the getTempCByIndex() function returns INF? NAN?

Store the value in an int. Print the value to the serial port. Make CERTAIN that you are getting a reasonable value BEFORE you try to print it to the LCD.

Hi,

I have a linear actuator with an input and output potentiometer (the actuator moves forwards or backwards until the two values match). I also have some LED’s displaying if the values are more than 2% different and also an LCD Display showing the pot reading of the output display and also the error between the two values.

I am using a 20x4 display through the lcd crystal library. I use the void setup section to set the constant displays e.g. lcdprint(“Valve =”) and the void loop to display the potentiometer percentage e.g. lcd.setCursor(0,8); lcd.print(PercentageOutRound); lcd.print("% ");

however turn on my set up the void setup runs correctly but when the void loop runs, it blanks off the first V for valve almost as if it defaults setCursor(0,0) and prints a blank block and I’m really struggling to find the error in my sketch.

#include<LiquidCrystal.h>;
void LCD_And_Display ();
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

int Pot_In = A1;
int Pot_Motor = A0;

const int RedLED = 7;
const int GreenLED = 8;

const int Motor_PWM = 6;
const int Arm_In = 9;
const int Arm_Out = 10;
const int Clutch = 13;

const int Calibration_Time = 5000;
const int Accuracy = 2;

long Previous_Millis = 0;
long Interval = 300;

#include <OneWire.h>
#include <DallasTemperature.h>
const int Int_Temp_Sensor = A2;

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(Int_Temp_Sensor);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

const int Fan_In = 52;
const int Fan_Out = 53:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  pinMode(Pot_In, INPUT);
  pinMode(Pot_Motor, INPUT);
  pinMode(Motor_PWM, OUTPUT);
  pinMode(RedLED, OUTPUT);
  pinMode(GreenLED, OUTPUT);
  pinMode(Arm_In, OUTPUT);
  pinMode(Arm_Out, OUTPUT);
  pinMode(Clutch, OUTPUT);
  pinMode(Int_Temp_Sensor, INPUT);

  digitalWrite(Motor_PWM, LOW);
  digitalWrite(RedLED, LOW);
  digitalWrite(GreenLED, LOW);
  digitalWrite(Arm_In, LOW);
  digitalWrite(Arm_Out, LOW);
  digitalWrite(Clutch, HIGH);

  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print("Valve=");
  lcd.setCursor(0,1);
  lcd.print("Error=");
  lcd.setCursor(0,4);
  lcd.print("Heat Sink=");

  sensors.begin();

}

void loop() {

  int sensorValueIn = analogRead(Pot_In);
  map(sensorValueIn, 0, 1023, 0, 100);
  int PercentageIn = map(sensorValueIn, 0, 1023, 0, 100);
  round (PercentageIn);
  int PercentageInRound = PercentageIn;

  int sensorValueAct = analogRead(Pot_Motor);
  map(sensorValueAct, 0, 1023, 0, 100);
  int PercentageAct = map(sensorValueAct, 0, 1023, 0, 100);
  round (PercentageAct);
  int PercentageActRound = PercentageAct;

  if (PercentageActRound == PercentageInRound)
  {
    digitalWrite(Arm_In, LOW);
    digitalWrite(Arm_Out, LOW);
    digitalWrite(Clutch, HIGH);
  }

  if (PercentageActRound > PercentageInRound)
  {
    analogWrite(Motor_PWM, 255);
    digitalWrite(Arm_In, HIGH);
    digitalWrite(Arm_Out, LOW);
    digitalWrite(Clutch, HIGH);
  }

  if (PercentageActRound < PercentageInRound)
  {
    analogWrite(Motor_PWM, 255);
    digitalWrite(Arm_In, LOW);
    digitalWrite(Arm_Out, HIGH);
    digitalWrite(Clutch, HIGH);
  }

  void LCD_And_Display ();
  unsigned long Current_Millis = millis();

  if (Current_Millis - Previous_Millis > Interval) {
    Previous_Millis = Current_Millis;


    lcd.setCursor(7, 0);
    lcd.print(PercentageActRound);
    lcd.print("% ");

    lcd.setCursor(8, 1);
    lcd.print(abs(PercentageActRound - PercentageInRound));
    lcd.print("% ");


    if (((abs(PercentageActRound - PercentageInRound) > Accuracy))) //Rule to say if values are out of Precision to flash red LED or if in tolerance to turn on GreenLED
    {
      digitalWrite(GreenLED, LOW);
      digitalWrite(RedLED, HIGH);

    }
    else {
      digitalWrite(RedLED, LOW);
      digitalWrite(GreenLED, HIGH);
    }
  }
  else
  {
  }

  sensors.requestTemperatures(); // Send the command to get temperatures
  lcd.setCursor(11,4);
  lcd.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
  lcd.print("DegC ");
 
 
}

Hi @TomGeorge. Thank you for the information :slight_smile:

PaulS:

 map(sensorValueIn, 0, 1023, 0, 100);

If you are not concerned about the value returned my map(), it is pointless to call the function.

round (PercentageAct);

Where is this function defined?

void LCD_And_Display ();

Why do you have a function prototype in loop()?

else

{
}



Empty else blocks are useless.



lcd.print(sensors.getTempCByIndex(0)); // Why "byIndex"?



What happens when the getTempCByIndex() function returns INF? NAN?

Store the value in an int. Print the value to the serial port. Make CERTAIN that you are getting a reasonable value BEFORE you try to print it to the LCD.

Hi PaulS,

The map is in place as I just took it out of the display as I was playing with the sketch to see if that changed anything, before I displayed the input and output potentiometer percentages and I plan to in the future.

I'm sorry, I'm confused about what you mean by the defined function of the round(PercentageAct) line. I have defined PercentageAct in the setup loop.

I have a function loop in my sketch as the actuator feedback was slowed by having the void LCD_And_Display loop in the void loop. The void LCD_And_Display used to have some delays in it for the LED's which have now been removed but I would like to keep this loop in place as I will be adding less time sensitive functions into it.

Sorry I will remove the
else
{
}
I thought this was necessary for a, if function.

I'll look into the lcd.print(sensors.getTempCByIndex(0)) now.

The sensor is serial and LCD printing suitable values (currently its hovering around 24 Deg C and it makes its way up to 28 Deg C when I put my finger on top of the temp sensor (I'm using a Dallas DS18B20)

I'm sorry, I'm confused about what you mean by the defined function of the round(PercentageAct) line. I have defined PercentageAct in the setup loop.

You are calling a function named round(). I do not see that function defined anywhere in your code. What I want to know is what the output of the function is. Is the argument a reference? That is, can the function modify the input argument? By default, functions can not pass data back through arguments. So, I want to see how round() is defined.

by having the void LCD_And_Display loop in the void loop.[/quote]
I can not imagine how the LCD_And_Display() function loops.

The sensor is serial

The DallasTemperature sensor is NOT a serial device.

PaulS:
You are calling a function named round(). I do not see that function defined anywhere in your code. What I want to know is what the output of the function is. Is the argument a reference? That is, can the function modify the input argument? By default, functions can not pass data back through arguments. So, I want to see how round() is defined.

So round is a function within the language that will allow you to round a number instead of having many significant figures. I use to display a whole number percentage.

by having the void LCD_And_Display loop in the void loop.
I can not imagine how the LCD_And_Display() function loops.
The DallasTemperature sensor is NOT a serial device.

I meant that the sensor is printing suitable values both in serial monitor and LCD print, I previously had the sketch serial print and then when I was happy with the output I altered the sketch to LCD print.

PaulS:
You are calling a function named round(). I do not see that function defined anywhere in your code. What I want to know is what the output of the function is. Is the argument a reference? That is, can the function modify the input argument? By default, functions can not pass data back through arguments. So, I want to see how round() is defined.

Maybe a macro in Arduino.h or math.h :wink:

Its usefulness is debatable though in this case as the input is an int; who wants to round an int?

@lparry92

It's by most members here not appreciated if you edit posts after they have replied; I think it's accepted that you add code tags but removing it completely is another story.

You did not mention that your code did not compile; I tried to compile the code in reply #3.

Please answer PaulS' question (quoted below).

void LCD_And_Display ();

Why do you have a function prototype in loop()?

  1. It was in reply to the request of the second post, I couldn't see an edit post option so that was the best option I could think of.

  2. I have the code compiled on my board.

  3. This was the answer I wrote in reply #5

"I have a function loop in my sketch as the actuator feedback was slowed by having the void LCD_And_Display loop in the void loop. The void LCD_And_Display used to have some delays in it for the LED's which have now been removed but I would like to keep this loop in place as I will be adding less time sensitive functions into it. "

You can CALL a function by putting

   LCD_And_Display();

anywhere in the code.

You define a function prototype by putting

void LCD_And_Display();

anywhere in the code (though some places make a lot more sense than others).

Defining a function prototype is NOT the same as calling a function. Putting function prototypes in other functions does not make sense.

lparry92:

  1. It was in reply to the request of the second post, I couldn't see an edit post option so that was the best option I could think of.

You managed to remove the complete content though :wink: But OK

lparry92:
2) I have the code compiled on my board.

Copy the code that you presented to us and try it. It will basically break its neck over this line

const int Fan_Out = 53:

With these (I admit, confusing) errors

sketch_nov07a:7: error: 'A1' was not declared in this scope

 int Pot_In = A1;

              ^

sketch_nov07a:8: error: 'A0' was not declared in this scope

 int Pot_Motor = A0;

                 ^

sketch_nov07a:36: error: expected ',' or ';' before ':' token

 const int Fan_Out = 53:

                       ^

Using library LiquidCrystal at version 1.0.4 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal 
Using library OneWire at version 2.3.2 in folder: C:\Users\Wim Sturkenboom\Documents\Arduino\libraries\OneWire 
Using library DallasTemperature at version 3.7.6 in folder: C:\Users\Wim Sturkenboom\Documents\Arduino\libraries\DallasTemperature 
exit status 1
'A1' was not declared in this scope

lparry92:
3) This was the answer I wrote in reply #5

"I have a function loop in my sketch as the actuator feedback was slowed by having the void LCD_And_Display loop in the void loop. The void LCD_And_Display used to have some delays in it for the LED's which have now been removed but I would like to keep this loop in place as I will be adding less time sensitive functions into it. "

It's a function prototype; those don't belong in other functions (you have already one near the top of your code as well which is the better place).

You however do not have a function LCD_And_Display() (although you might think you have one) and you never call it so both prototypes are useless and can be removed.

Sorry, I know I messed up with the first post but the third is identical.

Again another error. I uploaded the code and there was a colon after Fan_Out on line 35 instead of a semi-colon.

I'm sorry I need to spend some more time reading up on function prototype. From previous reading I had done I was under the impression that I had made a time driven loop that would run every 300ms which would allow the linear actuator to move more freely.

Hi,

I just played with interval of the void LCD_And_Dispaly and it is affecting the 'refresh rate' of the screen without affecting the response of the actuator

lparry92:
Hi,

I just played with interval of the void LCD_And_Dispaly and it is affecting the 'refresh rate' of the screen without affecting the response of the actuator

Since you have not posted the code you are playing with, we must assume that you don't have a problem.

lparry92:
I'm sorry I need to spend some more time reading up on function prototype. From previous reading I had done I was under the impression that I had made a time driven loop that would run every 300ms which would allow the linear actuator to move more freely.

Time driven loop and function prototypes have no relation :wink:

With regards to prototypes. Before you use a function in your code, the compiler needs to be told that that function exists and what type of arguments it takes (if any). One way is to define the function before it is actually used.

int multiplyBytes (byte x, byte y)
{
  return (x * y);
}

void setup ()
{
  Serial.begin(115200)!
  int z = multiply(3,5);
  Serial.println (z);
}

When a prototype is needed is if the function is defined elsewhere, e.g after setup or in anothrr file.

// prototype
int multiplyBytes (byte x, byte y);

void setup ()
{
  Serial.begin(115200)!
  int z = multiply(3,5);
  Serial.println (z);
}

int multiplyBytes (byte x, byte y)
{
  return (x * y);
}

In a sketch (ino file) you can be sloppy and usually forget about them. Before actually compiling the code, the IDE attempts to do some clever tricks to (amongsst other things) add the prototype for you; it gets it wrong at occasion.

In C/CPP files you can't be sloppy as they are not preprocessed by the IDE.