Lessons and the learning game

More pins: expanders, muxes and drivers

Never run out of pins on an Uno: shift registers, I2C expanders, analog and I2C multiplexers, an LED PWM driver, and a 64-button control deck.

Take the course at /learn/path/more-pins-expanders. It is an intermediate course: it assumes the Uno course.

The lessons

Shift registers. A 74HC595 drives eight LEDs from three pins: shift, latch, bit order and chaining. A 74HC165 reads an eight-way DIP switch, and Arduino's shiftIn() loses its top bit because it clocks before it reads.

On the I2C bus. A PCF8574, where a byte is its pins, and an MCP23017 with direction and pull-up registers. A CD74HC4067 joining one of sixteen channels to A0, and a floating empty channel. A TCA9548A keeping two BME280s and two OLEDs with the same addresses apart, and the collision when two channels are on at once.

Drivers. A PCA9685 dimming four LEDs with 12-bit PWM at 1 kHz, a squared breathing wave, and why 50 Hz flickers.

Boss. A spaceship control deck: four 4x4 keypads, each scanned through its own PCF8574 at 0x20 to 0x23, sixty-four ship systems on two wires, and an all stop key.

The benches

Four lessons open gallery circuits: the bar chaser (a 74HC595 on DS 4, SHCP 5, STCP 6), the more pins board (an MCP23017 at 0x27 and a PCF8574 at 0x20), the mux knobs (a CD74HC4067 on S0 to S3 at 2 to 5, COM on A0) and the two OLEDs behind a TCA9548A. Three benches are the course's own: a 74HC165 and a DIP switch (PL 8, CP 9, Q7 into 10), a PCA9685 with four LEDs on PWM0 to PWM3, and the four keypads and four PCF8574s of the control deck.

What each sketch does

  • pin595: a pattern, then a bouncing dot, with shiftOut() and a latch.
  • pin165: a load pulse and shiftIn(), with a correct readByte() beside it.
  • pinexp: an I2C scan, PCF_PATTERN on the PCF8574, a button on GPB0 lighting GPA0.
  • pinmux: all sixteen channels scanned, three printed, channel 9 floating.
  • pintca: scans with no channel and each channel, then each BME280 read and shown on its own OLED.
  • pinpca: a 0, 25, 50 and 100 percent ladder at FREQ_HZ, then breathing.
  • pinboss: row-by-row scanning through each PCF8574 and a toggle per key.

Honest limits

  • The PCA9685 is used for LEDs only; servos are in the robotics course.
  • Drive limits (6 mA a 595 output, 25 mA a PCA9685 sink) are the datasheets'. Design to them; do not test them on the bench.
  • A floating mux channel here wanders by itself; on a real board it also picks up the last channel read and nearby noise.
  • The deck's keypads are scanned with no diodes, so three keys held on the corners of a rectangle on one keypad would ghost a fourth, as on a real one.

Buttons, encoders, keypads and touch for the keypad scanning the boss builds on, and Talk to chips for I2C and SPI themselves.