Pages: [1]   Go Down
Author Topic: Input problems with 74HC595  (Read 1486 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think this is the right place to ask this. Also I've had a search of the internet and these forums but I don't seem to have come up with anything that helps which suggests that either it can't be done (which I think is very unlikely) or I've made a really simple mistake that I just can't seem to spot.

I've basically followed the tutorial on the arduino site for shift in http://www.arduino.cc/en/Tutorial/ShiftIn and using the code for what is pressed for 8 buttons http://arduino.cc/en/Tutorial/ShftIn12 (the only change I've made is because I'm using different pins)

When I upload the sketch to the arduino and open the serial monitor all I get is full 0s as the input from the 595 except occasionally it will read all 1s then randomly drop different bytes until it reaches all 0s again

I've taken some photos of how I actually put it together and linked them below (you may notice that the buttons appear to be connected to gnd and the shift register but its actually +5v)

Any guidance will be much appreciated smiley

https://www.dropbox.com/s/km625dgq4k2xa7y/Photo%2026-04-2012%2010%2039%2031.jpg
https://www.dropbox.com/s/e7gekwjx70hxz6s/Photo%2026-04-2012%2010%2045%2037.jpg
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1257
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hard to tell from the photos but have you put a signal to all the ic inputs, especially the reset? If they are not connected to 5v or gnd you can get strange effects from the floating inputs.

Just realized you are trying to use the 595 as an input device. The example uses a different chip. The 595 is for output only. You should get into the habit of reading the datasheets for the devices you use as these will spell out the capabilities.
« Last Edit: April 26, 2012, 06:44:18 am by marco_c » Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33371
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The 74HC595 is a serial in parallel out shift register.
It can not be used with the shift in tutorial because that needs a parallel in serial out shift register.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks mike, so you can't use the 595 for inputs? or i need to do it in a different way? if it is possible do you know of any tutorials that could help me?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33371
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so you can't use the 595 for inputs?
Correct.

That tutorial you posted is good if you use the right chips.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok thanks both of you, I was trying it as I already had (and only had) a 595. I guess you learn something new every day, I'm just a bit behind :p
Logged

Hamburg
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes the 74hc595 you can use only as a serial to parallel expander. For inputs its good to use the I2c-Bus called also TwoWireBus
and the PCF8574. I think you will find some application and hints in the Internet. On this IC you can use the pins as well as inputs and outputs.
kitte smiley
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ShiftIn Tutorial : http://www.arduino.cc/en/Tutorial/ShiftIn

And here the datasheet links - take your pick : http://www.datasheetcatalog.com/datasheets_pdf/C/D/4/0/CD4021.shtml

Check it out. download the datasheet and try to understand it.

And I did use the chip 4021 and do a test code. I was using a telephone keypad.

Here the test code.

Code:
//**************************************************************//
//  Name    : shiftIn Example 1.1                              //
//  Author  : Carlyn Maw                                        //
//  Date    : 25 Jan, 2007                                      //
//  Version : 1.0                                               //
//  Notes   : Code for using a CD4021B Shift Register    //
//          :                                                   //
//****************************************************************
// Modify code from the original
// Use only shiftIn () function
/*
    --------------
     1    2      3  <-- Col 1 
     4    5      6  <-- Col 2
     7    8      9  <-- Col 3
     *    0      #  <-- Col 4
     -------------
    /\   /\      /\
     |    |       |
    Row 1 Row 2  Row 3
   
   Telephone keypad pinouts
   
   col 1, col 2, col 3, col 4, row 1, row 2, row3, GND
   4021 connection :
   col 1 : pin 7
   col 2 : pin 6
   col 3 : pin 5
   col 4 : pin 4
   row 1 : pin 13
   row 2 : pin 14
   row 3 : pin 15

   pin 1 of the 4021 - PI-8 held HIGH with a 1 k pull-out resistor.
   
   All keypad pins are with a 1 K pull-up resistor.
   
   Also Serial In - pin 11 of the 4021 held HIGH with a 1 k pull-up resistor
   
   Therefore : 1CCCCRRR
   
   Button = 1 = 0b10111011 = 0xBB = 187
   Button = 2 = 0b10111101 = 0xBD = 189
   Button = 3 = 0b10111110 = 0xBE = 190
   Button = 4 = 0b11011011 = 0xDB = 219
   Button = 5 = 0b11011101 = 0xDD = 221
   Button = 6 = 0b11011110 = 0xDE = 222
   Button = 7 = 0b11101011 = 0xEB = 235
   Button = 8 = 0b11101101 = 0xED = 237
   Button = 9 = 0b11101110 = 0xEE = 238
   Button = * = 0b11110011 = 0xF3 = 243
   Button = 0 = 0b11110101 = 0xF5 = 245
   Button = # = 0b11110110 = 0xF6 = 246
   Button = None press = 0b11111111 = 0xFF = 255
*/

//define where your pins are
int latchPin = 10;
int dataPin = 12;
int clockPin = 11;

//Define variables to hold the data
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar;

void setup() {
  //start serial
  Serial.begin(9600);

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, INPUT);
  switchVar = 0b11111111;

}

void loop() {

  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,HIGH);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);
  //set it to 0 to transmit data serially 
  digitalWrite(latchPin,LOW);

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first
  switchVar = shiftIn(dataPin, clockPin,LSBFIRST);

  //Print out the results.
  //leading 0's at the top of the byte
  //(7, 6, 5, etc) will be dropped before
  //the first pin that has a high input
  //reading 
  Serial.println(switchVar, BIN);
  // or
  Serial.println(switchVar, DEC);
 
//white space
Serial.println("-------------------");
//delay so all these print satements can keep up.
delay(1000);

}

Logged

Pages: [1]   Go Up
Jump to: