Read data to a 74HC595

Hi guys!

I am working on a custom wheel to the Logitech G27, and in order to keep using it inside hardware to get the leds information of the RPM counter and still use its buttons, I am debugging the board that is between the wheel and it shaft.

The board consist simply of a HC595AG and a 74HC165, the HC595AG to drive the leds and the 74HC165 to read it buttons, my goal is to not use this board and put an Arduino in it place.

My first objective is to read the data that should go to HC595AG and process on the arduino, so I can drive other leds the way I want, but no matter what I try I can't read the data. Can someone help me on this?

I read and draw the schematic of the board, it can be seen here: G27_crack - EasyEDA open source hardware lab

I was abble to drive the board by it on with an Arduino and shiftout code, as normally with any 74HC595 IC.

Pin 1: Ground
Pin 2: Data from the 165
Pin 3: Data to the 595
Pin 4: Clock to both the 165 and 595.
Pin 5: Reset Clock to the 595
Pin 6: Parallel Load to the 165
Pin 7: VCC

To intercept data to the 595, connect to 0 (Ground), 3 (Data), 4 (Clock) and 5 (Reset). On each pulse of pin 4 (Clock), read a bit from pin 3 (Data). If you see a pulse on pin 5 (Reset) you should reset the input buffer.

OK, so here we are:


So next, read the instructions for posting and post your code.

Thanks! I tried an aboard like this, but didn't work, I will try with interrupt now!

I still don't have a code, this is what I am trying to figure out, the best way to do this.

Hi guys!

I've been playing with the board today following those comments and end up with this code:

int reg[8] = {1,1,1,1,1,1,1,1};
int j = 0;
int clock_pin = 2;
int latch_pin = 3;
int data_pin = 4;

void setup() {
pinMode(clock_pin, INPUT);
pinMode(latch_pin, INPUT);
pinMode(data_pin, INPUT);
//DDRD = B11111110; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
//DDRD = DDRD | B00000000;
attachInterrupt(digitalPinToInterrupt(clock_pin), clock_hc, RISING);
attachInterrupt(digitalPinToInterrupt(latch_pin), latch, RISING);
Serial.begin(115200);
Serial.println("teste");
}

void loop() {

}

void clock_hc() {
byte value = PIND;
//reg[j] = digitalRead(data_pin);
reg[j] = PIND & 0b00010000;
j++;
if(j >= 8) j = 0;
}

void latch() {
for(int i = 0; i < 8; i++){
Serial.print(reg[i]);
}
Serial.println();
}

I know that "digitalRead" is slow and not recomended to the job, so I used "reg[j] = PIND & 0b00010000;" instead, but i am getting the value "16" and not "1", I am new in port manipulation, can someone help me with this?

0b00010000 is = 16 :wink:

LED3 and LED2 are in series without a series resistor.

Where are the decoupling capacitors ?

Are you talking about the schematic?
LED1, LED2, R9, and Q8 are in series.
LED3, LED4, R10, and Q9 are in series.
LED3 and LED2 are not in series with each other.

Correct, my eyes couldn’t follow the lines properly.

hmm got it!

But how is the correct way to read if a pin is high or low using PIND? I didn't find anywhere, I just wanna know the state of pin 4 of the arduino, but not using digitalRead since it is slow.

The decoupling capacitors are in the board as normally, both close to it vcc pin of the chip, I just didn't put in the schematic by lazy :sweat_smile:

//read the 4th bit in port D
if(PIND & 0b00010000 == 0b00010000)
{
Serial.println( "The 4th bit is HIGH");
}
else
{
Serial.println( "The 4th bit is LOW");
}

Or:

// read the 4th bit in port D
if((PIND & 0b00010000) != 0) 

Or:

// read the 4th bit in port D
if(!!(PIND & 0b00010000))

Thak you for your help guys!

To read the state of pin 4 i am usnig the following code:

(PIND & (1 << data_pin)) >> data_pin;

And now with tests this is the best code I've reach so far:

int j = 0, k = 1, l = 0;
int clock_pin = 2;
int latch_pin = 3;
int data_pin = 4;
byte t;

void setup() {
  pinMode(clock_pin, INPUT);
  pinMode(latch_pin, INPUT);
  pinMode(data_pin, INPUT);
  attachInterrupt(digitalPinToInterrupt(clock_pin), clock_hc, RISING);
  attachInterrupt(digitalPinToInterrupt(latch_pin), latch, RISING);
  Serial.begin(115200);
  Serial.println("teste");
}

void loop() {
}

void clock_hc() {
  //reg[j] = digitalRead(data_pin);
  noInterrupts();
  /*reg[0] = reg[1];
  reg[1] = reg[2];
  reg[2] = reg[3];
  reg[3] = reg[4];
  reg[4] = reg[5];
  reg[5] = reg[6];
  reg[6] = reg[7];
  reg[7] = (PIND & (1 << data_pin)) >> data_pin;*/
  t = (t << 1) | ((PIND & (1 << data_pin)) >> data_pin);
  interrupts();
}

void latch() {
  noInterrupts();
  /*for(int i = 0; i < 8; i++){
      Serial.print(reg[i]);
      reg[i] = 0;
    }*/
  Serial.println(t, BIN);  
  t = 0;
  interrupts();
}