Software Serial, prevent Tx/Rx dual use

Hello,

I am using Software Serial for communication between an arduino nano and an adafruit sound fx board. I am trying to implement a 2 player game where each player has their own push button. Each time a player presses the button a message is sent to the sound fx board to play a sound. This works fine so long as the players don't press their buttons at the same time (or within ~40ms). When both players hit their push buttons at the same time software serial tries to transmit while simultaneously receiving. Looking at the Software Serial documentation page it mentions that it does not have this capability. Is there a function that checks to see if Software Serial is in the process of receiving information? Such a flag would allow me to hold off transmitting a new message.

Thanks

Ive used something like this with success using a Mega with multiple serial ports in use

  if(Serial2.available()) {
   callSomeFunction();
  }

In your case it would be Serial.available(){

your code here
. . . .

}

my understanding is that the available function makes sure the line of communication is free before it sends/receives anything else

I think that SoftwareSerial has nothing to do with your problem.
The one that you need - set the flag when the program receive the signal from the first user and do not react to the second.

1 Like

try AltSoftSerial on the UNO
otherwise move to a microcontroller with multiple hardware serial such as a Mega (as suggested by @fshausb )

1 Like

me too.

Do you have delays in your sketch? How do you debounce your buttons?

Thanks for all the replies. It turns out that the adafruit function 'playTrack' for the playing a sound waits for a reply from the sound board. It was this delay that caused my program to stall for half a second. To fix the issue I just avoided the function and sent the serial message myself. I also had to use the Tx/Rx pins on the nano because Software Serial seems make my LEDs go haywire.

1 Like

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