Arduino uno lcd 16x2

Good evening at all, I wanted to ask the Guru of this forum, help finding the problem in the attached program, once loaded on my arduino one with lcd, it does not write anything on the display, the same when connected to IDX pro metal detector, It should indicate what type of metal comes into contact with the coil. If on my arduino a genuine load program (Hello World) the same works regularly. I asked for your help to check the attached program, to understand why lcd remains without any writing. Thank you for your kind help.

Detector_Project_04012012.ino (5.13 KB)

Please post your question in English or post it in the Italian section.

Thanks,

Hi mauriziodg, and welcome.

#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);  // assign liquid crystal pins
int backLight = 13;      // pin 13 will control the backlight
// Sensors
int sensorPinx = A0;     // Intialize analog pin A0 and name it "sensorPinx" for the all metal channel
int sensorPinr = A1;     // Intialize analog pin A1 and name it "sensorPinr" for the all disc channel
//Variables
float sensorValuex = 0;  // assign a floating point value of "0" to a variable called "sensorValuex"
float sensorValuer = 0;  // assign a floating point value of "0" to a variable called "sensorValuer"
float slope;             // assign a floating point value of "0" to a variable called "slope"
int n = 0;               // assign an integer value of "0" to a variable called "n"
int cursorClmn = 0;      // assign an integer value of "0" to a variable called "cursorClmn" 
int numSamples = 0;      // assign an integer value of "0" to a variable called "numsamples"
float slopeTotals;       // assign an integer value of "0" to a variabel called "slopeTotals"
float slopeAve = 0;      // assign an integer value of "0" to a variable called "slopeAve"
int VDI = 0;             // assign an integer value of "0" to a variable called "VDI"



// program setup follows
void setup()
{
  pinMode(backLight, OUTPUT); 
  digitalWrite(backLight, HIGH);             // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(16,2);                           // columns, rows.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                               // start with a blank screen
  lcd.setCursor(0,0);                        // set cursor to column 0, row 0 (the first row)
  lcd.print(  "  VDI Project  ");            // print whatever you want
  lcd.setCursor(0,1);                        // set cursor to column 0, row 1
  lcd.print("running 04012012");             // print whatever you want
  delay (2000);                              // wait 1 second
  lcd.clear();                               // Clear the LCD
  
  
  
}

// The main loop follows
void loop()
{
first:                                        //This is a label called "first" so a goto statement can find the beginning of the loop when called
    sensorValuex = analogRead (sensorPinx);   //Read the analog pin A0 and store it's value as sensorValuex (it will be between 0 and 1023)
    sensorValuer = analogRead (sensorPinr);   //Read the analog pin A1 and store it's value as sensorValuer (it will be between 0 and 1023)
                                              //Change SensorValues below to adjust VDI sensitivity
    if (sensorValuex > 5) {                   //If this sensorvalue becomes > 5 it executes the next line. If not, it drops to the "else" statement and goes to the beginning again ("first")
            if (sensorValuer > 5) {           //If this sensorvalue becomes > 5 it executes the next line. If not, it drops to the "else" statement and goes to the beginning again ("first")
              for (int n = 0 ; n < 50 ; n ++) //Starts a counter to read the sensors again in a loop 50 times
              reread:                         //A label called reread will check sensors again if a floating point calulation is bad {0 value)
              {
    sensorValuex = analogRead(sensorPinx);    //Read the analog pin A0 and store it's value as sensorValuex (it will be between 0 and 1023)
    sensorValuer = analogRead (sensorPinr);   //Read the analog pin A1 and store it's value as sensorValuer (it will be between 0 and 1023)
     slope=sensorValuer / sensorValuex;       // calculate X/R ratio and call it "slope"
     if (slope ==0) {
      goto reread; 
     }
    slopeTotals = slopeTotals + slope;      
              }
           
 
         }

  }
  else {
    goto first;                      // runs a loop until the sensors become low again
  }
slopeAve = slopeTotals/50;           // take all the slope values and average them.

                                     // you can manipulate the range of how your VDI numbers are calulated by changing the line below

cursorClmn = (10 - slopeAve);        // slopeAve will typically be between .1 and 9. It just converts it to an integer number between 1 and 10.. used to position the "*" character
tone (8 , (cursorClmn * 200), 100);  // produces a tone of 200 Hz X the mumber above for 100 mS
lcd.clear();                         //clear LCD
lcd.setCursor(0,0);                  //Set cursor on line 0, column 0
lcd.print("VDI = ");                 // print "VDI ="
lcd.print ((10 - slopeAve) * 10);    // prints the calculated number following "VDI ="
lcd.setCursor(cursorClmn,1);         // Positions the cursor on a particular column on row 1
lcd.print ("*");                     // prints the "*" character in that partular colunm
delay (100);                         // display the VDI numbers for 100 mS before going to the beginning of the code again
numSamples = 0;                      // reset all numbers back to "0"
slopeTotals = 0;
slopeAve = 0;
slope = 0;

   }

You said nothing is displayed at all on your LCD.
Is that true, or is the welcome message (about VDI project) displayed ?

If the welcome message is displayed, then your display is connected as described in the sketch and working.
In that case, the conditions on when to write aren’t met.
Your code only writes to the display in the ‘else’ part.
So if the ’ if (sensorValuex > 5)’ is not true.
If it is true, nothing will happen on your LCD.
Perhaps you should write something to the LCD when it is true.

If the welcome message is not displayed, then you should look in to the connections, and the differences between the example that runs, and your code that doesn’t do what you expected it to do.

Hi Mr. MAS3, Thank you for having responded to my post, once I loaded the program, nothing is displayed on the dispay, there is only a row of squares. The program I have attached is not the author, as soon as it lights up it should display the welcome message, then interact with the metal detector circuit. What's wrong with the program? Thanks for your help. :)

once I loaded the program, nothing is displayed on the dispay, there is only a row of squares.

This is usually caused by a wiring error, not a problem with the program. A photograph of your setup would enable us to check the wiring.

How much current does your backlight draw? Could it be overloading the Arduino power supply causing it to shut down? Try turning it OFF instead of ON.

You might want to connect LCD pin 5 to GND and remove the reference to pin 11 in your constructor although your technique should work.

Don

Thanks for having responded to Mr. Forest, I have a question to ask, wiring harness between arduino and display should be done as written instructions in the program or otherwise? Because I seem to see links other than those made by me! Thank you…

It is either or.

Either you change the wiring to the description in the sketch, or you change the description to your wiring. Examine both sketches, or better study how the library works. In the sketch you showed, this is where it is set:

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);  // assign liquid crystal pins

Thanks for having responded to Mr. Forest.

I have to admit that my user name ‘floresta’ was taken from the name of a town in Colorado although the founders probably did choose it because of the surrounding forests.

As mas3 has pointed out you can use any available I/O pin on the Arduino to drive any of the I/O pins on your display. Generally speaking you would first assign pins to those devices that require specific Arduino I/O connections and then use whatever is still available for your LCD.

Don

Thanks for your response MAS3 and Floresta! The program is now perfectly finctioning, it turns out it was only a cabling issue. Thanks again for everything!

Maurizio.

Good! Btw, I always suggest an I2C adapter with 16x2 LCDs: first, you use less pins, second, the I2C can be shared with more than one device (e.g. LCD + RTC), third it's easier to manage for both the software (you only need to know the display I2C address) and the hardware (less connections=less mistakes!;-)).

docdoc: Good! Btw, I always suggest an I2C adapter with 16x2 LCDs: first, you use less pins, second, the I2C can be shared with more than one device (e.g. LCD + RTC), third it's easier to manage for both the software (you only need to know the display I2C address) and the hardware (less connections=less mistakes!;-)).

A bit off topic but just to clarify, Your third point is not really the case for s/w. The issue is that there are a few different types of i2c based LCDs. While most tend to use a PCF8574 based backpack, not all do. Even assuming you have a PCF8574 based backpack, getting working s/w for it can be quite a challenge. The biggest being which library? Unfortunately, there are many different i2c backpack LCD libraries out there for use with PCF8574 based backpacks and making things worse, many of them all use the same name "LiquidCrystal_I2C" for the library class. They don't all work the same and only one of them is available for installation using the IDE library manager. All the others require manual installation, which can be stumbling block for many users. And on top of all that, there is no standard for how the PCF8574 i/o expander chip is wired up to the LCD. As a result, not all of them are wired up the same way. Most of the libraries hard code the pin mappings. If you use one of those, yes, you only need to know the i2c address, but... the LCD will only work if the backpack matches the hard coded pin mapping in the library. A few like fm's newLiquidCrystal library using the LiquidCrystal_I2C i/o class, allow the library to be configured with the pin mappings in the constructor when defining the lcd object. Unfortunately, how to determine the correct pin mapping is often beyond the skill set of the user.

I have created a library package called hd44780 that helps eliminate all of these issues by having the ability to auto detect everything. It is available in the IDE library manager for quick and easy installation. More information is available here: https://github.com/duinoWitchery/hd44780

--- bill

I tried your lib yesterday, after having an all new install of the IDE (due to a new Windows install).
I was surprised about the autodetection, which works great.

Thank you for that, Bill.