Running MCP23017 via I2C on ESP-01

Posted on
  • Hello Forum,

    I'm having trouble getting the MCP23017 to work with my ESP-01 running Espruino v87.

    I'm using D2 for data and D0 for clock. This is the code I'm using to set up the connection:

    I2C1.setup({scl:D2, sda:D0});
    mcp = require("MCP23017").connect(I2C1, null, 0x20);

    If I try to send commands to the MCP, e.g. "mcp.A0.mode("output")" I get the "I2CWrite: No ACK" error. I searched the forum and google to find a solution. I tried to use Nodemcu.D2 e.g. instead of D2, changed the frequency to 80MHz of the ESP, but nothing seems to work.

    The wiring should be fine too, I have some C-Code doing some things with the MCP and that one worked, at least i could turn the ports of the MCP on and off. I've also added the 10K resistors on both pins, even though it was working without too, but that didn't help either...

    The only thing I didn't try yet is connecting the reset pin. Everything's already soldered up and it's kinda difficult to change that now. But I tried removing the MCP and putting it back on, it's not directly soldered...

    The address should be fine too, used it in the C-Code as well and "I2C.find(I2C1)" gives me Undefined...

    Do you have any suggestions what I'm doing wrong here?

  • ...not much than just to get the confirmation from you that you worked through the forum conversation titled 'please name the i2c devices you have tested or using'... :(

  • Yeah, I've already read that thread and tried the suggested solutions, but none of them work... It's really frustrating :/ But obviouly D0 and D2 seem alright, since Frida got them to work too...

  • Are those GPIO0/GPIO2 or NodeMCU's D0/D2 pins?

    I can never keep straight which one you get when you call the pins "D0" - I just call them by the number and there's no confusion.

    GPIO2 is the TX for the second uart, and I think by default debug output is printed to there. Did you turn off the debug output?

  • Thanks a lot for your answers guys, but nothing worked yet.

    Since it's an ESP8266 ESP-01 it should be GPIO. In the reference it says, that GPIOx maps to Dx, so I think that using D0 and D2 is alright. I also tried it with new Pin(0) and (2) but that didn't work either (and is deprecated).
    I also tried deactivating the debug output, but no change either. Plus I've read a few times, that it "should" be deactivated in newer builds by default.

    I once again tried my C-Code, because I feared that I made a mistake soldering the 10k resistors, but it's still working. So somethings wrong with my code, even though it's only 3 lines of code.

  • Ok, I just tried to use the ports D1 and D3 which are usually used for the serial communication. But I didn't have any luck either. Is there something I have to call to deactivate the serial stuff and use it for I2C? I called Serial1.setConsole(); but that didn't change anything.

  • Have you tried setting pinMode explicitly first? I had issues with this a long time back - I don't know if still a requirement, but a lot of my code for ESP8266 sets it anyway.

  • Just tried to set them to output, but nothing changed... It's so frustrating. Like, if it's working with C-Code, the wiring should be ok no? Feels like I'm missing a crucial detail, but can't find it. Basically, all I should have to do is setup the I2C via I2C1.setup({scl:D2, sda:D0}) and then via I2C.find(I2C1) I should be able to find the MCP or at least get something back, other than "undefined".

    EDIT: Just swapped the MCP to make sure, I wasn't using a faulty device... But not working either...

    Is there something I forget, what I need to setup the ESP properly? Similar things to setting the frequency as an example?

  • I can imagine. There's always a chance something got broken in the builds I guess. You are using a recent version, have you flashed any older versions just to sense check?

  • I had the 1v86 flashed first and now 1v87. I'll study the changelogs and see if something was changed concerning I2C. If I find something, I'll go back to that version.

    Thanks so far

  • Make sure you turn the debug output off. esp8266.setLog(0) or esp8266.logDebug(false)
    I use an MCP23008 just fine, but not on gpio0 or gpio2...

  • Mhmmm... yeah tried that in various combinations but nothing worked so far. I also tried LoopbackA.setConsole(). And I also tried using D1 and D3 instead of D2 and D0. Those are the serial port pins, but they also didnt work....

    I'm kinda out of ideas and it feels like I've tried everything I can think of. Maybe I'll just do it in C....

    Anyways, thank you a lot for your help. Tell me if you have another idea though, I'd love to try it out. It would still be great if I can swap it one day to Espruino, thanks a lot for Espruino :)

  • @Timothy3001

    ok - you are running Espruino 1v86 on ESP01 and have D0 and D2

    try this

    var ESP8266 = require("ESP8266")
    I2C1.setup({scl:D2, sda:D0}) ;
    mcp = require("MCP23017").connect(I2C1, null, 0x20);
    // and your code

    check i2cdetect to find a i2c device on the bus

  • Ok thank you, will try that :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Running MCP23017 via I2C on ESP-01

Posted by Avatar for Timothy3001 @Timothy3001