I bought a MCP23017 for my Raspberry Pi to increase the GPIO pins.
I have currently installed it and I'm trying to get the extra pins that I have; GPB0-GPB7 on the left and GPA0-GPA7 on the right to do my bidding.
I need to set them to input pins to read a HIGH and LOW status, and add the pull up resistors to them but this is as far as I have gotten:
import smbus
import time
bus = smbus.SMBus(1) # As I'm using an newer RPi.
DEVICE = 0x20 # this is what it shows when I check it.
IODIRA = 0x00
GPIOA = 0x12
bus.write_byte_data(DEVICE,IODIRA,0xFF)
bus.write_byte_data(DEVICE,0x0C,0xff)
value = bus.read_byte_data(DEVICE,GPIOA)
When I try to read the value, it gives me strange numbers, and I can barely find any explanation on the Hexidecimals ans the Binary numbers and it's compeltly throwing me off. The datasheet seems like Chinese to me..
Any help would REALLY be appreciated!
This script will turn on the internal pull-up resistors for GPIOA and GPIOB. Then it will print the values of all the registers once per second. You can use the output to watch the register values change as you change the inputs.
Example Output
I am using the MCP23017 on an Adafruit LCD Keypad Kit, so some of the pins are being pulled low by the board.
Understanding the Port Values
Each port has 8 GPIO pins. If all pins for a port are pulled high, the hex value for the port will be 0xFF. If a pin is pulled low, the bit for that pin will be zero. For example, if GPA0 is pulled low, the GPIOA register will have a value of 0xFE: