Pages: [1]   Go Down
Author Topic: Problem with setCursor in 20X4 LCD  (Read 205 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Im using a 20X4 JHD 204A LCD screen in my project. The project also has an accelerometer connected to the Arduino.

The pin layout is as follows:

ARDUINO UNO               LCD          ADIS 16210
12                                           4                    MOSI
9                                             6                   

LiquidCrystal lcd(8,9,5,4,3,2);


The code is as follows:
Code:
//Add the SPI library so we can communicate with the ADIS16210 sensor
#include <SPI.h>
// Add the Liquid crystal library
#include <LiquidCrystal.h>


//For ADIS 16210 ,  Assign the Chip Select signal to pin 10.
int CS=10;
int DOUT=11;
int DIN=12;
int CLK=13;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,5,4,3,2);

void setup(){


  lcd.begin(20,4);

  //Initiate an SPI communication instance.
  SPI.begin();
  //Configure the SPI connection for the ADIS16210.
  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV32);

  //Set up the Chip Select pin to be an output from the Arduino.
  pinMode(CS, OUTPUT);

  //Before communication starts, the Chip Select pin needs to be set high.
  digitalWrite(CS, HIGH); 
  delayMicroseconds(40);

void loop()

{

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(millis()/1000);
  delay(50);

}



The problem is that lcd.clear() is displaying a garbage character on the LCD and also it is not setting the cursor back to (0,0).
The LCD displays the word "Panther" continuously on the screen like autoscrolling and not overwriting it on the same position.

Any help will be appreciated.
Logged

The Netherlands
Offline Offline
Edison Member
*
Karma: 50
Posts: 1712
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.

Is that your entire sketch ?
I can't see any panther crawling around in there.
If this is all you sent to the Arduino, i'd suggest you to try the example sketch for these kinds of displays.
It should display "HELLO WORLD" on the first line, and that counter you have too on the second line.

That panther crawling over your screen might be some old sketch in your Arduino ?
Logged

Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 4395
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The pin layout is as follows:
ARDUINO UNO               LCD          ADIS 16210
12                                           4                    MOSI
9                                             6        

It looks like you are saying that Arduino pin 12 is being used for the LCD RS pin (LCD pin 4).  In that case the first number in the constructor should be 12, not 8.  On the other hand this causes a conflict with your DIN so I really don't know what is going on.

Also - remove the lcd.clear() from your loop and see if things improve.


Don
« Last Edit: August 27, 2014, 09:41:01 pm by floresta » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im Sorry. My mistake. I have used 12 itself in initialization and connection is also to the pin 12 of Arduino.
The problem occurs only when I use both the parts together i.e. LCD and ADIS 16210(accelerometer).
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 4395
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im Sorry. My mistake. I have used 12 itself in initialization and connection is also to the pin 12 of Arduino.
The problem occurs only when I use both the parts together i.e. LCD and ADIS 16210(accelerometer).

I think that you have discovered that you can't do that.  Since the LiquidCrystal library allows you to use any available I/O pin on your Arduino to drive any LCD data or control pin you should pick pins for the LCD that don't conflict with your other hardware.

Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Floresta.

You are right we cannot use the same pins for RS(Register Select) of LCD as well as for the E(Enable) pin.
Logged

Pages: [1]   Go Up
Jump to: