Digital I/O Expansion
How to expand your interfaces using digital I/O using serial
You are probably here because you have a problem either - you have just
out of pins and need to add more functions to your microcontroller
or the I/O you need is far more than the number of pins
available on your microcontroller.
The way to add more functions to a pin limited system is to
communication. As long as you have at least one pin available all is
There are several methods and each has different tradeoffs.
Here is a list of possible methods, in order of the number of pins needed
(excluding ground), but not in any other particular order of importance.
Digital I/O expansion: RS232
Perhaps the most unusual one is the RS232 serial comms method - for one
way communication you only need one wire. You won't need a
translator if you just communicate between two chips on the same board
and because it will be over a short distance you can run it fast.
The best way to use it is with the built in UART in each
but you could use a software version if absolutely necessary.
You can find more information by clicking the following links for RS232
Digital I/O expansion: Dallas 1 wire
This is a proprietary communication system created by Dallas
(part of Maxim www.maxim-ic.com
). Each device has
a unique laser engraved address etched into
it so that you can put multiple devices on the same wire network.
uses a single I/O pin (working as abus master) to control all slave
devices attached to that I/O pin and all of the devices can be powered
by the I/O pin! and the devices can be daisy chained over 10s of metres.
devices can be powered by the driving I/O
pin (you can add circuitry to provide additional power at the device)
making it super useful for
areas that do not have accessible power.
Typical devices you can use include:
this is not the full list - there are lots more devices!
Although you might think that the 1 wire system is only for
long distance control and measurement you can use it within a single
board and you
can use 100s of devices on the same wire network.
||A popular thermometer (very accurate)
channel addressable switch; input and output & latch.
||A switch (turns
on and off an open drain transistor 28V max).
||4k bit EEPROM
||Quad ADC converter
||Counter with 4kbit RAM
||4kbit EEPROM and dual IO
||Real Time Clock
There is more information on how to use it in the DS18B20
project which also
discusses parasitic mode and how to ensure the network does not go down
when too much power is demanded from lots of devices.
I/O expansion: Johnson counter
chip I like to use for very simple I/O expansion is
the 74HC4017 original
the CMOS version but also available in HC etc. It is a
counter that sequentially turns on one of 10 outputs. All you
need to drive it is two controls reset and clock. It does not
have a lot of output current drive so you may need transistors to
provide more current.
is a useful chip for multiplexing seven segment displays.
expansion: Serial to parallel/parallel to serial chips
can use the discrete chips 74HC595
in and 8 bit parallel out) and 75HC165
bit parallel in and serial out). All you need for each type
- Latch (to get or set stable data).
advantage of these two devices over simple shift registers e.g. 4094 is
that the latch control signal loads data from the internal shift
register to the outputs.
separates the output signals (595) from the shift register so you can
setup all the serial data, clocking it into the device without
changing the outputs. When you are ready you latch the data
through to the output using the latch control signal.
ensures that the data never changes until you are ready for it to
change and a similar operation happens for the parallel to serial
You can easily cascade these devices to provide more I/O using the same
set of controls.
is one of the more flexible ways of interfacing using only two
most important point is that it gives data transmission in both
The SPI protocol does this in a more limited way.
You can add devices onto the bus limited by the addressing scheme ~120
devices and the capacitance that each device adds to the total
capacitance. Addresses are fixed for manufacturers and device
family and some have extra pins to set the lower address range e.g. for
extra serial EEPROMS of the same type.
For more information on I2C
are many more I2C devices!
||8-bit I/O port (cheap version JLC1562).
||Quad ADC converter 8bit.
||Quad ADC and 1 DAC 8bit.
||32-Bit Binary Counter RTC.
||Dual Digital POT (256 position).
||Real Time Clock.
||Digital thermometer and memory.
I/O expansion: SPI
This is the Serial Peripheral Interface using 4 wires (3 if data is
sent in one direction). It is basically a shift register based protocol
- (because of this it can run fast).
For more information on SPI click here
are many more SPI devices!
||64 LED driver (cascadable).
||10-bit I/O expander (26MHz!).
||Quad ADC converter 14bit.
||DAC 8 channel 10bit
||Dual Digital POT 256 position.
||Real Time Clock.
||12 bit temperature sensor.
port expansion : Summary and a look at speed issues
The SPI interface is the fastest (>10MHz) but uses the most pins
while an I2C interface is medium speed (100kHz-400kHz) - although there
faster MHz mode - and RS232 is the
slowest. RS232 uses two pins for communication in both
directions but if you need only transmit data to a peripheral then you
can use one pin.
Digital I/O expander :
create in software
||3-4 (and ground)
||2 (and ground)
(and ground) (for simplex).
||1 (and ground) (for dual simplex)
 I2C has a faster mode (MHz).
SPI Example Project:
is an example ArduinoTM
Project that uses a 4
wire SPI device
for digital I/O
(actually in this case just for output)
adding 64 LED outputs. In addition you can cascade multiple MAX7219
devcies for unlimited I/O.
In practice the maximum number of devices
speed will depend on
how fast the SPI interface goes and the rate of LED output change
For a massive display the processor will need to be faster -
to work out which pixels to change and when etc. For a (5 - 10 ) x 64
there is no problem.
One-WireTM Example Project:
is an example ArduinoTM Project that uses the
One_wireTM protocol (one wire plus a ground
return line - so really 2 wires - but still very impressive). It also
runs on long
wires(10's of metres) - you could run a wire pair into the garden to
record temperature using no power supply!
This is a DS18B20
thermometer accurate to about 0.5°C over a wide temperature range.
The devices can be run either from an extra power line or in
parasitic mode where the power is leeched of a data line i.e. you only
need a micrcocontroller I/O pin to supply power and control it.
| About Me
Claim Your: Useful
"Arduino Software Guide"