I am designing a smart (or at least I hope so) onboard bicycle light system. The system will have an Arduino (currently prototyping with UNO) and a subsystem composed of a "panel" of buttons and leds.
This panel should stay at the handlebar, connected by multi-wire cable to the Arduino located elsewhere on the bicycle.
In order to read an arbitrary number of push-buttons, I plan to use CD4021 IC with shiftIn()
function. And, in order to turn an arbitrary number of leds on and off, I plan to use 74HC595 IC and the shiftOut()
function.
My doubts are: what should I consider in order to do so?
How many wires should I need to connect an arduino to the panel circuit containing the ICs? I believe it is 8 wires (two for the power, three for shifting in [latch, clock, data], and three for shifting out), right?
Can I use any pin I want? Or is it required to use specific pins?
Is that the "right way" of doing this? Any suggestion or improvement is welcome!
1 Answer 1
I have a post here about using an I2C 16-port port-expander: http://www.gammon.com.au/forum/?id=10945
That would use 4 wires for I2C (power, ground, SDA, SCL) or there is an SPI version which would require an extra wire (power, ground, SCK, MOSI, MISO).
I'm not sure about noise over your cable runs, on a bicycle presumably electrical noise is low, so either one might suit. This is the chip that Ignacio Vazquez-Abrams mentioned in his comments. Any of the 16 ports can be configured as inputs or outputs as you desire, plus it can raise an interrupt on a change on an input pin.
You might find that the maximum current limits for output may not be adequate for your LEDs (the datasheet says maximum of 25 mA per output pin, plus a maximum of 125 mA for the whole chip). You could work around this with driver transistors on the chip output, but this is more complexity.
There are higher-powered shift registers (eg. TPIC6B595) which can handle more per pin than the 74HC595.
Can I use any pin I want? Or is it required to use specific pins?
If you want to use I2C there are two specific pins dedicated to the I2C hardware. If you want to use SPI there are dedicated hardware pins as well (different ones) but you can also "bit-bang" SPI if you want.
See:
Is there a through-hole version of that?
All the chips I mention here have through-hole versions.
-
Excellent! I'm new to digital electronics, so finding out all these things has been amazing! One more little question: if I don't need as much as 16 IOs, is there a similar chip with less IOs? I searched for some, and looks like PCAL6408 is a similar, 8-bit one, what do you think? Thank you very much!heltonbiker– heltonbiker2015年06月26日 12:35:16 +00:00Commented Jun 26, 2015 at 12:35
-
As far as I can see the PCAL6408 does not come in a DIP package (through-hole). The MCP23017 seems to be selling on DigiKey for $US1.44 so that seems a reasonable price to me.2015年06月26日 21:05:32 +00:00Commented Jun 26, 2015 at 21:05
-
You're right, I though I have seen a DIP one, but no... Anyway, I'll look for the MCP, thanks!heltonbiker– heltonbiker2015年06月27日 03:22:47 +00:00Commented Jun 27, 2015 at 3:22
shiftIn()
tutorial, what would these shortcomings be? What other shift register could be used instead? Also, the I2C tip is interesting, are those parts expensive in comparison? How should I search for one, and what would be a good 8 channel "equivalent" to the parts I mentioned?