Page 1 of 1

MCP23017

Posted: Mon Jun 24, 2019 3:36 am
by FoolyCooly
I'm very new to programming and I apologize if this is seems rather basic, but I'm trying to learn new things. Thank you for any help in advance.

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 :lol: .

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))
I only get this back now...

>>> %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.

Re: MCP23017

Posted: Mon Jun 24, 2019 5:45 am
by Roberthh
This line:

io = MCP23017()

should be:

io = mcp.MCP23017()

Re: MCP23017

Posted: Mon Jun 24, 2019 6:23 am
by FoolyCooly
Well that was pretty dumb of me, thank you for taking the time to help, I don't even know how I did that. :lol: It works now

I will try my best not to ask anything this basic again.