Monday, April 27, 2015

JAVA led segment with Raspberry Pi


Hello there, 

One more lesson update for the Sunfounder Super kit for Raspberry Pi. These two lessons, 12 and 13, are based on the same shift register principle of the lesson 11. The key concept therefore is the same and these set of exercises use the same main methods "transferInputByteToShiftReg(byte)" and "latchShiftRegToStorageReg()" from the common base class "Common_74HC595". A new method "shiftOut(byte)" its been added to the Common_74HC595 class. This method is based on the Arduino shiftOut implementation and its an implementation of shifting with the Most Significant Bit first.

There are four exercises for the two lessons. Two exercises for each lesson. EX12_Segment is a simple direct Java translation from the segment.c code.

The Ex12_Dice  is a bit more interesting, because it has a button using a GpioInterrupt listener. When the button is pressed the dice stops rolling and one number freezes for 2 seconds. Then the dice starts rolling random numbers again. In the video below there is the absolute proof that Java code works in Raspberry Pi.


Rolling dice

Ex13_DotMatrix is also a direct Java translation of the dotMatrix.c code. Nothing really special once you understand how a led matrix works. A very good video to understand Led matrix devices is the Circuit Skills: LED Matrix from Make channel. The matrix is controlled using two 74HC595 ICs and the byte transfer and shifting is exactly the same as lesson 11 and 12. The only difference to notice is that the two ICs work in series. This means that when 16 bits are shifted to the first IC the 8 first bits are pushed out to the second IC by the Data Out pin of the IC 1. Again the superb video from Kevin Darrah called "How Shift Registers Work!" is a grate source to understand this point. 


The SunFounder pdf documentation is not very clear about how to connect the LED matrix. I found a better image which maps the pin out of the ICs with the pins of the LED matrix.  The ROW and COL numbers correspond to the ICs. Pins 1 to 8 are for IC1 and pins 9 to 16 for IC2. The PINs numbers of the image correspond to the LED matrix pins.

And finally the Ex13_DoMatrixAlphabet is an implementation based on this Arduinio sketch that I found online. Unfortunately one of my ICs stared failing and its not working fine. I guess I did some strange test on it ;-). However the code should work fine. Its a pending TODO item to get done when I get a new IC. 

That is all for the 74HC595 shift register lessons. I will be back soon with more stuff. 

One more video for the LED matrix sketch running just before I burned out one of the ICs.


Led matrix 8x8

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.

Posted by Marc Andreu.

No comments: