I would recommend ditching the the digitalRead in this case - it is performed sequentially, and is rather slow.
As you only need to read 8 input lines, consider using Port register: The Arduino Uno comes with a total of three Ports which "hold" all of the I/O pins.
Those are
- PORTB = Digital Pins 8 through 13 plus the crystal pins
- PORTC = Analog Input 0 through 5, reset pin
- PORTD = Digital Pin 0 through 7
Since you need the RX and TX lines (Digital pin 0 and 1) for your serial communication, you will have to split the signal onto two registers.
I would recommend connecting D0 through D3 to Digital Pins 8 through 11 for the first four bits (meaning they'll go to bits 3 to 0 of Port B), and D4 through D7 to Analog Pins 0 To 3 (meaning they'll go to bits 3 to 0 of Port C).
RW goes to Pin 7, RS to Pin 6, E to Pin 5.
The code you would then use to read the data would be this:
uint8_t byte_displaydata = 0x00;
uint8_t RW = 7;
uint8_t RS = 6;
uint8_t E = 5;
void setup() {
Serial.begin(1200); //perhaps increase this a bit
pinMode(RW, INPUT); //some speed is lost compared to register manipulation, but that is likely insignificant
pinMode(RS, INPUT);
pinMode(E,INPUT);
DDRB &= ~((1 << DDRB0) | (1 << DDRB1) | (1 << DDRB2) | (1 << DDRB3)); //technical not necessary since they're initialized with 0
DDRC &= ~((1 << DDRC0) | (1 << DDRC1) | (1 << DDRC2) | (1 << DDRC3));
PORTB &= ~((1 << PORTB0) | (1 << PORTB1) | (1 << PORTB2) | (1 << PORTB3)); //disable internal pullups
PORTC &= ~((1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3));
}
void loop() {
if(digitalRead(RS) == HIGH && digitalRead(E) == HIGH){
byte_displaydata = 0x00; //reset byte_displaydata
byte_displaydata = PINB << 4; //push PINB bits 3 to 0 to bits 7 to 4
byte_displaydata |= (PINC & 0x0F); //filter PINC bits 3 to 0 and OR them into result bits 3 to 0
Serial.println(byte_displaydata,BIN);
}
}
Please note that I have not tested this, and only recently have gotten started in AVR / Arduino.
If anyone can look this over, I'd greatly appreciate it.
Source: Microchip ATmega328P datasheet, Arduino pin mapping