![]() Wire.write(0x13) //selects the GPIOB pins Wire.endTransmission() //ends communication with the device Wire.write(00000011) // turns on pins 0 and 1 of GPIOA Wire.write(0x12) //selects the GPIOA pins Wire.beginTransmission(0x20) //starts talking to slave device Wire.endTransmission() //ends communication with slave device Wire.write(0x00) // sets all port B pins to outputs Wire.write(0x01) //selects the IODIRB register Wire.beginTransmission(0x20) //begins talking again to slave device Wire.endTransmission() //stops talking to device Wire.write(0x00) //this sets all port A pins to outputs Wire.write(0x00) //selects the IODIRA register Wire.beginTransmission(0x20) //begins talking to the slave device The code so that we can connect an MCP23017 I/O port expander to an arduino microcontroller to turn on LEDsĪrduino's I 2C communication library is called the Wire library. Later on in our code, this will be important for addressing this MCP23017 chip. This makes the address of these 3 pins 000. If you want to reset all the outputs, thenĪnd we connect the address pins, pins A0, A1, and A2, to ground. ![]() However, if you want to use this pin, you simply connect it to a digital pin on the arduino. This allows data transfer between the arduino and the I/O port expander chip.īeing that we're not working with interrupts, we leave INTA and INTB unconnected.īeing that we don't want to use the RESET pin, we connect it to +5V, since it's active LOW. We connect pin 13 of the MCP23017, which is the SDA (serial data line) to analog pin 4 of the arduino. This allows the clock synchrony from the arduino to the I/O port expander chip. We connect pin 12 of the MCP23017, which is SCL (serial clock line) to analog pin 5 of the arduino. We leave the 2 NC (Not Connect) pins unconnected (or floating). This establishes power to the MCP23017 chip. To power the pin, we attach +5V to V DD and connect V SS to GND. To each of the I/O pins, we attach a 220Ω resistor and an LED. In this circuit, the hardware connections are very simple. The MCP23017 I/O port expander circuit we will build with an Arduino microcontroller is shown below. MCP23017 I/O Port Expander Circuit with an Arduino Microcontroller This way, you will be able to uniquely address each of them. Up to 8 MCP23017s, you will need to configure these pins so that each has a unique address: 000, 001, 010, 011, 100, 101, 110,ġ11. Being that we are grounding all 3 pins, the address will for the address pins will be 000. For example, if I grounded A2 and A1 and held A0 HIGH, this would create Multiple ICs, so that we can distinguish between them. This is only necessary if you are connecting There are 3 pins, you can create a total of 8 different addresses (2 3=8). These pins are externally biased, meaning you provide voltages to them to create different addresses. You only need be concerned about these pins if you are using multiple This pin, we connect it permanently to +5V.Ī0, A1, and A2 are the address pins. The RESET pin is if you want the outputs all reset to 0. Being that we are not going to use them here, we just leave INTA and INTB are interrupt pins for the outputs. It connects to analog pin 4 on the arduino, which is the analog data line. It connects to analog pin 5 on the arduino, which is the analog clock pin. NC is Not Connected so we leave that unconnected (or floating). The GPB0-GPB7 and the GPA0-GPA7 are the 16 I/O ports. This completes the powering that's necessary for the Therefore, we can connect V DD to theĥV terminal of the arduino. The pinout of the MCP23017 is shown below. The datasheet for this chip can be found at the following link: It is a perfect addition to a microcontroller where more I/O ports are needed. The MCP23017 I/O port expander can be obtained for a little over $2. If you need more current you can always use a transistor to get more, but for this circuit,īeing that an MCP23017 contains 16 outputs, we can drive 16 LEDs with it. Each of the ports can sink up to 25mA of current, so this is enough to drive certain devices So the device attached to one of the ports can both receive and send The 2 pins that it uses are for the clock line and data line.Įach of the I/O ports are bidirectional. So it uses a very minimal number of I/O pins for communication. So onlyĢ digital pins on the arduino need to be used. The MCP23017 chip uses the I 2C bus and protocol. Just using 2 pins on the microcontroller. The MCP23017 chip will let us have an additional 16 I/O ports simply by If we need more inputs or outputs to a microcontroller, we canĮxpand the number of I/O ports with an I/O port expander chip. This is a very useful thing to do if we need additional I/O ports for a microcontroller. In this project, we will show how to connectĪn MCP23017 I/O port expander chip to an Arduino microcontroller. How to Connect an MCP23017 I/O Port Expander to an Arduino
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |