Lesson plan

More pins: expanders, muxes and drivers lesson plan

Run out of pins no more: 74HC595 outputs and 74HC165 inputs, PCF8574 and MCP23017 I2C expanders, a CD74HC4067 analog mux, a TCA9548A for twin addresses, PCA9685 PWM for LEDs, and a 64-button spaceship control deck.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Eight outputs and eight inputs on three pins each.
  • Expanders, an analog mux and an I2C mux.
  • Sixteen PWM channels that run themselves.
  • A spaceship control deck with sixty-four buttons on two wires.

Materials for the whole unit

  • 74HC165 input shift register
  • 74HC595 shift register
  • 8-resistor network
  • 8-way DIP switch
  • Arduino Uno R3
  • CD74HC4067 analog multiplexer
  • Full-size breadboard
  • Half breadboard
  • I/O expander, MCP23017
  • I/O expander, PCF8574 x 4
  • I2C multiplexer, TCA9548A
  • Keypad, 4x4 x 4
  • LED x 8
  • OLED display, 128x64 x 2
  • Potentiometer x 3
  • Pressure, humidity and temperature, BME280 x 2
  • Pushbutton
  • Resistor x 8
  • Servo driver, PCA9685 16-channel

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

Shift registers

Eight outputs and eight inputs on three pins each.

LessonTimeWhat students do
74HC595: eight outputs on three pinsA shift register drives eight LEDs from three pins: bits clocked in one at a time, a latch that changes all eight at once, bit order, and chaining for more.50 min
  1. Run it: a byte on eight LEDs
  2. Shift, then latch
  3. A scanner
  4. Bit order
  5. Chaining
74HC165: eight inputs on three pinsThe 595 the other way around: load eight switches at once, clock them out on one pin, and the shiftIn() bug that loses the top bit on this chip.50 min
  1. Run it: eight switches
  2. Load, then shift out
  3. The shiftIn() trap
  4. Read first, clock after
  5. More switches, still three pins

Materials

  • 74HC165 input shift register
  • 74HC595 shift register
  • 8-resistor network
  • 8-way DIP switch
  • Arduino Uno R3
  • Full-size breadboard
  • LED x 8
  • Resistor x 8

Check for understanding

Each student finishes "74HC165: eight inputs on three pins" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "More switches, still three pins".

Chapter 2. About 2 h 30 min

On the I2C bus

Expanders, an analog mux and an I2C mux.

LessonTimeWhat students do
I2C expanders: PCF8574 and MCP23017Extra pins on two wires: the PCF8574, where a byte written is its eight pins, and the MCP23017, with direction and pull-up registers like a real port.50 min
  1. Run it: two chips on the bus
  2. The PCF8574: a byte is the pins
  3. The MCP23017: a real port
  4. Your own pattern
  5. Choosing an expander
CD74HC4067: sixteen analog channelsAn analog multiplexer: four address lines pick one of sixteen channels and join it to one analog pin, so three knobs, or sixteen, share A0, and an empty channel floats.50 min
  1. Run it: three knobs on one pin
  2. Pick a channel
  3. Turn a knob
  4. An empty channel floats
  5. Print all sixteen
TCA9548A: same address, one busTwo sensors and two screens with the same I2C addresses kept apart by a TCA9548A: scans that see different chips on each channel, and what happens if two channels are on at once.50 min
  1. Run it: indoor and outdoor
  2. Scan each channel
  3. Cold outside
  4. Two channels at once
  5. When to use a mux

Materials

  • Arduino Uno R3
  • CD74HC4067 analog multiplexer
  • Half breadboard
  • I/O expander, MCP23017
  • I/O expander, PCF8574
  • I2C multiplexer, TCA9548A
  • OLED display, 128x64 x 2
  • Potentiometer x 3
  • Pressure, humidity and temperature, BME280 x 2
  • Pushbutton

Check for understanding

Each student finishes "TCA9548A: same address, one bus" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "When to use a mux".

Chapter 3. About 50 min

Drivers

Sixteen PWM channels that run themselves.

LessonTimeWhat students do
PCA9685: sixteen PWM channels for LEDsSixteen 12-bit PWM outputs on I2C: a prescaler for the frequency, on and off counts out of 4096, LEDs at four brightness levels, and a breathing wave that runs on its own.50 min
  1. Run it: four brightnesses
  2. On and off counts
  3. Full brightness
  4. A breathing wave
  5. Slow it down

Materials

  • Arduino Uno R3
  • Half breadboard
  • LED x 4
  • Resistor x 4
  • Servo driver, PCA9685 16-channel

Check for understanding

Each student finishes "PCA9685: sixteen PWM channels for LEDs" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Slow it down".

Chapter 4. About 1 h

Boss project

A spaceship control deck with sixty-four buttons on two wires.

LessonTimeWhat students do
Boss: a 64-button control deckA spaceship control deck with sixty-four buttons on two wires: four keypads, each scanned row by row through its own PCF8574, and every key a ship system that toggles.60 min
  1. Run it: the control deck
  2. Scanning through an expander
  3. Every key is a system
  4. Two decks at once
  5. All stop
  6. Feedback for every button

Materials

  • Arduino Uno R3
  • Half breadboard
  • I/O expander, PCF8574 x 4
  • Keypad, 4x4 x 4

Check for understanding

Each student finishes "Boss: a 64-button control deck" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Feedback for every button".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.