MCP23017 GPIO Control Via Ethernet
by Kallio Designs in Circuits > Remote Control
1747 Views, 1 Favorites, 0 Comments
MCP23017 GPIO Control Via Ethernet
Control MCP23017 IO-extender via ethernet using Sensor Bridge and MCP23017 break out board. Commands sent by Python scripts, browser URLs or any system capable of HTTP communication. Can be integrated to Home Assistant for home automation.
Wires are connected to Phoenix Connector clamp connectors. GPIO states are indicated by LEDs. Address is selectable from 0x20 to 0x27. GPIO BoB can be mounted on a DIN rail. Sensor Bridge has mounting flanges.
Supplies
Kallio Designs - Sensor Bridge Digital (Ethernet to I2C):
https://kalliodesigns.com/product/532003/
Kallio Designs MCP23017 Break out Board (I2C GPIO BoB):
https://kalliodesigns.com/product/532013/
8 - 26 V, 2 W Power supply
Ethernet cables
Connections to Ethernet to I2C Sensor Bridge
Connect pins 3 and 4 to SCL and SDA pins on the MCP23017 break out board for I2C bus.
Connect pins 5 and 6 to +5 V and GND pins on the MCP23017 break out board. This will provide power for the unit.
Connect Ethernet and Provide Power
If you have power over ethernet (PoE) available, just connect the ethernet cable. You can also use an injector. Both units should power up, standard PoE interfaces can power up both units.
If you don't have PoE, connect the ethernet cable and 8-26 V, 2 W power supply to pins 1 (GND) and 2 (Positive voltage).
You should see the green indicator LED lit as well as the ethernet port LEDs indicating traffic.
Setting Up
Make sure your PC or other control device is within the same LAN network as the Sensor Bridge.
Use the dip switches on the break out board to set the I2C address (default hex 0x20, which translates to decimal 32).
Commands are described in Sensor Bridge user manual. Simple option is to use the built in -commands, to avoid having to set several registers for the functions.
Browsing to "192.168.1.195/MCP27OA41" will set the pin A4 to high. You will see LED A4 lit on the right hand side LED banks.
Browsing to "192.168.1.195/MCP27IA4" will read the same pin and display it's state on the browser. LED will also be lit if the pin is set high externally.
Scripting With Python or Other Languages
To build more logic to the project you can use Python urllib to send commands. To read pin A4 state:
import urllib.request
print(urllib.request.urlopen("http://192.168.1.190/MCP27IA4").read())
input("Press enter to exit")
Or you can use curl to use the I2C interface directly. To set all pins in port A as output:
curl 192.168.1.195/I2CSTA027
curl 192.168.1.195/I2CW00
curl 192.168.1.195/I2CW00
curl 192.168.1.195/I2CSENDS
Same commands can be sent from any interface with same results, which ever suits your project best.