Software Serial Question

Hi all,

I am trying to listen into a uart line between two devices. When a particular set of characters is sent, I want my Arduino to transmit a specific message. My issue is that it seams some characters that should be sent are getting lost... and also once I trigger one event, the remaining events do not send any characters, just line feed.... not sure why. I have attached my code, not sure if this was adequate explanation but please feel free to comment and suggest any solution. Thanks,

#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 12); // RX, TX

const unsigned int MAX_INPUT = 50;
static unsigned int input_pos = 0;

void setup()  
{
  mySerial.begin(38400);
  pinMode(13, OUTPUT);
}

void(* resetFunc) (void) = 0;//declare reset function at address 0

void SendMessage(const char * data)
{
  digitalWrite(13, HIGH);
  boolean fourZero = false;



      SoftwareSerial mySerial(11, 10);      
      mySerial.begin(38400);
      mySerial.println();
      delay(1500);
 
      if(strcmp(data,"!01")==0) {mySerial.print("%50155%"); } 
      if(strcmp(data,"!02")==0) {mySerial.print("%50154%"); } 
      if(strcmp(data,"!03")==0) {mySerial.print("%50153%"); }   

 //     input_pos = 0;  

    mySerial.println(" ");
 
    mySerial.println("");
    pinMode(10, INPUT);



}

void loop()
{
  if (mySerial.available () > 0)
  {
    processIncomingByte (mySerial.read ());
  }   
}

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  
   if (inByte == 35)                    // # is the key
       {
         SendMessage(input_line);

          SoftwareSerial mySerial(11, 12); // RX, TX
          mySerial.begin(38400);
 
 
//       input_pos = 0;     

        resetFunc(); //call reset
           }
           else
           {

            if (input_pos < (MAX_INPUT - 1))
            input_line [input_pos++] = inByte;
            }
  }

I'm sure this won't help but I have to ask - why do you use pins 11,12 for software serial?. This seems just dumb as they are used, if not strictly reserved, for SPI bus, but I saw somebody else do this recently, and I wondered if I am missing something.

That is 100% right. ... The software serial example uses 11 and 12. Changing them did not alter the issue though. ....any other ideas? ????

beginit:
I want my Arduino to transmit a specific message

Is the Arduino intercepting the message (i.e. it receives it on one interface and transmits it on another - there is no direct path past it), or just listening to the message (i.e. the original message is also received at the ultimate destination)?

Why have you two separate instances of softwareSerial with the same name and different pins?

As far as I know the Arduino can only use one at a time and only rx or tx at any one time.

What is the purpose of resetFunc? what happens when that is called?

...R

Robin2:
Why have you two separate instances of softwareSerial with the same name and different pins?

I wondered about that, but more about why use software serial at all.

I get the impression that this project is to eavesdrop on communication between two others, and signal when it hears something interesting. Maybe that has something to do with using software serial?

sorry for delay in reply - thanks for the help.

Is the Arduino intercepting the message (i.e. it receives it on one interface and transmits it on another - there is no direct path past it), or just listening to the message (i.e. the original message is also received at the ultimate destination)?

yes, the arduino is intercepting/ aka listening to the "transmit" line of one of the uart modules. when it hears something that it is listening for, it then connects "its" transmit line to the uart bus and sends its message to the same uart device that was being talked to. after it is done it "releases" the line by turning the pin into an input so as to allow normal non-arduino communication to occur.

Why have you two separate instances of softwareSerial with the same name and different pins?

again, this is so that I can listen on one pin without having the tx pin hold the line "mute". when I acutally want to send something after an event is triggered, that is when I change the pin assignments...

I wondered about that, but more about why use software serial at all.

using this on an attiny, no hardware uart lines....

thansk for all the help guys - and sorry for all the """""" uses :slight_smile: :slight_smile:

beginit:
when it hears something that it is listening for, it then connects "its" transmit line to the uart bus and sends its message to the same uart device that was being talked to.

Since the original transmitter will still be connected, and possible even still transmitting, the two output drivers will be fighting against each other. That's not a good idea, even if it works (which is far from certain). It would IMO be safer to intercept the incoming signal line and terminate it at a SoftwareSerial instance working as a receiver, and then echo each receiver character to the hardware Serial port which you arrange to have its Tx pin connected to the ultimate destination device.

I don't know whether the serial links are bidirectional, but if they are then you have the option of either connecting the return data through a similar path, or allowing it to pass directly i.e. not via the Arduino.

SoftwareSerial is rather limited especially when used to send (which is why I suggested using it to receive only) - the solution would be easier if you used an Arduino with two hardware serial ports.

Peter,
Thanks for the suggestion - that makes much more sense. The one caveat I would mention is I am 100% certain that once the original transmitter sends the trigger, it will be silent until the event is over. there is no change that two drivers will fight each other in that sense. My other issue is that I was hoping to do this with a attiny85.... so hardware uart lines are out. I understand the limitations of software serial, so if its not possible - that's the deal :slight_smile: I will have to go back to the drawing board.... but if you can see any other way please let me know your thoughts...

It's a shame that the hardware UARTs are out, but I understand your reasoning. Do pay attention to the restrictions of SoftwareSerial, though - they have quite severe limitations.

Although the sender may not be transmitting, if it is holding the signal low then that will conflict with your SoftwareSerial Tx pin trying to drive it high. Each serial data line should at most one sending device connected, unless you add a circuit to stop them fighting against each other.