Cornell University ECE4760
More I/O for
Pi Pico rp2040/2350
You may find that you need more i/o pins either for analog inputs or digital i/o. The stock Pico or Pico2 has 23 digital gpio pins (gpio0 to gpio22) and three pins which may be configured for digital or analog (gpio26, 27 and 28). The configuration used for most of the lab exercises in ece4760 uses 6 to 10 digital pins for VGA video. Moving to HDMI output on the rp2350 requires 8 digital pins (gpio 12 to gpio19). In addition, one SPI channel is used to control a high-speed DAC for audio synthesis. This DAC uses 4 digital gpio pins. Also, two digital pins are used for serial communication to a host PC. The net result is that you have about 10 digital pins left for any other peripherials.
Quite often student projects need more digital i/o and many projects could use 4 or more analog inputs. A typical example might be two analog joysticks, which require 4 analog input channels. Another example would be a keypad which requires 7 or 8 digital i/o pins for scanning, but can be fairly slow. Below are some ideas on how to solve i/o limitations. Generally, there will be some tradeoff when adding i/o, perhaps speed, or current drive capabilities, or bi-directional (input and output) limitations. Think carefully about what you need. Do you really need to sample the ADC at 100 KHz for a joystick? Can you tolerate a 1 MHz output rate to 8 additional digital outputs. Are you driving LEDS, which require milliamps of current, or a FET, which requires microamps?
More Analog I/O
- External ADC to i2c
- External ADC to SPI
- MCP3008 - 8-Channel 10-Bit ADC With SPI Interface
200 Ksamples/sec, single ended or differetial.
- Analog multiplexer front end to existing on-chip ADC
- CD74HC4051A 8 channel 35 MHz bandwidth on a channel
You can change channels at about 2MHz.
Requires 3 i/o lines to choose channel.
- PWM as a DAC
Clocking the PWM at 150 MHz means that you can generate 8-bit samples
at about 586000 samples/sec,
and 12-bit samples at 36000 samples/sec. This is fast eoiugh to produce audio, with just a passive RC lowpass
filter attached to the PWM output.
Choose the RC lowpass cutoff to be at least a factor of 10 lower than the PWM
sample frequency. You can get better sample-rate attenuation with a 2 or 3 pole active lowpass filter.
- PWM to voltage converter
The Analog Devices LTC2644 is a two channel DAC which directly reads two PWM duty cycle signals and converts them to a
voltage. Sample rate is high enough for audio. The part comes in 8, 10, or 12 bit accuracy versions. The only package is surface mount,
but the MSOP package is easy to solder with a magnifier.
More Digital I/O
- Shift register output
- 74HC595 8-bit Shift Register (can be daisy-chained)
serial-in, parallel-out shift register, max shift frequency is ~10 MHz at 3.3 volts.
Only a clock and data line are necessary, but sometimes output-inhibit may be useful.
typical application (from TI data sheet)
- Various LED light strips
- Shift register input
- SN74HC166 parallel-in/ serial-out 8-bit shift register, synchronous load
- SN74HC165 parallel-in/ serial-out 8-bit shift register, asynchronous load
- Multiplexer to input
- 74HC251 eight 1-bit inputs, one bit output. three bit-select lines.
- Port Expander
- MCP23s17 SPI port expander or MCP2317 i2c port expander
SPI or i2c control of two fully bi-directional 8-bit ports with pullups.
SPI is faster but i2c has fewer control lines.
- MCP23s17 library and test code
There is a discussion of the port expander and a short program to test the interface routines.
- MCP23s17 driving keypad
The lower speed interface available on the port expander drives the keypad easily.
Copyright Cornell University
July 4, 2025