Thursday, April 23, 2015

JAVA Shift register with Raspberry Pi


Hello there, one more lesson to comment on.

This lesson is good to truly understand what is a shift register. The code is relatively simple once you understand what is a shift register. A grate video to understand what are shift registers is the video called "How Shift Registers Work!" from Kevin Darrah

The circuit is quite straight forward and the documentation schema works fine without any modification. You can find the Java translated code, from the original C code, in the exercise "Ex11_74HC595_LED.java". The unit test class "Ex11_74HC595_LEDTest.java" is just checking that the initialization process is correct. The loop method of the sketch is ready to be modified without any constrain on unit testing. 

Being a Java implementation there fore we can make the code more readable. The key methods to understand are:

 "transferInputByteToShiftReg(led.getValue())" and "latchShiftRegToStorageReg();"

The first one is transmitting a byte value to the shift register using the input data in pin 0 and the shift register clock in pin 2. One bit at a time. Once the byte is transferred then we just need to call the second method which is going to toggle the storage clock in order to latch all the bit values to the register and because of the Open Enabled pin of the chip is low the values are directly sent to the Q0 to Q7 pin outs.    

This is all what it is in this lesson, not much but a very important step to understand lesson 12 and 13 which are using the 74HC595 IC to control cool little led devices. 

For full details about how to set up your Raspberry Pi and how to run these exercises please check out my old post Raspberri Pi with Pi4j and Junit testing mockups. Or leave me a comment if you have any issue or question.

I hope this helps,
Keep on hacking !

Posted by Marc Andreu.

No comments: