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:
- Slave Action: When the slave receives a new configuration, it sets pin 4 to HIGH.
- 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.
- The master then communicates with the slave to retrieve the new configuration.
- 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.