0

I'm working on a program which listens for certain bytes on serial through an if/then/elseif ladder. I want to also check if a pin (say, A15) has been given a HIGH state, by another Arduino with shared ground. The slave Arduino will turn a digital pin to HIGH and I want the MEGA2560 to check every time it loops if a HIGH is present from the other board. A "While button not pressed do nothing statement won't work, because that won't let the loop go. I tried doing an if statement, using something to the effect of this:

if (digitalRead(A15)==HIGH) {
  //things to do
}

But it seems no matter what I put, be it HIGH, LOW, != HIGH, != LOW, etc. or either input pinmodes, pullup or not, it always thinks the board is transmitting HIGH. In fact, it only doesn't think it's HIGH when it actually is HIGH. I'm pretty stumped on this. If you ask me, digitalRead is really odd with what's HIGH and what's LOW.

4
  • Do you declare A15 as INPUT in Setup(), pinMode(A15, INPUT);? Could you show us the entire sketch you are using?
    – VE7JRO
    Apr 12, 2019 at 0:27
  • 1
    I tried both that and input_pullup as well. I can include the whole sketch. EDIT: Actually ,unfortunately, I just looked and it looks like, because the previous sketch bricked the board, I edited it back to before this was added and neglected to save a copy of the broken code.
    – SYGMAH
    Apr 12, 2019 at 0:31
  • Do you have a custom atmega2560 pcb or a real arduino mega 2560 board or a clone? Maybe some gnd or vcc pins of the atmega2560 are not soldered. Is the arduino mega 2560 running at 5.0v? It starts to do weird things at 4.5v or lower.
    – Jot
    Apr 12, 2019 at 1:59
  • It's an Elago clone of the MEGA2560 board. I have it connected to a desktop's USB port, so I doubt there's power failure.
    – SYGMAH
    Apr 12, 2019 at 13:34

1 Answer 1

1

Simplify, and show your setup code.

First, do you have a pinMode call in your setup function:

void setup() {
  pinMode(A15, INPUT_PULLUP);
  Serial.begin(115200);
}

Then use test code like this:

void loop() {
   if (digitalRead(A15) == HIGH) {
      Serial.println("Pin A15 is HIGH");
   } else {
      Serial.println("Pin A15 is LOW");
   }
}

Connect your A15 pin directly to ground with a jumper and run the sketch above. Open the serial monitor and see what is output. It should be LOW. Then disconnect the jumper and check again. It should now be HIGH. Finally, connect the jumper between A15 and +5V and check the output again. It should still show HIGH.

That lets you troubleshoot just the software piece. Once you get that working, connect pin A15 to the remote Arduino's output pin and try again.

1
  • I'll try this as soon as I get to the board tomorrow.
    – SYGMAH
    Apr 12, 2019 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.