Arduino and 74x595
wb4jfi at knology.net
wb4jfi at knology.net
Sun Mar 30 18:02:44 CDT 2014
There’s many ways to do the I/O expansion.
To further my previous comments, setting up the LEDs in software also depends somewhat on how the LED on/off data is kept. For example, if the 32 LEDs are represented as the 32 bits of an unsigned long, then it just a matter of using a for loop to test each data bit as you send each clock bit toggle, then toggle the latch pin at the end of the for loop. Obviously, I have not checked out the following, and it’s not real Arduino code, but here’s a close proximity:
(set up pins first.. in setup code...
clock = 595 clock pins (set low at startup)
data = first 595 data pin (set low at startup)
latch = 595 output latch pins (set low at startup)
end of pins setup)
unsigned long leds; // a long handles 32 bits
leds = 0x00000010; // turn on LED 4 ??
for(int count = 0; count < 32; count++) {
if(leds & 0x80000000); // test most-significant bit
data = 1; // turn on data pin
else
data = 0; // turn off data pin
clock = 1; // toggle clock up (leading edge) to send latest bit
clock = 0; // toggle clock back down
leds = leds << 1; // shift leds data one bit left (may not be exactly right)
} // end of bit-test & send loop
latch = 1; // now toggle the 595 data output latch to transfer all bits to output pins
latch = 0; // and set it back down
This assumes that the first data bit sent out will become the most-significant bit (bit 31), as your hardware is wired. Therefore, bit 31 of the unsigned int matches up to LED31, and bit 0 of the int matches up to LED0. There are cleaner ways to code this up, but I’ve left it pretty simple so it’s more clear.
That is, if I’ve got all the above correct! ints vs longs, and shifting correctly... but this is quick, off the top of my head code.
73, Terry, WB4JFI
From: Joseph Bento
Sent: Sunday, March 30, 2014 6:31 PM
To: wb4jfi at knology.net ; Tacos AMRAD
Subject: Re: Arduino and 74x595
Thanks, Terry
It's time to heat up the soldering iron and give a couple of these circuits a try. I've recently discovered tronixstuff.com where I now see there is a wealth of info for the 595 and the I2C chips that you mention. I think it's time to finally get myself out of the strictly analog world of electronics I've been in for so many years. :-)
Joe, N6DGY
On 3/30/2014 4:00 PM, wb4jfi at knology.net wrote:
I don’t have a sketch, but I would say that you want to toggle the clock line as many times as you want, in this case probably 32 times. Keep the data line low except for the equivalent bit that you want to turn on, and keep the latch line disabled until all 32 bits are shifted into position. Then toggle the latch bit once (up then down). Both clock and latch lines are leading edge. If that makes sense? I’m sure a Google search will also help, as the 595 is a common way to expand data I/O on the Arduinos.
Another option that only requires two lines, but does require slightly more expensive parts, would be to use I2C port extender ICs. The PCF8574P is a very popular 8-bit extender, while the PCA9555N handles 16-bits of I/O. Two PCA9555 (or equiv.) would do the same job. There are many others as well. The Arduino Two-Wire library makes using I2C devices very simple. I’ve also use I2C 16x2 LCD displays, as that also greatly reduces the number of pins used for these displays.
I use these I2C chips all the time, as they don’t use up the limited digital I/O pins of the Arduino. For example, on a current project I am using a PCF8574P for I/O expansion, a “digital pot” IC to control the output level of the AD9850 DDS, an EEPROM (24LC256?) for a large look-up table, a DS1307 RTC chip (for battery-backed-up RAM), and a temperature chip, all using only the two I2C pins of the Arduino Uno.
I2C, it’s a great tool!
73, Terry, WB4JFI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://amrad.org/pipermail/tacos/attachments/20140330/81059ba7/attachment.html>
More information about the Tacos
mailing list