Monday, November 16, 2015

Creating a Four Digit Display Using 74HC595 Shift Registers

My last experiment was with the three 74HC595s I was using to create the Knightrider effect on 24 leds.  In this experiment I am going to add another 74HC595 and use all four to control four common-cathode seven-segment LED displays.

To duplicate this setup you will need the following hardware:



Connections from Arduino in my setup

Pin 12 of the Arduino goes to pin 5 (the latch pin) on all of the 74HC595 shift registers.  When data is shifted out in serial to the shift registers this pin is first taken low then brought back high once the data has been shifted out and needs to be presented to the outputs of the shift registers.

Pin 11 of the Arduino goes to pin 6 on all of the 74HC595 shift registers.  This pin is clocked for each bit that is shifted in.  This pin is used by the ShiftOut() library function to clock data into the shift registers.

Pin 14 of the Arduino is being used as the Serial Data Input to the shift registers.

In order for the serial data to flow to all four of the shift regisers, pin 9 of shift register 1 (my least significant digit, holding the ones position) will connect to pin 14 of shift register 2 (digit holding the 10's position).  Pin 9 of shift register 2 will feed into pin 14 of shift register 3 (100's digit) and pin 9 of shift register 3 will feed into pin 14 of shift register 4 (1,000's digit).

Anytime I update the display it will involve four calls to the ShiftOut() routine:

digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, digits[digit3]); 
shiftOut(dataPin, clockPin, LSBFIRST, digits[digit2]);
shiftOut(dataPin, clockPin, LSBFIRST, digits[digit1]);
shiftOut(dataPin, clockPin, LSBFIRST, digits[digit0]);
digitalWrite(latchPin, HIGH);

Connections to 7 Segment Display

LED pins A through G connect to pins Q0 through Q6 and DP connects to Q7 via current limiting resistors





Wiring the Display 

Each 7  segment display is going to have 8 resistors associated with it.  I placed those 8 above the display on the breadboard and connected them to the 7 segment in the following order:
DP (pin5), G (pin 10), F (pin9), E (pin 1), D (pin 2), C (pin 4), B (pin 6), A (pin 7).

Once I completed that wiring you might consider applying power to the board and testing by jumpering  5 volts to each resistor and confirming that the appropriate segment lights on your display.

Now that the resistors are in place and connected to the 7 segment displays you can connect the shift registers.  Each 7 segment display is being driven by it's own shift register.  Following the order laid out for the 7 segment display you will connect Q7 to the resistor on DP, Q6 to the resistor on G, Q5 to F, Q4 to E, Q3 to D, Q2 to C, Q1 to B and Q0 to A.

NOTE: A more practical way to have a 7 segment display would be using an Adafruit 0.56 4-digit 7-Segment Display w/I2C backpack and only using two pins on the Arduino.  The backpack also multiplexes the displays so the current requirements are much lower.  This experiment is an exercise in using the shift registers that were already breadboarded.

Here is a video of the display counting 0 through 13,000 with no delay between counts.  Once the count goes over 9,999 it will display dashes.


Here is the code I use to test the display.  I have it display dashes if the number is above 9,999, or out of range:


Wednesday, November 11, 2015

Kano Coding Kit For Ages 6-12


Kano is a computer and coding kit for all ages, all over the world. Our mission is to give people a simple, fun way to create with technology, and take control of the world around them.

The kit contains:
Raspberry Pi 2 Model B, ARM 900MHz Quad-Core CPU and 1GB RAM
8GB micro-SD Card preloaded with the latest Kano OS full of projects and games
Kano books, illustrated and intuitive
Wireless Kano Keyboard and mouse (USB RF & Bluetooth)
DIY speaker
Custom case, stencils and stickers!
HDMI cable
Wifi dongle
Mini-USB power supply (US plug)

Click Here To Get Yours




Tuesday, November 10, 2015

Playing night rider with three 74HC595s

Connected three 74HC595s in series and entertained myself by simulating KITT from Knightrider.  Would have hooked up the fourth one but was running out of realestate and LEDs.  I should have a another breadboard in a few days along with some 7 segment leds that I will be hooking up and controlling with the 74HC595s.
NOTE:  The breadboarding of 4 seven-segment displays and driving them with the 74HC595's is an exercise in digital electronics and programming not meant to be a recommendation for implementation in an actual project.  If you need a 7 segment display in your project I recommend using I2C like I am doing in this photo using the Adafruit 0.56 4-digit 7-Segment Display w/I2C backpack (assembly with soldering required).



Till then, enjoy the video and code.

UPDATE - Found that with zero delay the data is getting clocked to the registers at 58KHz.  I thought it would be faster but then if you divide 58Khz into the 16MHz clock of the arduino you get 275 (275 machine cycles). That means it takes the Arduino 17 microseconds to complete the loop when there is no delay.  Looking at the code it is hard to believe 275 machines cycles are required to prepare the next unsigned long integer to be shifted out then clock it out, but I do not know how many of those are used up by the ShiftOut() library function that is called three tiems to shift out all 24 bits.




SourceCode on GitHub

Sunday, November 8, 2015

Serial to Parallel Shifting-Out with a 74HC595

 Using the 74HC595 to control 8 leds (outputs) without giving up 8 ports on the arduino uno. Three outputs from the arduino are used to shift the data out in serial to the 74HC595 were it is then parceled out to each of its individual pins. You can link multiple registers together to extend your output even more, without giving up any more pins on the arduino.
Note: The shift register is not what gives the appearance of the led going back and foth...ie shifting. All the shifting happens prior to the output states changing. The led appears to be shifting because it is in a loop writing int 1, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, and 2.
Next, I will be connecting four of the  74HC595s together to experiment with controlling 32 outputs with 3 pins from the arduino.  Then modify the circuit to control four seven segment leds with 3 pins.  Why do this instead of using the low cost I2C interface?  Speed.  I2C runs at 100k where these shift registers can be clocked as fast as for for loop that shifts the data out, which is well over 1mb/sec.



This is the code used in the video above.  Pin out for the 74HC595 along with a short tutorial by Simon Monk can be found here.

Source Code Here:

Wednesday, November 4, 2015

Controlling an RGB LED with PWM

This is an example from the Arduino Workshop.  You can breadboard the circuit or use a squid


Squid connected directly to Arduino


RGB LED Pinout


Sample code from Arduino Workshop that will demonstrate the RGB Led.



Here it is in Action




Tuesday, November 3, 2015

Playing Music With Remote Control

This was the first experiment I did with Ken Shirrif's Infrared Remote Control Library for the Arduino.

The circuit uses a TSOP382 IR photo sensor to receive the codes from the Clarion remote controller I had lying around.  Once the code is received the program then decides which tone to play.  In this example I have 8 tones set up, middle c through middle b.  For added fun and visual effects I turn on a led for each of the notes as they are played.

Here is a short video of a few notes being played on the Arduino.  Below the video is the code along with some instructions on how to modify the library so it will work with the tone() function.



If you try to use this you will need to install the Arduino library written by Ken Shirrif.  You will also need to modify the library so that it uses TIMER1 instead of TIMER2 because TIMER2 is used by the tone() function.

Technology librarian Trey Ford explains how you modify the library to use TIMER1

  1. First, go to Libraries\Documents\Arduino\libraries\IRremote , the files for the library would be there.
  2. In IRremoteInt.h, at line 194 we have this

    //Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
    #else
      //#define IR_USE_TIMER1 // tx = pin 9
      #define IR_USE_TIMER2 // tx = pin 3
    #endif
  3. We’d need to uncomment the IR_USE_TIMER1 line and comment the IR_USE_TIMER2 line like this:
        // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
        #else
                #define IR_USE_TIMER1 // tx = pin 9
               //#define IR_USE_TIMER2 // tx = pin 3
        #endif


Now if your using codebender you will need to upload the modified version of Ken Shirrif's library to your personal libraries so that when compiling it will user your modified version rather than the default version that is allready registered with codebender.

Here is the code:


Monday, November 2, 2015

Remote Controlling Arduino Robot Shield

Received my board of education arduuino robot shield last Friday and the first thing I wanted to try after assembling it was to control it with an IR remote using Ken Shirrifs IR Library.

The motors on the robot are 360 degree servos that are controlled by sending them a digital pulse ranging in duration from 1300 to 1700 microseconds every 20milliseconds.  The width of the pulse determines the speed and direction they rotate.  1500 would be no motion at all, 1300 full speed counter clockwise and 1700 full speed counter clockwise.  While this is modifying the width of the pulse it is not the same as the PWM functions found in the Arduino library.

When polling for commands from the IR receiver I found that that this particular remote requires me give it at least 175 ms before attempting to read its next transmission.   That, combined with the IR remote being single channel makes for a choppy RC because within 200 ms the servos have already repeated the last command 10 times.

Oh and if you are wondering why no beeping from the Robot it is because the tone function is unable to access TIMER2 because it is being used by the IR Library   The servo library uses TIMER1.

Here is a short video




Here is the Code: