What is easy way to extend digital inputs pins using 74hc595+ arduino pro micro

Hello sir ,,. I have an issue with arduino pro micro 32u4 board with 74hc595. I want to extending digital pins of arduino pro micro board using 74hc595. I am new to arduino . But I know how to use all inputs pins on arduino board. I am making a midi device, in which I need to add 40 or 40+ pushing buttons and 1 old display. I also know use of display with arduino board . I have tried 74hc595 shift register with arduino board using mega das IOextention library (digital Read example) I saw , example is working . Because there is one input pin of 74hc595 used as digital Read . But when I tried 2 or others input pins , resulting is wrong
..................

#include <MegaDAS_IOExtension.h>              

const int SH_CP=10;       
const int DS=14;          
const int ST_CP=16;                        
const int IN_P=4;


IOExtension myExt(SH_CP, DS, ST_CP, IN_P); 
void setup()
{
 Serial.begin(9600);
}

void loop()
{
  if (myExt.DigitalRead(1)==HIGH)    {     
   Serial.println("on1");
  } 
 if (myExt.DigitalRead(1)==LOW)   {    
    Serial.println("off1");
 }
   if (myExt.DigitalRead(2)==HIGH)    {      
   Serial.println("on2");
  } 
 if (myExt.DigitalRead(2)==LOW)   {    
    Serial.println("off2");
  }
}

. now if button1 or button2 is pressed (not both at once ) , serial monitor displaying.....
on1
on2

if button1 or button2 is released , serial monitor displaying.......
off1
off2
,,,,,,,,,,, even then if any other button is pressed serial monitor displaying.....
on1
on2
,,,,,,,,,,,,,,,,,,,,,, even then if any other button is released serial monitor displaying.....
off1
off2

i mean to say that all input pins from 74hc595 giving same result. and every pin is not giving its own result,,
please try to understand and solve my problem,,,,,if any can do,,,,,, many many thanks in advance

Just use SPI

SS to RCK (output register clock)
SCK to SRCK (shift register clock)
MOSI to serial data in.

digitalWrite (SSpin, LOW);
SPI.transfer(byte_of_data);
// if you are daisychaining, add 2nd, 3rd SPI.transfer(next_byte_of_data )
digitalWrite (SSpin,  HIGH);

You must post a schematic showing how you have wired the switches to the 74hc595 and how you have wired the 74hc595 to the Arduino.

74hc595 is a serial-to-parrallel shift register and is normally used when you need more outputs, not more inputs (although there are ways to achieve this using Arduino inputs). 74hc164 is a parallel-to-serial shift register, more suitable for inputs like buttons.

There are other techniques for reading large numbers of buttons, which do not require shift registers (or maybe fewer shift registers). You can connect your buttons as a matrix. For example 40 buttons could be arranged in a 6 X 7 or 5 X 8 matrix using 13 Arduino pins.

(deleted)

Hi,
Welcome to the forum, I have given you a karma for reading the how to.

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

larryd:
Just use SPI

SS to RCK (output register clock)
SCK to SRCK (shift register clock)
MOSI to serial data in.

digitalWrite (SSpin, LOW);

SPI.transfer(byte_of_data);
// if you are daisychaining, add 2nd, 3rd SPI.transfer(next_byte_of_data )
digitalWrite (SSpin,  HIGH);

To Larryd
am sorry Larryd,,, i am new to arduino and not understand about use of spi,,. till now, i have test my arduino board as usb midi keyboard using examples like digitalRead, analogRead , usb midi function. but my device has lack of more push puttons,. as i wrote a sketch at the top, is easily understandable. so i followed it.
but i don't know use of spi . if any other solution is availble. please tell me

PaulRB:
You must post a schematic showing how you have wired the switches to the 74hc595 and how you have wired the 74hc595 to the Arduino.

74hc595 is a serial-to-parrallel shift register and is normally used when you need more outputs, not more inputs (although there are ways to achieve this using Arduino inputs). 74hc164 is a parallel-to-serial shift register, more suitable for inputs like buttons.

There are other techniques for reading large numbers of buttons, which do not require shift registers (or maybe fewer shift registers). You can connect your buttons as a matrix. For example 40 buttons could be arranged in a 6 X 7 or 5 X 8 matrix using 13 Arduino pins.

thank you for reply ,,
i want to show diagram .byt there is not any option to upload jpeg. so will write about wiring,,
all pushbuttons's first leg connected to Arduino pin4 and to (Arduino GND wia 10k resistor) as IN_P..
.
second leg of pushbutton1 connected to 74hc595's Pin1-----------
,,second leg of pushbutton2 connected to 74hc595's Pin2---------
second leg of pushbutton3 connected to 74hc595's Pin3------------
second leg of pushbutton7 connected to 74hc595's Pin7-----------
but second leg of pushbutton8 connected to 74hc595's Pin15------------

74hc595's Pin10 connected to Arduino VCC -----

74hc595's Pin11 as(SH_CP) connected to Arduino pin10 -----
74hc595's Pin12 as(ST_CP) connected to Arduino pin16 -----
74hc595's Pin13 connected to Arduino pinGND -----
74hc595's Pin14 as(DS) connected to Arduino pin14 -----
this wiring and top given sketch was easy to understandable for me . but it did't gave correct result.

i have tested my arduino pro micro board as usb midi keyboard after learned pushbuttons use as digitalRead,
and usb midi functions and upload sketch into it . but there is lack of more push buttons...

as you told about matrix 8x5 ,7x6 using 13 pins,,
yes i have 16 pins free on arduino board. if there is tutorial or some info on use of this techniques. although
2x2 using 4pins of arduino board . i will understand and apply on 16pins 8x8matrix,,,
please give me any link to learn it,,,,,,,,,,

TomGeorge:
Hi,
Welcome to the forum, I have given you a karma for reading the how to.

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

to Tom George

thanks Tom George .. i am new to arduino . by the experience, i have tested my arduino pro micro board as usb
midi keyboard. but it is limited to 16 notes. means it need more push button for more notes & functions, so i want to add more pushbuttons ,, i want to learn how to do it easy way ..if you something helpful for me ,,,, please tell me thanks

spycatcher2k:
I love post that start like this, having designed a 75HC595/TPIC6B595 Breakout board to drive displays, the fact that I'm female means I don't have to help. Nice.

To spycatcher2k
am sorry if you mind at my starting words. it was for respect. i am male (music Keyboard player) i thanks to all of
(who are helping & guide to new..) i think you can"t solve any issue to new one

This is what I use for my Control Surface library. It allows you to use the outputs of the shift registers as if they were regular output pins (using digitalWrite).

/**
 * @brief   This example demonstrates the use of shift registers as if they were
 *          just normal IO pins.
 * 
 * Connections:  
 * 
 *   - SS:   74HC595 ST_CP
 *   - MOSI: 74HC595 DS
 *   - CLK:  74HC595 SH_CP
 * 
 * Connect an LED (and series resistor) between the first output of the
 * shift register and ground. 
 * 
 * Remember to connect the enable pins the shift register to ground in order to 
 * enable it.  
 *  
 * This sketch will just blink the LED once a second.
 * 
 * Written by PieterP, 2018-09-01
 * https://github.com/tttapa/Control-Surface
 */

#include <Control_Surface.h> // Include the Control Surface library.

using namespace ExtIO;

/* Instantiate a shift register with the SPI slave select pin as latch pin, most
 * significant bit first, and a total of 8 outputs. */
SPIShiftRegisterOut sreg = { SS, MSBFIRST, 8 };

const pin_t ledPin = sreg.pin(0); // first pin of the shift register

void setup() { /* Initialize everything. */
  sreg.begin();
  pinMode(ledPin, OUTPUT); // You don't even need this line, since
                           // shift registers are always outputs
}

void loop() { /* Toggle the state of the LED every 1/2 second */
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

Link: https://github.com/tttapa/Control-Surface/tree/revision-4

You might find some other useful features, because the library is meant for MIDI devices (it can read buttons, potentiometers, etc, and it can light LEDs based on the incoming MIDI messages, as well as display them on an OLED display). I am still actively working on the documentation.

What exactly are you trying to do here? 74HC595 shift registers are output only. You can use them to drive LEDs, but not for reading inputs.
You could use multiplexers, parallel-in/serial-out shift registers or a switch matrix if you need more buttons than you have IO pins.

Pieter

74hc595 can be used to read buttons, as the OP explained in post #6.

However, if the OP has connected the buttons as described, there is a danger that there will be a short-circuit if two buttons are pressed at the same time. This could damage the 74hc595. One of the 595 outputs will be HIGH and the others will be LOW. The pin which is HIGH is changed frequently to scan all buttons. If two buttons are pressed at the same time, the HIGH output will be short-circuited to a LOW pin and a dangerously high current will flow. This is not a good design.

For a matrix of keys, the design will be slightly different if two or more buttons will be pressed at once. As there are 40 buttons, I think this will be a musical keyboard, so multiple simultaneous button presses are important, for chords etc. So the matrix will need a diode in series with each button, to prevent "ghost" key presses from being detected.

For a tutorial, the OP should use Google and use terms like "Arduino", "keyboard" and "matrix". Look for designs with diodes in series with the buttons.

Hi,

Please re-read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html.

It will tell you how to attach a jpg file.

Thanks.. Tom... :slight_smile:

Regretting giving the OP that Karma point already, Tom?

TomGeorge:
It will tell you how to attach a jpg file.

Can new users, with only 5 posts, attach files? I seem to remember there are various restrictions which force users to bypass the forum guidelines.

PaulRB:
Regretting giving the OP that Karma point already, Tom?

No... OP used code tags.... that's a very big deal....

Using a 74HC595 in this fashion is inappropriate as its specific purpose is to put any 8-bit value to its outputs.

What you actually want is a 74HC4017 which is a binary counter with ten outputs that are pulled HIGH one at a time (including the "zero" output) This requires only two pins to drive it, a reset so that you know it starts at zero, and a clock to advance to the next output.

You use this to select each of ten columns of a matrix, each key in the matrix having a series diode with anode to the column and cathode to a row. Five "rows", each of which needs a pull-down, feeding a pin each would allow you to scan 50 keys with a total of only seven pins.

Hi,
Isn't the OP trying to get more INPUTs, 4017 is for single OUTPUTs.

So we need a copy of the circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom... :slight_smile:

Yes, it was difficult to figure at first, but he appears to be describing a matrix reading system for which you do need scanning, that is, an output function.

In reply #6 he reveals:

charnjit:
all pushbuttons's first leg connected to Arduino pin4 and to (Arduino GND via 10k resistor) as IN_P...

It's not a matrix, unless you describe it as a 40 X 1 matrix of switches! But it is used to scan each of the switches in turn and read their states using a single Arduino input pin. But there is the possibly of a short circuit if two or more buttons are pressed simultaneously, which I suspect is the OP's intention.

Yes, a 40 X 1 matrix is still a (technically, degenerate form of) matrix.

The thing is, using a 74HC4017 to scan ten columns, and switches - with series diodes - matrixed to four or five inputs with pull-downs, is a singularly effective approach to this requirement. The diodes are (always) non-negotiable but their use enables both the use of a scanning source which is not open-collector, and multiple simultaneous key-presses.

Thanks to all for response,,,, after Reading your answer and web browsing , I think 'arduino keypad library' can be best solution.. because my project is a USB midi keyboard from arduino pro micro board with a small oled display+ some functions buttons+ some buttons for midi keys. I think I can solve my issue by trying editing in keypad examples. So first of all ,I will try ready-made example from library. ,,,, So please tell me , I found some digital pins are going to rows ,and some going to colomns. When any row pin is hit to colomn pin.,it make input,. .. is there need of any resistor or diode in circuit.???????? If yes ,. Where in circuit ???& ?? Which value????