Mega need to receive INT data from multiple Nano at a time

hi all,
i am on the project of a race timer. having 2 timers in it. Mega is in main unit and 2 Nanos are at end. Nano are working for P10 module as stopwatch. using RS485.
Mega starts the race. Both P10 module are running.
My issue is, while both players tapped the touchpad near P10 module, timing needs to come to Mega for display.
getting fustraited.
I am using softwareserial library

Mega code;
digitalWrite(timer_1_pin, LOW);
timer_1_Serial.listen();
if (timer_1_Serial.available()) {
  timer_1 = timer_1_Serial.parseInt();
  Serial.print("Timer 1 : "); Serial.println(timer_1);
}
digitalWrite(timer_2_pin, LOW);
timer_2_Serial.listen();
if (timer_2_Serial.available()) {
  timer_2 = timer_2_Serial.parseInt();
    Serial.print("Timer 2 : "); Serial.println(timer_2);
}

Nano code; (both nano same code)
digitalWrite(timer_pin, HIGH); timer_Serial.print(testTimer); delay(10); digitalWrite(timer_pin, LOW);

any Nano gets trigger any time. atfer triggered by touchpad, timing should come to Mega immediately.
not getting it....

help me please
TIA.

Software serial can only work one channel at a time. The Mega has three free serial hardware channels plus the console, why not use them. Also post a schematic showing exactly how this is wired and note any wires over 10" in length. Why separate units, the Mega should be able to process two channels.

Without seeing the rest of your code, I bet you are invokiing software serial twice in your program. Only the LAST one invoked will be active. There is only a single software serial possible at a time. Why not use a hardware serial port?

its a timing device for race. Mega is used with btns like start, reset etc with plug and play tft screen. 2 Nanos with P10 modules are at endpoint of race. Communication is through RS 485, because of distance is 30 mtrs.
when i am calling timing by pressing btn or coding from 1st, it comes. when calling from 2nd, it comes.
but my issue is why to call seperately ?
aftering triggering touchpads at both endpoints, Timings should come automatically, whichever is first or second.

i am trying to code on this line "timing should come immediatelly after hitting touchpads, in any sequence."

is it clear ?

u r correct. the last one invoked is active.
thats why, i am using xxx.listen() for half or a minute there and calling timing. thereafter again using yyy.listen() for half or a minute and calling 2nd timing.
my plan is Mega is calling both timings from both Nanos simultaniously (i.e. using if available).
i am calling unsigned long using millis() to display it in clock style.
calling timing simultaniously with 2 triggers successfully
but why to use trigger, it should come automatically with coding, after hitting touchpad at endline of race, whichever 1st or 2nd.
that is my issue

now....

  1. can i use hardwareserial for RS485 ?
  2. can hardware serial can accept multiple timings at a time ?
    any example please....

But you have not invioked the second serial by just doing a listen. You have to go through the WHOLE set up procedure first so the address will point to the new connection. So much easier to just use the hardware uarts that your board already has.

whether hardwareserial can accept 2 data at a time ?
i.e. whichever touchpad hits, accept the timing from it at real time

main thing, whether there is need to insist each serial by listen() or not ?

The MEGA has 4 serial ports, each totally independent of the others. The MEGA hardware serial ports are interrupt driven for both TX and RX. when incoming data is received it gets copied in a software buffer that you can read later, the default size is about 64 bytes . Conversely be send gets copied into a software buffer (except for the first byte when the transmit register is empty, that will be placed straight into the transmit register).

You can change the serial buffer size() with something like this. #define SERIAL_RX_BUFFER_SIZE 128

It's working fantastic, really
as soon as any touchpad get tapped in any sequence, immediatelly timings comes

I am trying from last 2 months, issue solved in 2 days
thanx a lot....

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