Trying to get a simple LCD to work with a Nano

Ok, I feel like an idiot. Bought (off of eBay) a "QC2004A" 20x4 LCD display. I2C. It uses the PCF8574T serial chip.

Can't get it to work, it just gives me light and boxes where the chars should be. I think the problem is I'm not at all sure just HOW to hook this up; which pins on the Nano to connect SDA and SDL. I looked up the pinouts on the Nano and it "seems" I need to use D4 and D5. I've tried various drivers and yet, nothing. From the Nano spec it's: 4 (SDA) and 5 (SCL). Should be simple, I'd thought. I've used 1602's before with little problem, but this thing just doesn't work.

More important, I used "I2Cscanner" and it can't find the board. I think I'm just wiring it up badly. But we're talking TWO WIRES here. Again, I think I'm simply not understanding the pins on the Nano that I should use. Either the board is a dud, or I'M the dud.

Any help? Suggestions?

Thanks...

Have you got 4k7 pullups on the I2C lines?

But we're talking TWO WIRES here

Three, when you include ground.

It A4 (SDA) and A5 (SCL), just like on any other ATmega328p-based Arduino.

It's the ANALOG pins? I kinda wondered about that, but I didn't think that was right. And why would I need to put pullup resistors on the pins (Including ground, especially; why pull ground slightly "HIGH?") I'm hardly new at Arduinos, but it seems I have much more to learn.

Here's the spec for the Nano I read on this site:

"I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library." So I assumed they were the digital pins.

Who said you need a pullup on the ground?
SDA is A4, SCL is A5. They need pullups.

Oh YEAH guys! I swapped them to the analog pins and ... I2Cscanner is now showing up at "0x27." I still don't understand, though, why it is supposed to be the analog pins. But THANKS. Uh now though, I need to get it to actually DO something.

I still don't understand, though, why it is supposed to be the analog pins.

Because those happen to be the pins the hardware that drives I2C are attached to.
If you weren't using I2C, you could also use them for digital I/O if you wanted to.

Apparently, AWOL. But from the spec I didn't see it; dunno why they would be the analog pins. It would've helped a lot, and I wouldn't have to bothered you folks, if they'd written the spec to be "A4 and A5." Maybe I should read some other spec sheet on the Nano. But thanks. (Oh, and now I'm having library problems; seems there are a TON of libs for this, and I kept updating them and now, it's toast. I should be able to find a viable library.)

Thanks again. "Analog pins... Who knew?"

Ok, I gotta take that back. I didn't bother to read the paragraph before that pin definition I posted. Apparently it was stating they were talking about analog pins. The pin definitions I read I didn't link to that. So while it's not exactly "expertly worded," I should'a read the whole thing. "My bad." Thanks again.

Oh yeah, and anyone know of a good, working Liquid_Crystal library? Mine won't compile. And it'd be great if it had a definition ("Readme") of the commands you can use and their parameters.

I agree, it could be clearer.
If you look at the product page for the Uno, although the layout is similar, the pins are explicitly labelled as analogue.

Well, got the thing working, thanks to you all! Coded some "fun stuff" to display. I'm still bummed that I have to sacrifice some analog pins though; I needed eight of them for a bench power supply I'm making (Four outputs, measuring both voltage and current for each output.) So I need to see how to get that done; might have to go to a Mega. And I did NOT use any pullup resistors on the signal pins (And, as one person said, ground.) It works fine without them. And that makes sense; you shouldn't need to do that, it's like buying a new car and needing to add a fourth wheel because they only come with three.

bratwurst:
I'm still bummed that I have to sacrifice some analog pins though; I needed eight of them for a bench power supply I'm making

You need the Arduino Leonardo or Arduino Micro:
http://arduino.cc/en/Main/ArduinoBoardLeonardo
http://arduino.cc/en/Main/ArduinoBoardMicro
They use the Atmega32U4 processor and have I2C on D2 and D3 instead of A4 and A5. They also have a total of 12 analog input pins: A0-A5 plus D4, D6, D8, D9, D10, and D12 (called A6-A11).

Bratwurst: sticking with your cars and wheel analogy, you don't need to buy a different car, you just need to add some more wheels to the axles you already have: Sparkfun Analog Multiplexer

So long as you don't need ridiculously high a/d conversion rates, multiplexing the inputs is an easy way to expand your input channel count.

Hi Bratwurst, just starting a project using LCD, what library did you use in the end ?

Dave

Davey-T: I actually don't know for certain. I tried several, and only found one that works. The problem is, I didn't exactly "log" which driver I'm now using. But gimme some time and I'll see if I can figure it out. In the meantime, I THINK it's this one: https://bitbucket.org/fmalpartida/new-liquidcrystal but I'm not certain. Try that and see if it works. If not, I'll try to get you the right link. Here's a small sketch that shows what worked for me, but again, not entirely positive if that "new-liquidcrystal" driver is what I'm using; sorry, I just kept trying them, over and over. Try this code and please let me know if it works for you. I'd be interested to know. Thanks.

/*
** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens
** Readily found on eBay or http://www.sainsmart.com/
** The LCD2004 module appears to be identical to one marketed by YwRobot
**
** Address pins 0,1 & 2 are all permanently tied high so the address is fixed at 0x27
**
** Written for and tested with Arduino 1.06
** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** NOTE: Tested on Arduino NANO whose I2C pins are A4==SDA, A5==SCL
**
** Modified (Heavily) by "bratwurst," (Dean Cashen) 02/01/2015
*/

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27 // define I2C Address where the PCF8574A is
#define BL_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

long n = 0; // used just to display "count number" used below

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
lcd.begin (20,4); // set LCD object to 20 chars by 4 lines

// turn on the LCD backlight
lcd.setBacklightPin(BL_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go to LCD "home"

lcd.setCursor( 5, 0 ); // set cursor to the 1st line, 5 chars in
lcd.print("Hello World");
lcd.setCursor ( 4, 1 ); // set cursor to the 4th line, 4 chars in
lcd.print(""QC2004A" LCD");
}

void loop()
{
// just some simple code to display an incrementing number ("n" var)
lcd.setCursor( 2, 3 ); // set cursor to 4th line, 2 chars in
lcd.print("- "); // just for "presentation"
lcd.setCursor( 4, 3 ); // set cursor to the 4th line, 4 chars in
lcd.print(n++); // display counter
delay(450); // set update rate
};

Dang, sorry. This is "hack code" I just posted; it WORKS, but it's not good code, and the comments, well, I was to short of time to make them correct. But again, for me at least, this works. Again, lemme know...

AWOL, it was my fault, I kinda rushed through the spec and didn't do it right. And I have an Uno, my very first Arduino, in fact. But I wanted, quite frankly, something a little more "cheap," and the Nano seemed to fit that bill. And the Uno only has 6 analog pins, unless (again,) I'm reading the spec incorrectly. I need a "solid" 8 pins for analog input.