1

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?

  1. 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?

  2. Can I use any pin I want? Or is it required to use specific pins?

  3. Is that the "right way" of doing this? Any suggestion or improvement is welcome!

  • If you can get your head around it, using SPI will let you output to the '595 and input from a shift register (I would avoid CD4k unless you're prepared for its shortcomings) at the same time. And there are a number of GPIO chips that use I2C, which will let you avoid having to deal with shifting altogether. – Ignacio Vazquez-Abrams Jun 24 '15 at 1:26
  • I'd recommend drawing a schematic of your circuit. Not only will that make it clear in your own mind, it will aid the folks in the forum to visualize the picture. Also, once you have the schematic, it will be much easier to construct your physical circuit as you will now have a blue print to follow. – Kolban Jun 24 '15 at 4:08
  • @IgnacioVazquez-Abrams now you got me curious: Since this is the IC used on 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? – heltonbiker Jun 24 '15 at 12:48
  • 1
    As for I2C, there are many options available, some a bit more pricy than others. The basic chip is the MCP23017, which has 16 GPIOs that can be used in any combination of input or output, with optional pullups, pin change interrupt support, etc., and up to 8 can be put on a single bus. It even comes in a SPI variant if you need to access it faster. There are other options such as the TCA6424A, but they come in more exotic packages that you may not be ready for. – Ignacio Vazquez-Abrams Jun 25 '15 at 1:32
  • 1
    If you follow the link and examine the datasheet you'll see that the MCP23x17 is available in DIL, among other packages. – Ignacio Vazquez-Abrams Jun 25 '15 at 1:38
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:

http://www.gammon.com.au/i2c

http://www.gammon.com.au/spi

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 Jun 26 '15 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. – Nick Gammon Jun 26 '15 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 Jun 27 '15 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.