Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: MCP23017 using encoder

  1. #1
    Senior Member
    Join Date
    Oct 2015
    Posts
    227

    MCP23017 using encoder

    I've got an MCP23017 wired up to my bread board and it is working fine with push buttons.

    A lot is on the internet about getting encoders to work with an MCP23017. Most have not had any luck in getting an encoder to work with the MCP.

    While I don't have get my encoder to work with an MCP either as I have enough pins on my Teensy 3.6 to wire it up that way and make it work, I thought I'd try a little bit more just for the education of it and see if I'm close to getting it to work.

    What I see if I turn my encoder knob cw or ccw is unreliable click results. I'm printing out 'left' and 'right' and I see mixed results. Pretty much what others have reported when they have tried to do this.

    However, if I slowly try to turn the knob to the right and hold it there and don't complete the click, I can see 'right' being printed out in the output window repeatedly...thus showing (initially) correct sensing...as long as I don't compete the click. Same for turning to the left...I can just start to turn the knob ccw and hold it there and watch the stream of 'left' display on the output window.

    I'm wondering if I can detect that first initial turn in my code below and thus obtain correct directional sensing?

    Code:
      // Loop block
      // MCP23017 Chip #2 -----------------------------------------------
      Wire.beginTransmission(mcp2_address);
      Wire.write(GPIOA);                 // set pointer to bank A pins
      Wire.endTransmission();
      Wire.requestFrom((int)mcp2_address, 1); // request one byte
      while(Wire.available())            // slave may send less than requested
      { 
        c =~( Wire.read());              // receive a byte as character
      }
      delay(25);
      checkKeyPress_MCP2_BankA(c);
      Wire.beginTransmission(mcp2_address);
      Wire.write(GPIOB);                 // set pointer to bank B pins
      Wire.endTransmission();
      Wire.requestFrom((int)mcp2_address, 1); // request one byte
      while(Wire.available())            // slave may send less than requested
      { 
        c =~( Wire.read());              // receive a byte as character
      }
      delay(25);
      checkKeyPress_MCP2_BankB(c);
      // MCP23017 Chip #2 -----------------------------------------------

    Code:
    void checkKeyPress_MCP2_BankA(byte c)
    {
      switch(c)
      {
       case 2:
    	   Serial.println("left");
          break;
      }
    }
    
    void checkKeyPress_MCP2_BankB(byte c)
    {
      switch(c)
      {
       case 128:
    	   Serial.println("right");
          break;
      }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Posts
    188
    Hi, there is any update on this?
    i'm also interested, thanks

  3. #3
    Senior Member
    Join Date
    Oct 2015
    Posts
    227
    I could not get my Prop Wash dual rotatory encoder to work via the MCP chip.

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Posts
    188
    this is a bad news...

  5. #5
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Location
    Florida
    Posts
    465
    If you really need to you can run multiple encoders through some multiplexers with really no problems as long as your sketch repeats fast enough.

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,206
    mcu pins and interrupts are definately faster than the MCP23017, if you want performance, go direct, or use an MCP23S17 (SPI), be sure to use itís interrupt line for fast responses as well

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •