Arduino Forum

Using Arduino => Storage => Topic started by: Taskmgr on Oct 22, 2020, 01:15 pm

Title: Two Arduinos
Post by: Taskmgr on Oct 22, 2020, 01:15 pm
Is it possible to connect two different Arduino UNOs to each other in a way that they will display only one Serial Port while being able to run two different loops?

More detail: I'm writing some data to an SD card. But I need two different data from two different loops and I don't want to use two different SD modules and two SD cards, I want them to record in one single card. Is such thing possible? Or could I perhaps use one SD module and parallel connect it to two Arduinos, gathering data simultaneously?

Thank you.
Title: Re: Two Arduinos
Post by: wildbill on Oct 22, 2020, 02:28 pm
You could connect the two Unos using softwareSerial and have the device with the SD card tell the other Uno what it read.

But if you can do that, then perhaps you can read the data from two files and have a single Uno do the processing. It's not clear to me why you need two Unos.
Title: Re: Two Arduinos
Post by: sterretje on Oct 22, 2020, 08:56 pm
Why can't your two different loops not run on one Arduino?
Title: Re: Two Arduinos
Post by: Taskmgr on Oct 23, 2020, 04:54 pm
Because I read that it is not possible to run two different loops in one Arduino UNO. Isn't that right?
Title: Re: Two Arduinos
Post by: wildbill on Oct 23, 2020, 04:57 pm
You can't have multiple functions called loop. You can have more than one thing invoked from your loop function though.
Title: Re: Two Arduinos
Post by: CrossRoads on Oct 23, 2020, 05:19 pm
Or make loop-like functions:
Code: [Select]

void loop(){
// maybe read a pin?
  if (digitalRead(pinX) == HIGH){
  loop1();
  }
  else { // pin is LOW
  loop2();
  }
}

void loop1(){
// do whatever
}

void loop2(){
// do whatever
}