Please.. I need help in using analog pins for LCD display

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jedihonor
 
Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Please.. I need help in using analog pins for LCD display

Post by jedihonor »

HI,
In setting up my Arduino project, I need 2 more digital pins to make my LCD (standard 16 by 2) work. ( I ran out of digital pins) After several hours, I have been unable to get the LCD to work using A0 and A1 as digital pins and the rest of the needed pins are digital. It works great if I use only digital pins and no analog pins. Can someone please help?? Thanks so much. Here is borrowed code I modified.
Scott from Salem

Code: Select all

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,A0, A1);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}
 

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Please.. I need help in using analog pins for LCD display

Post by floresta »

It works great if I use only digital pins and no analog pins.
You didn't give us any clues about what happens when you use the analog pins.

Don

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Please.. I need help in using analog pins for LCD display

Post by mtbf0 »

try

Code: Select all

LiquidCrystal lcd(7,8,9,10,14, 15);

User avatar
jedihonor
 
Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Re: Please.. I need help in using analog pins for LCD display

Post by jedihonor »

HI Don,
When I upload the program, nothing happens, the screen is blue, and on, but no characters. Just blank. Unfortunately I can only use the aforementioned digital pins as the other "busy" digital pins other than pins 0 and 1 (tx, rx), are dedicated to the motor controller I am using. So I must use these unused arduino digital pins 3,5,11,13, plus two more. So A1 and A1 are what I need to get the LCD going. Yes, I tried using pin 14, and 15 without any luck. I'm stumped.
Thank you so much. Any ideas?
Scott from Salem, Or

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Please.. I need help in using analog pins for LCD display

Post by adafruit_support_bill »

I haven't actually tried it (these days I mostly use backpacks to save pins)
But I don't see anything in the library code that would preclude using analog pins. :?

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Please.. I need help in using analog pins for LCD display

Post by mtbf0 »

how about a picture of your circuit?

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Please.. I need help in using analog pins for LCD display

Post by floresta »

Which Arduino are you using? There are some issues regarding certain versions of UNO and the pull-up on pin 7. (http://forums.adafruit.com/viewtopic.php?f=25&t=21671)

Don

User avatar
baldengineer
 
Posts: 127
Joined: Sun Sep 26, 2010 11:49 pm

Re: Please.. I need help in using analog pins for LCD display

Post by baldengineer »

This probably doesn't need to be asked, but did you check that you are actually connecting to Analog 0 and Analog 1? Not Digital 0 and 1 or Analog 4/5?

User avatar
jedihonor
 
Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Re: Please.. I need help in using analog pins for LCD display

Post by jedihonor »

I am using the Arduino Uno, I do not know the version. Yes, I made sure I am using the analog pins 0 and 1. I have tried all the analog pins to use to get the LCD working. The digital pins work great and the LCD works great. It's when I use two analog pins, that the display lights up, but no characters. I am thinking it's a hardware or software problem. It should be easy, just call out the pins A0 and A1 and plug the two remaining LCD pins in and it should work. But it doesn't. I went ahead and bought two "backpacks" so I only need two pins to make the lcd work. Should arrive this week.
Thanks
Scott

User avatar
baldengineer
 
Posts: 127
Joined: Sun Sep 26, 2010 11:49 pm

Re: Please.. I need help in using analog pins for LCD display

Post by baldengineer »

does it help to explicitly call out "pinMode(A0, OUTPUT)" for both pins?

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Please.. I need help in using analog pins for LCD display

Post by floresta »

I went ahead and bought two "backpacks" so I only need two pins to make the lcd work. Should arrive this week.
That doesn't solve the underlying problem.

Don

User avatar
jedihonor
 
Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Re: Please.. I need help in using analog pins for LCD display

Post by jedihonor »

I fixed the problem YESSSS!!! Thank you so much for helping me get the LCD working. Here is what I was doing wrong. A beginners mistake, but I reviewed the literature and could not find a tutorial or "beware of doing this..." Using two pins with the same number.

1. I was trying to be safe, and was declaring my 4 analog sensor (2 through 5) as input pins e.g. (pinMode(pinL, INPUT) . Big mistake so I learned.
2. These pins by default are already input pins. By labeling them as input pins via pinMode, the Arduino assumed they were digital pins 2 through 5).
4. This in turn messed up the actual digital pins needed for the LCD and my motor controller.
5. So the fix.... was just to remove all 4 statements relating to my analog pins, i.e. pinMode(pin, INPUT).

6. The confusion is there are two sets of pins labeled 0 through 5. One analog set, and of course the other set is the digital pins. How does the arduino know which is which when writing the code? I could say: int sensorPin = 2, and also say int ledPin = 2. WOW .. two pins with the same number whats up with this? When I write analogRead(sensorPin), the arduino now knows which pin is analog. And for that matter when I write digitalRead(ledPin) it knows it is a digital pin.

So I may be slow, but I finally got it. Thank you so much!!!
Scott from Salem

User avatar
baldengineer
 
Posts: 127
Joined: Sun Sep 26, 2010 11:49 pm

Re: Please.. I need help in using analog pins for LCD display

Post by baldengineer »

BANNED wrote: The confusion is there are two sets of pins labeled 0 through 5. One analog set, and of course the other set is the digital pins. How does the arduino know which is which when writing the code?
This is why it is better to use "A0, A1, A2, etc" when referring to the analog pins. These expand out to be 14, 15, 16. digital read and write know that 14+ (on an Uno) actually refers to the analog pins.
digitalWrite(A1, HIGH);
effectively turns into
digitalWrite(15, HIGH); //(on an Uno)

Using the name "A0" instead of "14" or "0" makes your code more readable.

analogRead() knows that 0 only refers to Analog0. digitalRead() only knows that 0 is digital pin 0.

Another benefit to using A0..A5 is that if you move your code to a Mega2560, you don't need to change any code. Just changing the board type will work.

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Please.. I need help in using analog pins for LCD display

Post by floresta »

1. I was trying to be safe, and was declaring my 4 analog sensor (2 through 5) as input pins e.g. (pinMode(pinL, INPUT) . Big mistake so I learned.
2. These pins by default are already input pins. By labeling them as input pins via pinMode, the Arduino assumed they were digital pins 2 through 5).
4. This in turn messed up the actual digital pins needed for the LCD and my motor controller.
5. So the fix.... was just to remove all 4 statements relating to my analog pins, i.e. pinMode(pin, INPUT).
Do you realize that you had all of us working at a big disadvantage? There was no way that any of us could have suspected any of this because there was no reference to this in the code example that we were provided.

Don

User avatar
jedihonor
 
Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Re: Please.. I need help in using analog pins for LCD display

Post by jedihonor »

HI Don,
Thanks for the input and I am sorry I did not add the code. I am new at using a forum and just plain had a brain lapse. Won't happen again.
Thanks for your feedback,
Scott

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”