0

HW: 2 Arduino ProMini 16Mhz, 5V Software serial directly connected using male jumpers on bredboard.

I have creates a software serial port for communication between two arduinos, Parent and child

as per the documentation http://arduino.cc/en/Reference/SoftwareSerialAvailable

mySerial.available()

should return the number of bytes available in the buffer. and

mySerial.read(); 

should give me the byte or return -1 (255) on error. http://arduino.cc/en/Reference/SoftwareSerialRead

here is my code snippet where i read the values

if(child1.available() > 0){
    Serial.print("ParentReceived Something from child 1\n");
    while(child1.available()){
      recvBuffer1[i] = child1.read();
      Serial.print(recvBuffer1[i], DEC); Serial.print(" ");
      Serial.print(i, DEC); Serial.print(" ");
      i++;
      if(i == FRAME_SIZE) break;
    }
  }

the Serial outputs are for debugging, The condition for while is true. we go inside. Now what i receive with child1.read() is the following

ParentReceived Something from child 2
255 0 255 1 255 2 255 3 255 4 255 5 255 6 255 7 

all i see is 255.

what i did: I first suspected the child of sending these data, but i used a TTL to USB converter to directly read the values being sent by the child and they are received correctly as they should be. even if i TAP the serial ports to another TTL to USB converter i get 255 on my arduino Serial monitor and the correct data on the sniffer.

  • 3
    You haven't actually asked a question. – Mike Dec 28 '14 at 6:26
  • 1
    Update the question to show the definition of recBuffer1[]. Also include what the child is sending. – jdr5ca Dec 30 '14 at 2:56
  • Yes, add code where we see the definitions of variables. Also, try bypassing the recvBuffer and directly write the value to the serial window to see if that variable is the issue or not. – Anonymous Penguin Jan 31 '15 at 0:11
  • 1
    Did you call softwareSerial.begin()? – Anonymous Penguin Mar 7 '15 at 14:26
1

I notice that your code only mentions "child1", but the output you've displayed mentions "child 2". I assume that means you're using more than one instance of SoftwareSerial.

It's important to note that only one instance can receive data at any given time. You need to call listen() on an instance to enable it, which will prevent any other instance from receiving data. (Anything which would have been received by another instance will be discarded.)

See the documentation here: http://www.arduino.cc/en/Reference/SoftwareSerialListen

0

I would suggest trying this with only one Arduino using Software Serial at first. Try using the receiver board's Hardware Serial to listen, possibly using its Software Serial for the debug output. The Hardware Serial is full duplex - it can talk and listen at the same time. Software Serial is not; only xmit or recv can run at one time, and nothing else on the board runs while it does. That can make synchronizing your two boards difficult if the communication needs to be bi-directional.

0

The question is - are you "listening" to the port? Per doc SoftwareSerial will discard the data if not in"listening state".

The real question is - when not in listening state how does "available" becomes > 0 (true) AKA there is data in SoftwareSerial "buffer"? It really looks as if there is no real data in the buffer - character count 1 and up to 254 , the buffer content is 255 == -1 which "available" will evaluate as "true".

It can be verified using code to actually get the buffer character count returned from "available" and not just test for if () validity.

if(int count = child1.available())
{
    than print count - how many characters in buffer for real 
or

if(child1.available() != -1) to test for real data in buffer. 


if(child1.available() > 0){ // anything != 0 will ring true 
    Serial.print("ParentReceived Something from child 1\n");
    while(child1.available()){// anything != 0 will ring true 
      recvBuffer1[i] = child1.read();
      Serial.print(recvBuffer1[i], DEC); Serial.print(" ");
      Serial.print(i, DEC); Serial.print(" ");
      i++;
      if(i == FRAME_SIZE) break;
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.