Using a 74HC595 as input - Page 1
Forum section: electronics / beginners

author: blaklite
author_rank: Newbie
timestamp: August 27, 2014, 01:37:46 am
content: I am trying to find some examples/tutorials on using a 595 to read data, rather than the usual output.Essentially I am playing around with 2 line LCD's, and wanted to lower the number of pins I was using on my Arduino (ie the 8 data lines) so I figured using an 8-bit shift register would help.I was trying to build things, without the use of 3rd party libraries, to learn as much as possible. So in that spirit, I thought it would be a good idea to be able to read information from the display, to get things going correctly, rather than throwing data at it and hoping for the best.I have tried a few searches, but the majority of what I have come up with, is about using the 595 to output stuff, and other IC's to read stuff. Although the datasheet does describe the 595 as an "8-bitserial-in, serial or parallel-out shift register" so I reckon it must be possible ?Thanks in advance, for any suggestions you might have.

author: mariush
author_rank: Super Contributor
timestamp: August 27, 2014, 01:50:15 am
content: The chip takes data IN from a microcontroller using serial communication (2 wires) and OUTputs the 8 bits on its output pins. It doesn't do the opposite. There are chips that do the opposite but it's just silly to use two chips for bi-directional communication.For something bidirectional, there are I/O extenders out there that offer input output pins, up to 60 if you need.. here's a list I filtered for you:http://goo.gl/AEsdtN(digikey mile long url )Most support i2c , serial, spi .. they're easy to work with, just look into the datasheet.They cost 1-2$, but for a hobby it's not that expensive.

author: blaklite
author_rank: Newbie
timestamp: August 27, 2014, 03:23:22 am
content: Oh well, thanks for the reply.I was figuring I could somehow toggle a pin to read whatever was on the end of the 8 "output" pins, into the "shift (storage?) register" and read it back into the Arduino, albeit as a serial stream.Thanks for the list. As I am pretty cheap, and I only had the 595's on hand was the reason for my question.I guess it's better to use the correct tool for the job, but for ~$1.28 =) could stretch the budget!Might even get 2! as Christmas is coming up.Out of curiosity, in general is it common to use something like an IO expander. As I could see that a couple of sensors (say separate I2c and SPI buses) plus an LCD would take up most if not all of the available pins, without enough code complexity to justify stepping up to a larger controller. Then again perhaps I am being fussy, after all the pins are there to use, it's just that all the wires look messy when on a breadboard.

author: Unknown
author_rank: Unknown
timestamp: August 27, 2014, 03:24:24 am
content: The 74HC165 would be the parallel-in, serial-out equivalent of the 74HC595, but as mariush says a proper I/O extender is more suited for bidirectional use.My personal favourite of those, for general purpose micro use, is the PCA9535 (specifically TI's TCA9535 variant). I2C, 16 bidirectional I/O pins, individually configurable as high-Z inputs or push-pull outputs, and a state-change interrupt output.edit:Quote from: blaklite on August 27, 2014, 03:23:22 amPretty common - take a look at the Arduino-related 'I2C backpacks' available for LCDs, etc; they mostly use an 8-bit port expander (4 pins for LCD data, plus 2 for R/W & EN, plus a couple of leftover pins used to read switches/backlight control/etc.).I'm currently working on a project that uses a couple of TCA9535's to 'break in' between the front-panel switches (2 x 8-bit BCD switches plus other buttons) and internals of some old analog communications gear. Not only does that mean there's only 6 wires between the radio & micro instead of 30+, they share the I2C buss with a serial EEPROM, keypad, and LCD. I'm using an ATmega328 for development, but the final thing will probably use an 8-pin ATtiny85...

author: David Hess
author_rank: Super Contributor
timestamp: August 27, 2014, 03:37:39 pm
content: The 74HC165 is what I like to use. String it up in series with 74HC595s for outputs and you have dedicated inputs and outputs with separate or combined latch in and latch out controls.

author: macboy
author_rank: Super Contributor
timestamp: August 29, 2014, 04:11:41 pm
content: Try using a LCD expander or adapter board, available at the usual places like ebay, etc. for around $1 (search ebay for "arduino lcd (board,module,interface,adapter)" ). They use a PCF8574 I2C I/O expander to provide enough I/O lines to control the LCD data (4 bit) and control lines as well as backlight control. The PCF8574 allows you to read any pin as well, so you would just set those pins to an input to read the data (after commanding the LCD to do a read). You should have no trouble finding example code to write to the LCD, and maybe to read from it as well... I haven't looked. As a bonus, this device will be able to share a common I2C bus with other devices, saving you even more I/O lines.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 30, 2014, 12:54:57 pm
content: Quote from: blaklite on August 27, 2014, 01:37:46 amYou don't need to read anything from normal 44780 LCDs - just add delays as specified in the datasheet. Only the clear screen takes significant time

author: macboy
author_rank: Super Contributor
timestamp: August 30, 2014, 11:15:23 pm
content: Quote from: mikeselectricstuff on August 30, 2014, 12:54:57 pmI loathe hard-coded delays.My LCD code always checks the busy flag, then sends data when it is not set. This allows the program to send data, prepare the next byte while the LCD is busy, then send the next byte as soon as the LCD is ready. It saves a lot of cycles. In fact I find that most of the time, the LCD is ready when I am ready to send data, so I don't waste any cycles in a NOP loop. Depending on what else the system needs to do, this can be a significant improvement over sending data then NOP-ing for a specified maximum wait time.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 30, 2014, 11:44:32 pm
content: Quote from: macboy on August 30, 2014, 11:15:23 pmYou won't often be updating the display fast enough to worry about speed.

author: dannyf
author_rank: Super Contributor
timestamp: September 07, 2014, 10:27:56 pm
content: QuoteYes, if you can inhibit the other devices (like a LCD) on the shift register's output.One implementation is shown below. The process goes like this:1) Output 0x01 on HC595. If S_OUT is high, SW1 is pressed;2) Output 0x02 on HC595. If S_OUT is high, SW2 is pressed;....With 8 pulses, you can read all 8 switches.