Effects are only limited by one’s imagination. So lets start dancing in this LED forest.
To wire the cube to your Breadboard, MCP23017 chip and Arduino, connect the following pins:
We will use the first six pins of MCP23017 GPIO B bank, and the last six pins of MCP23017 GPIO A bank to control the LED signals:
- Pin Header 1 ⇔ MCP23017 Pin 4
- Pin Header 2 ⇔ MCP23017 Pin 5
- Pin Header 3 ⇔ MCP23017 Pin 6
- Pin Header 4 ⇔ MCP23017 Pin 23
- Pin Header 5 ⇔ MCP23017 Pin 24
- Pin Header 6 ⇔ MCP23017 Pin 25
- Pin Header 7 ⇔ Breadboard Vss
- Pin Header 8 ⇔ 1kohm ⇔ MCP23017 Pin 3
- Pin Header 9 ⇔ 1kohm ⇔ MCP23017 Pin 2
- Pin Header 10 ⇔ 1kohm ⇔ MCP23017 Pin 1
- Pin Header 11 ⇔ MCP23017 Pin 26
- Pin Header 12 ⇔ MCP23017 Pin 27
- Pin Header 13 ⇔ MCP23017 Pin 28
(see the side photo for the Pin Header ids.)
Set MCP23017 Address and Reset:
- MCP23017 Pin 15 ⇔ Breadboard Vss
- MCP23017 Pin 16 ⇔ Breadboard Vss
- MCP23017 Pin 17 ⇔ Breadboard Vss
- MCP23017 Pin 18 (Reset) ⇔ Breadboard Vdd
Communication between Arduino and MCP23017:
- Arduino A5 (SCL) ⇔ MCP23017 Pin 12
- Arduino A4 (SDA) ⇔ MCP23017 Pin 13
Power the Breadboard and the MCP23017:
- MCP23017 Pin 9 (Vdd) ⇔ Breadboard Vdd
- MCP23017 Pin 10 (Vss) ⇔ Breadboard Vss
- Arduino 5V ⇔ Breadboard Vdd
- Arduino GND ⇔ Breadboard Vss
The rest of the pins are not connected (NC).
The three 1Kohm resistors should be placed between Pin Headers 8, 9, 10 and the appropriate MCP23017 Pins (3, 2, 1 respectively.)
Instructions and Code
The Pin Headers 8, 9 and 10, control the cube levels (or floors if you prefer), while the Pin Headers 1-6 and 11-13 control the (nine) columns.
We can control which LED is on by setting the appropriate level and column on.
You will need the Wire library to speak to the MCP23017 chip with Arduino.
The MCP23017 address is defined by the MCP_ADDR constant, which is set to the default 0x20. Same applies for the GPIO A and B bank addresses, defined by the GPIO_A and GPIO_B constants respectively.
The LVL_x and COL_xx constants map the pin of the MCP23017 chip, to the appropriate IO bank that controls the ‘x’ level or ‘xx’ column.
Columns have two id-numbers, because they are thought as a two-dimensional matrix on the perfboard. COL_00 is the lowest left column on the perfboard, COL_01 is the lowest center column and COL_22 is the highest right column etc.
NOTE: depending on how the cube was built, you may need to change the values of LVL_x and COL_xx constants. Their values are eight binary – 0 or 1 – numbers. Each of them represents the values of all the pins of the GPIO bank that the pin belongs to. For example, COL_00 belongs on GPIO B bank, and its value is ‘0b00100000’. This means that when one sets the COL_00 pin, then all pins of GPIO B bank are zeroed, except for pin 3/GPB2 which is set to ‘1’ (counting right to left on the binary value.)
Levels and columns are packed into arrays for convenience in iterating over them.
We also have two helper functions that return information on whether the MCP23017 chip is found and on what address and print the GPIO banks’ state given the appropriate GPIO bank (either ‘gpio_a’ or ‘gpio_b’.)
First thing we need to do is initialize the Wire library, set the GPIO pins to output pin-type and clear their state.
We now have a clean, ready-to-use MCP23017 chip, waiting our instructions.