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

Thread: Teensy 3.2 - Wrong (?) readings from mcp23017/i2c

  1. #1

    Teensy 3.2 - Wrong (?) readings from mcp23017/i2c

    Hello guys, I'm trying to read pin status of a mcp23017 in one shot using the Adafruit_mcp23017 library (https://github.com/adafruit/Adafruit...rduino-Library);

    The sketch:

    Code:
    #include <Adafruit_MCP23017.h>
    
    /* Our I2C MCP23017 GPIO expanders */
    Adafruit_MCP23017 mcp;
    
    
    void setup() {
      Serial.begin(9600);
      Serial.println("MCP23007 testbuttons ...");
      //
      mcp.begin();
      Wire.setClock(100000);
      // setup pins, pullup resistor and INPUT
      for (int i = 0; i < 15; i++) {
        mcp.pinMode(i, INPUT);
        mcp.pullUp(i,HIGH);
      }
    }
    
    void loop() {
      int i = 0;
      delay(50);
      // all pins in one shot
      uint16_t pins = mcp.readGPIOAB();
      // GPA
      uint8_t pinA = mcp.readGPIO(0);
      // GPB
      uint8_t pinB = mcp.readGPIO(1);
      Serial.println("Read: " + String(pins)+ "/"+ String(pins, BIN)+ " : A: "+String(pinA)+"/"+String(pinA, BIN)+ " : B: "+String(pinB)+"/"+String(pinB, BIN));
      
    }
    Result: 32767/111111111111111 : A: 255/11111111 : B: 127/1111111

    Am I wrong or it should be 65535 ? Also B should be 255..

    I tried 2 IC, one normal size on a breadboard and one on small board with the smd version.

    Thanks,
    Daniele.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,187
    Actually, you are driving only 15 mcp input pins (0 to 14) high with your pull-up configuration which would explain the missing bit:
    Code:
      // setup pins, pullup resistor and INPUT
      for (int i = 0; i < 15; i++) {
        mcp.pinMode(i, INPUT);
        mcp.pullUp(i,HIGH);
      }
    Try instead :
    Code:
      // setup pins, pullup resistor and INPUT
      for (int i = 0; i < 16; i++) {
        mcp.pinMode(i, INPUT);
        mcp.pullUp(i,HIGH);
      }

  3. #3
    Quote Originally Posted by Theremingenieur View Post
    Actually, you are driving only 15 mcp input pins (0 to 14) high with your pull-up configuration which would explain the missing bit:
    No words.. It is incredible the time that is lost for stupid mistakes

    Thank you !

    Daniele.

Posting Permissions

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