Digispark ATtiny85
Digispark ATtiny85

Digispark ATtiny85 with MCP23016 GPIO Expander

by Lewis Loflin


This project connects a MCP23016 GPIO expander to a Digispark ATtiny85. Use the Arduino Nightly compiler and install the TinyWireM library. The original I2c on Arduino won't work.

See my YouTube video for this page: Digispark ATtiny85 with GPIO Expansion

Setup information from Digispark: How to connect ATtiny85.

I've kept a copy of the I2c TinyWireM library which is a zip file.

Support for the Arduino IDE 1.0+ (OSX/Win/Linux)
Power via USB or External Source
Onboard 5V Regulator
Built-in USB
6 I/O Pins
8k Flash Memory (about 6k after bootloader)
I2C and SPI (vis USI)
PWM on 3 pins (more possible with Software PWM)
ADC on 4 pins
Power LED and Test/Status LED

Pin outs: All pins can be used as Digital I/O

Pin 0 - I2C SDA, PWM
Pin 1 - PWM
Pin 2 - I2C SCK, Analog
Pin 3 - Analog In (also used for USB+ when USB is in use)
Pin 4 - PWM, Analog (also used for USB- when USB is in use)
Pin 5 - Analog In, default disabled, only for RESET You can 
check MCUSR and program different behaviar for power-on and 
reset button press PIN 0,1,2,GND,VCC are 
available to insert into breadboard

// 102 bytes
void setup() {
  // initialize the digital pin as an output.
  DDRB = DDRB | 0b00000010; // 2 bytes
  PORTB = PORTB & 0b11111101;  // 2 bytes

void loop() {
  // toggle pin 1
  PORTB = PORTB ^ 0b00000010; // 8 bytes
  // delay
  for (int i = 0; i <= 500; i++)   {
    // 1000 uSec = 1 mS
    delayMicroseconds(1000); // 72 bytes
  } // for loop 18 bytes

The above sketch uses direct port access to save memory. It blinks the on board LED on PB1.

To better understand Arduino port register commands see Arduino Port Registers Revisited

Digispark ATtiny85 I2C connections.
Digispark ATtiny85 I2C connections.

Also MCP23016 LEDs schematic. Also MCP23016 spec sheet.

   Count binary port 0 MCP23016 with 8 LEDs

#include <TinyWireM.h>

// MCP23016 Address
uint8_t MCP23016_add = 0x20;
// must use the uint8_t !
uint8_t i;

void setup() {

  TinyWireM.send(0); // port 0 output
  TinyWireM.send(0xFF); // port 1 input
  // setup PBO for output
  DDRB = DDRB | 0b00000010; // 2 bytes

void loop() {

  for (i; i <= 255; i++)   {

    PORTB = PORTB ^ 0b00000010; // 8 bytes

See How I got into Electronics