LiquidCrystal lib – use analog A1 & A2 pins

Hi All,
LiquidCrystal Library lcd constructor
Is it possible to pass in analog A1 & A2 pins [& set as pinMode(A1, OUTPUT) etc in setup] in place of digital 5 and 6?

E.g. I tried LiquidCrystal lcd(12, 8, 7, A2, A1, 4); = failed silently.
I’d like to free up digital 5 and 6 for PWM use, don’t wish to use a 4094 bit shifter etc & have all the other digital pins in use (ATmega 328). Is it a case of altering the assignments within the cpp file etc?

Any hints/code appreciated-
Cheers and thanks!

Use digital 14-19 for analog 0-5. So you should say:

LiquidCrystal lcd(12, 8, 7, 16, 15, 4);

Have in mind analog pins also start from zero like digital ones so your A1 is the second analog pin.

Thanks liudr,
Perfect, will give it a shot tonight - (I have a LM34 temperature module input on A0) hence using the A1 & A2, but cheers for the reminder just in case!

Rich

richCarthew:
Thanks liudr,
Perfect, will give it a shot tonight - (I have a LM34 temperature module input on A0) hence using the A1 & A2, but cheers for the reminder just in case!

Rich

It was worth checking/mentioning :slight_smile:

Reply back if you have any trouble.

Reply back if you have any trouble.

Hi - no problems, worked like a charm thanks again liudr :slight_smile:

For anyone else wanting to do this, here's a summary:

  1. Pass in the analog pin numbers you want as their respective digital pin numbers as per liudr's series above
  2. Ensure you have the correct wiring! once you make the change (I had the two from the LCD crossed over in error on A1 & A2 instead of the other way as determined by the numbers in 1 (long day),
  3. Set their pinMode's as OUTPUT e.g. pinMode(15, OUTPUT); would be for Analog 1 == can use pinMode(A1, OUTPUT); as equivalent.
  4. Upload the sketch and have fun!
    side note: There is no need to digitalWrite HIGH any analog pins used for this particular example (just in case it occurs for you to do so, as there is mention of doing that in some sections on using analog pins as digital outputs. digitalWrite(pin#, HIGH) would be to turn an LED on (via a resistor in series) etc.

Cheers,
Rich