Pages: 1 [2] 3 4   Go Down
Author Topic: Stealing data sent to an LCD  (Read 7686 times)
0 Members and 1 Guest are viewing this topic.
Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Come on guys.... If you reply to a thread, keep checking back...
Logged

New Zealand
Offline Offline
Full Member
***
Karma: 1
Posts: 105
Just this guy you know.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a problem with your logic.

You don't seem to know/test to see when the screen is being updated.
I see you just have a loop that is constantly reading the screens data pins.
You need to work out how to be in sync with the data being send to the screens processor.
You then need to decode what the messages being sent to the screen is,
is it change to cursor location in screen memory or is it an update/change to the value in screen memory.
The character codes on page 15 of http://www.adafruit.com/datasheets/TC1602A-01T.pdf  might help decoding the text.

Also reading arduino-0022\libraries\LiquidCrystal\LiquidCrystal.cpp  may help in working out what's going on.

http://www.adafruit.com/datasheets/HD44780.pdf  Page 5 might also help.
Pin 6 E  - MPU Starts data read/write  that might also be the one to look at as it's this start you want to catch.
Also Page 8
Quote
Busy Flag (BF)
When the busy flag is 1, the HD44780U is in the internal operation mode, and the next instruction will not
be accepted. When RS = 0 and R/W = 1 (Table 1), the busy flag is output to DB7. The next instruction
must be written after ensuring that the busy flag is 0.

A good way to debug your routine is to have one arduino running the helloworld example and a 2nd arduino running your snoop hack.
That way you cut down on the random variables of getting it to work with a random device by getting it going with someone simple.

I am guessing you might be able to get timing/sync/update notification by monitoring pins 4 or 5 of the LCD, but NB that a guess.

Also when displaying your 8 bit codes include the leading 0's so 11100  is 00011100 make it easier to see what's going.

So your current returns where and I think decodes to;  (base on page 17 character codes from http://www.adafruit.com/datasheets/HD44780.pdf)

0011 1000 - 8  
-------------------
0011 1000 - 8
-------------------
0011 1000 - 8
-------------------
0011 1000 - 8
-------------------
0001 1100 - either blank or custom character 5a??
-------------------
0001 1000 - either blank or custom character 1a??  not sure
-------------------
0011 1000 - 8
-------------------
0001 1100 - ...
-------------------
0001 1000
-------------------
0011 1000
-------------------
0001 1000

I reserve the rigth to be wrong smiley
« Last Edit: October 17, 2011, 02:28:25 am by hellonearthis » Logged

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok.... Now I'm getting somewhere...

Pin 6 - E is indeed the Clock pin I was looking for.... I modified the code below to only read from the shift register when the clock pin is high.

This is the current code...
Code:
//**************************************************************//
//  Name    : shiftIn Example 1.1                              //
//  Author  : Carlyn Maw                                        //
//  Date    : 25 Jan, 2007                                      //
//  Version : 1.0                                               //
//  Notes   : Code for using a CD4021B Shift Register     //
//          :                                                   //
//****************************************************************

//define where your pins are
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;
int LEDClk = 3;

//Define variables to hold the data
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 72;  //01001000

void setup() {
  //start serial
  Serial.begin(9600);

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, INPUT);
  pinMode(LEDClk, INPUT);

}

void loop() {

while (digitalRead(LEDClk) == HIGH ){
  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,1);
  //set it to 1 to collect parallel data, wait
  //delayMicroseconds(20);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,0);

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first
  switchVar1 = shiftIn(dataPin, clockPin);

  //Print out the results.
  //leading 0's at the top of the byte
  //(7, 6, 5, etc) will be dropped before
  //the first pin that has a high input
  //reading  
  Serial.println(switchVar1, BIN);

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up.


}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) {
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
  for (i=7; i>=0; i--)
  {
    digitalWrite(myClockPin, 0);
    //delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    }
    else {
      //turn it off -- only necessary for debuging
     //print statement since myDataIn starts as 0
      pinState = 0;
    }

    //Debuging print statements
    //Serial.print(pinState);
    //Serial.print("     ");
    //Serial.println (dataIn, BIN);

    digitalWrite(myClockPin, 1);

  }
  //debuging print statements whitespace
  //Serial.println();
  //Serial.println(myDataIn, BIN);
  return myDataIn;
}

Here is the output I am getting.... (note the consistency in the output smiley-grin) This is in BIN (binary) output mode... (read all of it)

Code:
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111

***Repeat***


I have a feeling the Shift register and  arduino can not speak to each other fast enough... Do you think this could be the problem?

As I heat up the Laser sensor I can see shifts in the output... for example...


Code:
-------------------
11111111
-------------------
11111111
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
0
-------------------
0
-------------------
11111111
-------------------
11111111
-------------------
11111111
-------------------
11111111
-------------------
0
-------------------
0
-------------------
0
-------------------
0
-------------------
0

Does this make any sense to anyone?

How can I take this and turn it into meaningful data?
« Last Edit: October 18, 2011, 03:35:58 am by bobhaha » Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just some thoughts. Have not gone thru the whole thread to see what has been discovered so these are only ideas.

First off I would determine if the lcd is being driven in 4 or 8 bit mode. That way you know what to look for in the data being sent.
Is the R/W being used? That adds to the complexity.The data bus is bi-directional.

I would just use the pins of the arduino to hookup to it bypassing the shift register to reduce the problem to its simplest before taking on another.

Treat the enable pin as an interrupt source and in the service routine read the data pins. You will also need to read the RS pin to
see if it's a command or data. If the R/W is being used then that will also need to be delt with.

Driving an lcd is not set in stone- meaning that there are several ways to do it and that would be my main task at hand in finding out how to interface to it.

Hope this helps.


Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have a feeling the Shift register and  arduino can not speak to each other fast enough
Possibly, if you have enough pins I wouldn't bother with the added complication of a serial SR, just read the signals directly through a port as justone suggested.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do I determine if its 4 bit or 8 bit? I've done some research and it only says that 8 bit mode will be used in high refresh scenarios, which this is not.

I put a LCD unit onto some breadboard and connected all the wires to the respective pins. I found that I only needed 8 pins, 2 for LCD power, 2 for backlight power and 4 for data transmission. I forgot to take notes of what pins they were... but when I get home I'll update this post.

Does that mean it's in 4 bit mode? Also does that mean if the E pin is not used it will set it up as always send data and not expect anything returned?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When writing to the display data is valid when E goes low right?

If you run E to an external interrupt and set the interrupt for a falling edge, then have the ISR read the data from the LCD control pins into an array you should have a mini logic analyzer.

Do this for say 1000 times then stop and spit the data out to the USB to the a terminal program.

If all the bytes have F (or 0) in the upper nibble it's a fair bet that you are running in 4-bit mode. Either way you should have data to analyze.

If your device it writing too fast this may not work, in which case a tight polling loop may be better.

______
Rob
« Last Edit: October 20, 2011, 09:06:24 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understood approximately 10% of that....

What does this portion mean?

"If you run E to an external interrupt and set the interrupt for a falling edge"

As far as I understand / can work out, I can use the E pin to stop the device sending data to the shift register, then take in the data, release the E pin (return to low state) and repeat? Is that what you mean?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would forget the shift register, I don't see what that does for you except add another layer of stuff to do.

I would connect E to one of the external interrupt pins, say INT0.

Now when the E signal drops indicating that there is valid data on the LCD data pins you get an interrupt. Connect the lowest six of the LCD data pins to the analogue inputs, we'll assume it's using 4-bit for the time being and add two more if needed later;

Then you write an ISR to handle and some code to print out the buffer

Code:
#define BUF_SIZE 100  // change this to a larger number when/if ti works
byte buffer[BUF_SIZE];
byte * ptr = buffer;
int count = 0;

void myISR () {
  *ptr = PINC; // reads the six data signals and stores them in the buffer
  ptr++;
  count++;
}

void setup () {
   attachInterrupt (0, myISR, FALLING);  // look this up in the reference
   Serial.begin (115200);

   while (count < BUF_SIZE) {};  // wait for BUF_SIZE interrupts to occur

   for (int i = 0; i < BUF_SIZE; i++) {
      Serial.println (buffer[i], HEX);
   }
}

void loop () {};

Hopefully that's close enough.

You should then get 100 bytes printed to the screen. If they all have bits 4 and 5 set (or cleared) then you can assume that only bits 0-3 are being used, hence the LCD is working in 4-bit mode.

______
Rob
« Last Edit: October 20, 2011, 09:56:27 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not seeing any output... let me confirm

A0 - E pin
A1 - D0 from LCD
A2 - D1 from LCD
A3 - D2 from LCD
A4 - D3 from LCD
A5 - D4 from LCD
A6 - D5 from LCD
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino doesn't have an A6, or do you have a Mega?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a nano. It has up to A7. Is this configured correctly?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I see, then try

D2 - E pin

A0 - D0 from LCD
A1 - D1 from LCD
A2 - D2 from LCD
A3 - D3 from LCD
A4 - D4 from LCD
A5 - D5 from LCD

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sydney, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
I ♥ Code :D
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still nothing on serial monitor....

If I go along the outputs with a small LED I'm getting activity on D4 and D5 (pin 12 & 13 respectively)

EDIT: also the TX light is staying on continuously.
« Last Edit: October 20, 2011, 10:41:24 am by bobhaha » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

put

serial.print (".");

in the ISR to see if it's ever being entered.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: 1 [2] 3 4   Go Up
Jump to: