Skip to content

Problem with digitalRead #6

@pspastushkov

Description

@pspastushkov

Hi!

program code

#include <Wire.h>
#include <MCP23017.h>
#define i2c_mcp23017_ADDR_000 0x20
MCP23017 mcp23017_0x20 = MCP23017(i2c_mcp23017_ADDR_000);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mcp23017_0x20.init();
  for (uint8_t i = 0; i < 16; i++) mcp23017_0x20.pinMode(i, INPUT);
  Wire.beginTransmission(i2c_mcp23017_ADDR_000);
  Wire.write(0x02);
  Wire.write(0xFF);
  Wire.endTransmission();
  Wire.beginTransmission(i2c_mcp23017_ADDR_000);
  Wire.write(0x03);
  Wire.write(0xFF);
  Wire.endTransmission();
}

void loop() {
  if (mcp23017_0x20.digitalRead(2)) {
    Serial.println("pin2 = HIGH");
  }
  else {
    Serial.println("pin2 = LOW");
  }
  Serial.println(mcp23017_0x20.readPort(MCP23017_PORT::A), BIN);
  Serial.println(mcp23017_0x20.readPort(MCP23017_PORT::B), BIN);
  delay(1000);
}

COM port monitor

pin2 = LOW
10000000
10000000
pin2 = LOW
10000100
10000000
pin2 = LOW
10000100
10000100
pin2 = HIGH
10000101
10000100
pin2 = LOW
10000100
10000100

When inverted ports with any choice of pin (0-7 / 8-15), the condition is triggered when a signal is applied to 0 or 8, respectively.
Help me!

Pavel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions