Designing A Calibrator using 16x2 LCD

Hello,

I am currently building a universal calibrator using Nano/Uno which is capable of delivering millivolts, milliamps and rtd resistance. It is also able to sink it. Sources are given by an external circuit which i have built.

The display which I am using is 16x2 LCD. I have interfaced external ADC MCP3421 so that I am able to get 16 uV step for accurate reading. Everything else works fine now. Just a bit of fine tuning is left.

The problems which I am facing.

  1. I am displaying millivolts in this format. eg. 100.000 mv. Now if it goes to 2 digits, it becomes 99.0000 mv. How do i set it to 3 decimals only. I have currently stated it as :
lcd.print(vin,3);

When i start, i get 0.000 and it goes properly till 250.000 which is my max range. While reducing, as the digits are reduced, decimal place is increased by a digit. eg. while reducing it from 250.000 to 0, final value I get is 0.00000, which should be 0.000. It returns to normal after I reset the arduino. How to define it to 3 decimal places only?

  1. I want to add RTD lookup table in the program and if possible thermocouple also. How should i go about that? Like after I convert the resistance to equivalent voltage, it should take the reference adc value and display the temperature according to the table.

Your comments and suggestions are valuable to me.

Thank You

When you print to the LCD it does not automatically clear what is already there. So, when you print 250.000 there is a zero in the seventh position. When you subsequently print say 99.000 there will still be a zero in the seventh position on the screen. To get round this either print seven spaces where the number will be before repositioning the cursor and printing the number or print spaces after the number to remove the digits from the previous number printed.

Printed spaces on either sides didnt solve the problem. I have put lcd.clear(); command in the loop. Now it is updated every 500 ms i.e. delay within the loop. A small thing i notice is a very very minute screen flickering when it clear. Cant even notice it from a distance. The problem seemed to be solved using this technique. :slight_smile:

Printed spaces on either sides didnt solve the problem

Then I suggest that you did it wrong. The spaces should not be on either side but rather where the number will be printed. Please post the code using spaces that did not work.

Using lcd.clear() is a sledgehammer to crack a nut.

Yes, did the same thing but even after using all the spaces, still 3 spaces are remaining from 16 digits. Can you give an example of how you are inserting the spaces, may be my method is wrong?

Here is mine (untested)

lcd.setCursor(0,0); //position the cursor where the number will be printed
float x = 123.45;
lcd.print(x, 3);  //print the number
lcd.print("    ");  //print spaces to erase any previous number that was longer
delay(1000);
lcd.setCursor(0,0); //position the cursor where the number will be printed
x = 0;
lcd.print(x, 3);
lcd.print("    ");  //print spaces to erase any previous number that was longer

Now show us yours

@Bob: I've wondered if it is more memory-efficient to use:

   char blanks[] = "                ";

   lcd.setCursor(0, 0);
   lcd.print(blanks);
   // some code that prints something

or to hard-code the spaces like your code does.

I've wondered if it is more memory-efficient to use:

It almost certainly would be. I don't have an LCD to hand but here are a couple of tests using Serial.print()

void setup()
{
  Serial.begin(115200);
  float x = 123.45;
  Serial.print(x, 3);
  Serial.println("XXXX");
  x = 0;
  Serial.print(x, 3);
  Serial.println("XXXX");
}

void loop()
{
}

Sketch uses 3,890 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 202 bytes (9%) of dynamic memory, leaving 1,846 bytes for local variables. Maximum is 2,048 bytes.

void setup()
{
  Serial.begin(115200);
  float x = 123.45;
  Serial.print(x, 3);
  Serial.println(F("XXXX"));
  x = 0;
  Serial.print(x, 3);
  Serial.println(F("XXXX"));
}

void loop()
{
}

Sketch uses 3,954 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 196 bytes (9%) of dynamic memory, leaving 1,852 bytes for local variables. Maximum is 2,048 bytes.

void setup()
{
  Serial.begin(115200);
  char spaces[] = "XXXX";
  float x = 123.45;
  Serial.print(x, 3);
  Serial.println(spaces);
  x = 0;
  Serial.print(x, 3);
  Serial.println(spaces);
}

void loop()
{
}

Sketch uses 3,932 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 202 bytes (9%) of dynamic memory, leaving 1,846 bytes for local variables. Maximum is 2,048 bytes.

I don't know quite what to make of the results.

Sorry for a late reply as i was out of town.

My LCD and ADC had stopped working. So i replaced the ADC and checked again and it started working. Now I just checked, my LCD takes in 80 mA for backlight LED. So should i power it externally? It was giving random garbage value and then it stopped working.

I wish i could have tried that spaces which you had suggested before this problem encountered. :confused: