Logical level of a pin not changing ?

Hello everyone, hope you're doing well!

I've connected an Arduino Nano RP2040 Connect as a slave device to an Arduino Uno which is acting as the master. Additionally, I’ve linked pin 4 on the Nano to pin 10 on the Uno. The purpose of this connection is to signal the master when the slave receives a new configuration via Wi-Fi.

Here’s how the process works:

  1. Slave Action: When the slave receives a new configuration, it sets pin 4 to HIGH.
  2. Master Action: The master periodically checks the status of pin 10. If it detects a HIGH signal, it understands that a new configuration is available.
  3. The master then communicates with the slave to retrieve the new configuration.
  4. After successfully reading the new configuration, the master sends an 'S' to the slave, indicating the completion of the process.

Problem: After this process is completed, I'm encountering an issue where I can't seem to reset pin 4 (on the slave) to LOW. It only stays LOW for a brief moment and then returns to HIGH. Here’s the code for the Arduino Uno (master) that handles this operation:

void ConfigObject() {
  int pinstate = digitalRead(10);
  if (pinstate == 1) {
    Serial.println("Reading Configuration");
    int totalBytes = 128;
    int bytesRead = 0;
    int chunkSize = 32;
    int index = 0;

    while (bytesRead < totalBytes) {
      int bytesToRequest = (totalBytes - bytesRead) < chunkSize ? (totalBytes - bytesRead) : chunkSize;
      Wire.requestFrom(8, bytesToRequest);

      while (Wire.available() && index < totalBytes) {
        char c = Wire.read();
        configobj[index] = c;
        index++;
      }
      bytesRead += bytesToRequest;
    }
    configobj[index] = '\0'; // Null terminate the message 
    newData=true;
    removeAsterisks(configobj);
  }
}

after this function is successfully executed, the master does this :

void  ConfirmerConfig() {
  Wire.beginTransmission(8);
  Wire.write('S');
  Wire.endTransmission();
  delay(300);
}

as for the receive function on the slave side :

void receiveEvent(int howMany) {
    // Read incoming data and store it in the buffer
    for (int i = 0; i < howMany; i++) {
        if (configIndex < MAX_BUFFER_SIZE - 1) { // Leave space for null terminator
            config[configIndex++] = Wire.read();
        } else {
            Wire.read(); // Read and discard the excess data
        }
    }
    // Null-terminate the string after the latest read data
    config[configIndex] = '\0';
    if(config[0]=='S') {
        Serial.println("configuration Done");
        udp.beginPacket(udp.remoteIP(), udp.remotePort());
        udp.write("Configuration done");
        udp.endPacket();

    digitalWrite(INTERRUPT_PIN, LOW);
    delay(300);
     int pinstate = digitalRead(4);
     Serial.println(pinstate);

    }
    configIndex = 0; // Reset index for the next message
}

as you can see here, i do set the pin to LOW but after the delay it still goes to high, although i clearly said in the setup that pin 4 is an output.

We should assume, then, that INTERRUPT_PIN has a value of 4? Why not then
digitalRead(INTERRUPT_PIN); just for consistency?

Share your full code, please, so we can, for example, verify there are no other actions setting/resetting the pin in question.

First roblem, your code doesn’t have a setup(), loop(), or main() function, so there’s no way it can possibly compile in the IDE.

There are other things missing, but you’ll get errors when you try to compile this code.

Maybe you can also show us a schematic with all the connections and power surly lines displayed,

this the master arduino code :

void setup() {
  pinMode(INTERRUPT_PIN, OUTPUT);
  Wire.begin(8); // Join I2C bus with address #8
  Wire.onReceive(receiveEvent); // Register event handler
  Wire.onRequest(requestEvent);
  Serial.begin(9600);
  digitalWrite(INTERRUPT_PIN, LOW); // Initialize pin to LOW
  }
  Serial.println("Access Point created");

  udp.begin(localPort); // Start UDP listener
}

void loop() {
  // Main loop does nothing, waiting for I2C events
  if(!isReadingDone) {
       RecupConfigObjet();
  }
  delay(100);
}

and this is the slave code :

void setup() {
pinMode(9, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(5, OUTPUT);
Wire.begin(); // Join I2C bus as master
Serial.begin(9600);
}

void loop() {
  ConfigObject();
    if (newData) {
        ConfirmerConfig();
        newData = false;  
    } 
}

and yes interrupt_PIN has a value of 4.

@adjedjou you're clearly an experienced programmer, and you've been here a while, so you should know by now that solutions very often lie in the 'dark corners' of people's codes, not where they think the problem lies. So, we ask for 'complete code'. That must include data definitions, #include statements for libraries, etc. etc. Anything that might give us a clearer picture of the whole project. Add to that schematics very often; in your case, as long as the two Arduinos have a common ground(please, say yes they do), we can probably dispense with the schematic until it is clear the code is correct.

1 Like

thank you all for your positive feedbacks, i could n t post the whole code cause it s too large, but i m managed to find the problem, i was working to improve an already existing platform for sensor measurements, in the provided files, it stated that he used SPI in arduino uno but with a diffirent SS (not the default one on D10, so i assumed i can use the D10), but for whatever reason, once i put the D10 on high it never goes down again, i just had to change the pin to D4 and it worked ( i have limited pins to work with )

I hope you realize that, for whatever reason, you have an unexplained code or hardware problem that you have masked by making whatever changes you made that you think 'fixed' the problem. So, it will return.
Good luck, see you soon!

1 Like

I just googled

spi owns pin 10 uno

Pin 10 is part of the hardware SPI. I have no energy for reviewing this thread to see if.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.