[Solved] If(SoftwareSerial) ?

Hi friends, i am using Arduino Mega and 3 of its serial ports.
And plus i had to create one SoftwareSerial connection.

#include <SoftwareSerial.h>
SoftwareSerial ECSerial =  SoftwareSerial(2, 3);

If statement works for serial ports but not SoftwareSerial.

if(Serial1){.. OK
if(ECSerial){.. NOT OK

It says ECSerial is not a boolean.

How can i know if it is ready?

you should use Serial.available to see if there is a byte in the buffer ready to read

I am trying to send before reading.

So i need to know if it is ready.

beingobserver: I am trying to send before reading.

So i need to know if it is ready.

Just use ECSerial.available instead of ECSerial, like Osgeld said. It returns a boolean.

What the guys above said seams OK to me from a programming perspective however; if you are using the Mega make sure you know which pins support interrupts - a requirement of the Software Serial library i.e. needed for the RX pin.

I don't think pin 2, 3 will work for you with the Mega.


Refer to the "Limitation" section of the page.



You don't need to check if SoftwareSerial is ready before sending. Those checks are only for HardwareSerial on the boards which have the Atmega32U4 processor.

:) You were all right.

And thank you adamatcooranbong, my pins were wrong (they were 2,3) and i changed to rx:10, tx:11 and solved.

Thank you so much.