I have an esp32 and I wanted to create a simple alarm for my house using MQTT, but I needed more available inputs for hardwired switches. The MCP23107 seemed like a good option, unfortunately I haven't found much of a beginners friendly solution that works. This is the only thing that worked for me once, but I have no idea how i got it to work

https://github.com/ShrimpingIt/micropython-mcp230xx
This is just a basic example:
Code: Select all
import mcp
import machine
import time
io = MCP23017()
inPins = list(range(0,8))
for pinNum in inPins:
io.setup(pinNum, mcp.IN)
while True:
time.sleep(1)
print(io.input_pins(inPins))
>>> %Run example_mcp.py
Traceback (most recent call last):
File "/home/Downloads/micropython-mcp230xx-master/example_mcp.py", line 6, in <module>
NameError: name 'MCP23017' isn't defined
Any suggestions or pointers are appreciated, if anyone has an example code using this library I would love to see it (or similar). I'm a mechanic and not a programmer, please go easy on me.