Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting (digitalWrite) pin y, unsets pin x #102

Open
FunDeckHermit opened this issue Jul 23, 2024 · 1 comment
Open

Setting (digitalWrite) pin y, unsets pin x #102

FunDeckHermit opened this issue Jul 23, 2024 · 1 comment

Comments

@FunDeckHermit
Copy link

  • Arduino board: Custom board

  • Arduino IDE version (found in Arduino -> About Arduino menu): PlatformIO

  • List the steps to reproduce the problem below:
    Run below sketch, it is expected that pin5 is toggling every 2 seconds.
    It will however prematurely turn off setting another pin.

#include <Arduino.h>
#include <Adafruit_MCP23X08.h>

Adafruit_MCP23X08 mcp;
TwoWire my_wire(0);

void setup()
{
    Serial.begin(460800);

    my_wire.setPins(5,6);
    mcp.begin_I2C(0x27, &my_wire);
    mcp.pinMode(5, OUTPUT);
    mcp.pinMode(6, OUTPUT);
}

void loop()
{
    delay(2000);
    digitalWrite(1, HIGH);
    mcp.digitalWrite(6,LOW);
    
    delay(2000);
    digitalWrite(1, LOW);
    mcp.digitalWrite(6,HIGH);
    
    mcp.digitalWrite(5,HIGH); //This write also sets pin6 low ???
    delay(50);
    mcp.digitalWrite(5,LOW);
}
@xKaimac
Copy link

xKaimac commented Aug 5, 2024

I'm having the same issue with a MKRWAN 1310.

With the following setup function I have no trouble:

#define MCP_I2C_ADDRESS 0x21
#define RESET_PIN = 4;
#define RELAY_ONE = 12;
#define RELAY_TWO = 13;
#define I2C_DIGITAL_PIN = 7;
#define INPUT_ONE = 0;

void setup() {
  Wire.begin();

  mcp.begin_I2C(MCP_I2C_ADDRESS);

  pinMode(RESET_PIN, OUTPUT);  
  digitalWrite(RESET_PIN, HIGH);

  mcp.pinMode(RELAY_TWO, OUTPUT);
  mcp.pinMode(RELAY_ONE, OUTPUT);

  pinMode(I2C_DIGITAL_PIN, INPUT);
  mcp.pinMode(INPUT_ONE, INPUT);
}

But if I set all of the pins before writing, ie:

  pinMode(RESET_PIN, OUTPUT);  

  mcp.pinMode(RELAY_TWO, OUTPUT);
  mcp.pinMode(RELAY_ONE, OUTPUT);

  pinMode(I2C_DIGITAL_PIN, INPUT);
  mcp.pinMode(INPUT_ONE, INPUT);
  
  digitalWrite(RESET_PIN, HIGH);

I have issues with the Arduino going into a boot loop (in my case it's the RESET_PIN being pulled low). I've reduced it down to only being the RELAY_ONE setting (12 in this library) that throws it all out of whack, the other ones are fine. This issue can be reproduced with any available digital pin for bridging the RESET_PIN in my case, not just digital pin 4.

I don't have a robust solution for you as I'm unsure what's causing this, but play around with the order in which you set pins and you might find one that gives you the desired result. Hopefully there's a patch or explanation for it eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants