Go Down

Topic: using shift registers without shiftOut? 74HC595 (Read 167 times) previous topic - next topic

TobiasRipper

Today at 04:42 am Last Edit: Today at 08:54 pm by TobiasRipper Reason: Better title
There is a video on youtube where a user hoocked up buttons to 2 serial-installed shift registers (total 16 outs) and displayed how the registers worked. Is it possible to use an arduino to control shift registers also without serial?

Reason asking is that I am using software serial and already have to handle reading and writing 3 different types of serial messages and I can not switch to another serial speed that seems to be needed to operate the 74HC595s with arduino
Habeeb!!! Clean up on aisle four!!!

Delta_G

#1
Today at 04:57 am Last Edit: Today at 04:59 am by Delta_G
You can't use serial to control shift registers.  Are you sure he was using serial and not SPI?  It is quite common to use the SPI bus to control a shift register.  Either way you can do it without, look at the shiftOut function.
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

TobiasRipper

I think I may have been looking in an example on a different page where the serial was engaged. Weird. Anyways this is the guy: https://www.youtube.com/watch?v=6fVbJbNPrEU
Habeeb!!! Clean up on aisle four!!!

aarg

Serial is asynchronous. It lacks a clock signal to clock the 595.
  ... with a transistor and a large sum of money to spend ...

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

TobiasRipper

Serial is asynchronous. It lacks a clock signal to clock the 595.
I don't know about that considering in order to read MIDI messages you need to set serial speed at 31,250 bits per second.
Habeeb!!! Clean up on aisle four!!!

sterretje

For the 74HC595 you don't use a serial port.

You use a data line and a clock line. This is called synchronous communication; on each clock tick on the clock line a bit is clocked into the (in this case) 74HC595.

With asynchronous communication (e.g. serial port), there is no clock line. In that case each device (sender and receiver) uses its own clock; the sender to send bits and the receiver to receive bits.

Example code from sparkfun: Experiment 14: Using a Shift Register


TobiasRipper

Ah, got it. Asynchronous communication works with pre defined data transfer speeds which need to be matched by the controller. With the shift registers you need to provide your own clock.

What I really meant in the original question is - arduino has a fiction within which you set the clock pin and data pins and that function controls the shift register. The guy in the video used simple push buttons which essentially just go high and low in arduino code terms. So what I meant was, can you drive the register by just manually pulling clock n data pins high and low instead of the shiftOut function?
Habeeb!!! Clean up on aisle four!!!

Delta_G

Yes, but you have to first understand how the shift register works.  Read the link in reply #4. 
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

TobiasRipper

Yes, but you have to first understand how the shift register works.  Read the link in reply #4.  
Well read up on the shift registers from the data sheet and tutorials as well as videos: 1 or 0 enters the shift register memory bit via data; shift, moves the data to the next bit after which data needs to entire again and latch releases the data into the physical pins in simple terms. Along with other control pins. My main issue is that the shiftOut function outputs the data in binary as demonstrated by the example code where the shift register counts to 255 in binary using the shift register outputs.

I need to be able to set each pin individually by either writing their state in an array or a string and simply having a " for loop" go through each array or string position and write it to the shift register.
Habeeb!!! Clean up on aisle four!!!

UKHeliBob

Quote
I need to be able to set each pin individually by either writing their state in an array or a string and simply having a " for loop" go through each array or string position and write it to the shift register.
Set the bits of a byte the way you want using the bitWrite() function and then use shiftOut() to send the byte to the shift register.

You can also set/clear bits in a byte using the bitwise operators & and | but you may find bitWrite() easier to begin with.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Delta_G

I need to be able to set each pin individually by either writing their state in an array or a string and simply having a " for loop" go through each array or string position and write it to the shift register.
Just think in binary.  Want to turn the 1st pin on and all others off, shiftOut a 1.  Want to turn the 3rd pin on and all others off, shift out a 4.  Want to turn the 3rd and first pins on and all others off, shift out a 5.  Whatever you're doing with that array can be used to build the number you want using bitshifts.  
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

CrossRoads

Having a byte variable that you manipulate by whatever means, and then shifting it is the typical way:

Code: [Select]

// start with a value
byte shiftVar = 0b00001111;

// shift it out:
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shiftVar); // or SPI.transfer(shiftVar);
digitalWrite(latchPin, LOW);

manipulating the byte examples:
shiftVar = shiftVar & 0b11111011; // clear bit 2, leave rest alone, result is 0b00001011

shiftVar = shiftVar | 0b01000000; // set bit 6, leave rest alone, result is 0b01001011

// then shift it out same as above
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shiftVar); // or SPI.transfer(shiftVar);
digitalWrite(latchPin, LOW);
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy