Receiving 5 volts as an input, and then sending 5 volts as an Output

Thank you, Grumpy_Mike. From your input and a little bit of research, it seems like that would be the best solution. I appreciate the idea; I wish I had your knowledge going into the project.

I am a bit disappointed that Arduinos cannot read two inputs simultaneously.. that bums me out a bit. I have no interest in trying port manipulation, like TomGeorge suggested.. I think I would break something ahaha.

I will do even more research into Shift Registers. I have already bought all the components I would need (I think), including the capacitors. When the time comes that I inevitably have more questions with my code, I will reach out.

Thanks again.

It can @TomGeorge told you about reading the port memory location but it is too complicated for you to understand.

But as I said you don't need to anyway, I don't know why you think you do.

Do you ever need to turn more than one relay on at any one time?

Hi,
How quickly do you need to update the data from UNO to Mega?

@Grumpy_Mike suggestion is good, in fact its the external hardware way of port manipulation.

If you understand registers, then go for it. It will mean some extra hardware, but a good learning curve.

Tom.... :grinning: :+1: :coffee: :australia:

In below (simple) example, your Uno will set the data on its pins based on received serial data. This only supports characters '0'..'9' (numbers 0..9). Once it has processed the received data (the for-loop in loop(), the Uno sets a pin HIGH telling the Mega that the data is valid.

const byte outputPins[] = {2, 3, 4, 5, 6, 7};
const byte strobePin = A3;

void setup()
{
  Serial.begin(115200);
  
  for (byte outputCnt = 0; outputCnt < sizeof(outputPins); outputCnt++)
  {
    pinMode(outputPins[outputCnt], OUTPUT);
  }

  pinMode(strobePin, OUTPUT);
}

void loop()
{

  // reset output pins
  for (byte outputCnt = 0; outputCnt < sizeof(outputPins); outputCnt++)
  {
    digitalWrite(outputPins[outputCnt], LOW);
  }
  // set strobe low
  digitalWrite(strobePin, LOW);

  // check if there is serial data
  if (Serial.available() > 0)
  {
    // read serial input;
    char ch = Serial.read();

    if (ch >= '0' && ch <= '9')
    {
      // convert to number
      ch -= '0';

      for (byte outputCnt = 0; outputCnt < sizeof(outputPins); outputCnt++)
      {
        if((ch & (1 << outputCnt)) == (1 << outputCnt))
        {
          digitalWrite(outputPins[outputCnt], HIGH);
          Serial.print("Pin ");
          Serial.print(outputPins[outputCnt]);
          Serial.println(" set to HIGH");
        }
      }

      // tell the Mega that the data is valid
      digitalWrite(strobePin, HIGH);
      Serial.println("Telling Mega that data is valid");
      // pulse for 50 milliseconds
      delay(50);

      // because loop() is called repeatedly, the next time that loop() is called, data and the strobe are removed
    }
  }
}

The last code in post #24 will be the companion. I've tested this Uno code.

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