ARDUINO EXPERIMENT #2 – DOT-MATRIX DISPLAY AND 74HC595 IC

Description

After many failed attempts to follow Lesson #12 in the Sunfounder Super Kit and even more frustrated with the Sunfounder website, I decided to publish my findings for the dot-matrix experiment because a) I forget and b) maybe someone else will find this useful. The correct tutorial can ultimately found on youtube. The whole playlist seems to be more useful than the booklet, the PDF in the super kit download and the Sunfounder forum or website. But that’s all part of the fUn!

Like my previous experiment, this experiment uses the shiftOut function to write to 2 74HC595 chips. One chip controls the dot-matrix columns while the other controls the rows.

The dot-matrix display that comes with the super kit is an 8 x 8 monochrome (red) LED matrix, model number 1588bs. I couldn’t find a data-sheet for this model and it was unclear which side was top or bottom and therefore which pins were the column pins and which were the row pins. What I found is that the side which I ultimately deemed the bottom row had the model number stamped on it along with a rounded-tab like protrusion in the middle.
20150208_215348

Breadboard View

breadboard-2breadboard-3breadboard-1

Code

The code in the download seemed to be slightly different and didn’t work with the breadboard connections I ultimately used. The download had some extra junk code and was missing the logical negation values passed as the last argument to the shiftOut function. The calls to delay for even one millisecond seemed to slow down the display to a painful crawl, so I removed them.


const int latchPin = 8;//Pin connected to ST_CP of 74HC595
const int clockPin = 12;//Pin connected to SH_CP of 74HC595 
const int dataPin = 11; //Pin connected to DS of 74HC595 

int data[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/
              0xFF,0xC1,0xBE,0xBE,0xBE,0xC1,0xFF,0xFF,/*"0",1*/
              0xFF,0xDF,0xDF,0x80,0xFF,0xFF,0xFF,0xFF,/*"1",2*/
              0xFF,0xDC,0xBC,0xBA,0xB6,0xCE,0xFF,0xFF,/*"2",3*/
              0xFF,0xDD,0xBE,0xB6,0xB6,0xC9,0xFF,0xFF,/*"3",4*/
              0xFB,0xF3,0xEB,0xDB,0x80,0xFB,0xFF,0xFF,/*"4",5*/
              0xFF,0x8D,0xAE,0xAE,0xAE,0xB1,0xFF,0xFF,/*"5",6*/
              0xFF,0xC1,0x96,0xB6,0xB6,0xD9,0xFF,0xFF,/*"6",7*/
              0xFF,0xBF,0xBC,0xB3,0xAF,0x9F,0xFF,0xFF,/*"7",8*/
              0xFF,0xC9,0xB6,0xB6,0xB6,0xC9,0xFF,0xFF,/*"8",9*/
              0xFF,0xCD,0xB6,0xB6,0xB4,0xC1,0xFF,0xFF,/*"9",10*/
              0xFC,0xF3,0xCB,0x9B,0xEB,0xF3,0xFC,0xFF,/*"A",11*/
              0xFF,0x80,0xB6,0xB6,0xB6,0xB6,0xC9,0xFF,/*"B",12*/
              0xFF,0xE3,0xDD,0xBE,0xBE,0xBE,0xBE,0xDD,/*"C",13*/
              0xFF,0x80,0xBE,0xBE,0xBE,0xBE,0xDD,0xE3,/*"D",14*/
              0xFF,0x80,0xB6,0xB6,0xB6,0xB6,0xBE,0xFF,/*"E",15*/
              0xFF,0x80,0xB7,0xB7,0xB7,0xB7,0xBF,0xFF,/*"F",16*/
              0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/};
void setup ()
{
  //set pins to output
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);
}
void loop()
{
  
  for(int n = 0; n < 136; n++)
  {
    for(int t = 0;t < 100;t ++)
    {
      int dat = 0x01;
      for(int num = n; num < 8+ n; num++)
      {
          //shift to simulate right to left scrolling
          dat = dat<<1;     

          shiftOut(dataPin,clockPin,MSBFIRST,~data[num]);
          shiftOut(dataPin,clockPin,MSBFIRST,~dat);    

          //return the latch pin high to signal chip that it 
          //no longer needs to listen for information
          //pull the latchPin to save the data
          digitalWrite(latchPin,HIGH);

          //ground latchPin and hold low 
          //for as long as you are transmitting
          digitalWrite(latchPin,LOW); 
      }
    }
  }
}


Arduino Experiment #1 – 4×4 Keypad, 7 Segment Display and 74HC595 IC

Description

After looking for different tutorials on how to use the 4×4 keypad on the Sunfounder website and getting bits and pieces, I decided to publish my findings because a) I forget and b) maybe someone else will find this useful. This arduino experiment is based on a few different tutorials I’ve found on the Internet.

Using the shiftOut function to write to the 74HC595, the 7 segment display LEDs have corresponding values when controlled through the 74HC595. ( See the crude ascii art comments below the keymap array below.)  I then added the appropriate values for the 4th column to the keymap array.  From there, its a matter of mapping the key value returned from customKeypad.getKey() to the values in the keymap array.

I had trouble reading from PIN 1 on the arduino, so I switched to PIN 9.  I’m new to hobby, so I am not sure if there is a way to switch PIN 1 to an input.

One thing they don’t mention is that you have to download and install the Keyboard library found at http://playground.arduino.cc/Code/Keypad#Download

Breadboard View

Code

//
//4x4 Keypad, 7 Segment Display and 74HC595 IC Experiment #1
//
#include <Keypad.h>

const int latchPin = 12; //Pin connected to ST_CP of 74HC595 - time sequence input of memory                          
                         //register. On the rising edge, the data in shift register moves 
                         //into memory register
const int clockPin = 8; //Pin connected to SH_CP of 74HC595 - time sequence input of 
                        //shift register. On the rising edge, 
                       //the data in shift register moves successively one bit, i.e. 
                       //Data in Q1 moves to Q2, and so forth. 
                       //While on the falling edge, the data in shift register remain unchanged

const int dataPin = 11; //Pin connected to DS of 74HC595 - Serial data input pin

//display           0,  1,   2,   3,   4,   5,   6,   7,   8,   9,   A,  b,   C,   d,   E,   F
int keymap[16] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};

//   ___ 128
// 4 | |  64
// 2 ---
// 8 | |  32
//16 ---  *1

const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {0, 9, 2, 3};
byte colPins[COLS] = {4, 5, 6, 7};

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup ()
{
  //set pins to output
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);

  Serial.begin(9600);
  displayKey('0');
}
void loop()
{
  readKey();
}

void readKey(){
  char key = customKeypad.getKey();
  if (key != NO_KEY)
  {
    displayKey(key);
  }
}

void displayKey(char key){
  Serial.write(key);
  int keycode = 0;
  switch(key){
    case '0':
      keycode = keymap[0];
      break;
    case '1':
      keycode = keymap[1];
      break;
    case '2':
      keycode = keymap[2];    
      break;
    case '3':
      keycode = keymap[3];    
      break;
    case '4':
      keycode = keymap[4];    
      break;
    case '5':
      keycode = keymap[5];    
      break;
    case '6':
      keycode = keymap[6];    
      break;
    case '7':
      keycode = keymap[7];    
      break;
    case '8':
      keycode = keymap[8];    
      break;
    case '9':
      keycode = keymap[9];    
      break;
    case 'A':
      keycode = keymap[10];    
      break;
    case 'B':
      keycode = keymap[11];    
      break;
    case 'C':
      keycode = keymap[12];    
      break;
    case 'D':
      keycode = keymap[13];    
      break;
    case '*':
      keycode = keymap[14];    
      break;
    case '#':
      keycode = keymap[15];    
      break;
    default:
      keycode = 0;
      break;
  }
  digitalWrite(latchPin,LOW); //ground latchPin and hold low for as long as you are transmitting
  shiftOut(dataPin,clockPin,MSBFIRST,keycode);
  //return the latch pin high to signal chip that it 
  //no longer needs to listen for information
  digitalWrite(latchPin,HIGH); //pull the latchPin to save the data
}