- Only speeds up to 9600 baud work
- Serial.available() doesn't work
- Serial.read() will wait until data arrives
- Only data received while Serial.read() is being called will be received. Data received at other times will be lost, since the chip is not "listening".
Is the article saying that it's safe to skip Serial.available and allow Serial.read to pretty much do the same job as checking if any data is available in the port, but on its own? For example, I have this code:
#include <SoftwareSerial.h>
#define rxPin 3
#define txPin 2
byte x;
byte y;
byte incomingByte;
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup(){
mySerial.begin(9600);
Serial.begin(9600);
}
void loop(){
if (mySerial.available()){
incomingByte = mySerial.read();
Serial.print(int(incomingByte));
if (int(incomingByte == 101)){
x = mySerial.read();
Serial.print("X Value = "
Serial.print(int(x));
}
if (int(incomingByte == 102)){
y = mySerial.read();
Serial.print(" Y Value = ");
Serial.println(int(y));
}
}
}
the void loop starts out with checking if any data is available using serial.available (i know this function doesn't exist in the library, but I didn't know that when I wrote the code). If i delete that if statement and just have incomingByte = mySerial.read(); be the first line in the loop, will the code run "correctly"? that is, will the code first wait for data to be "available" in the serial port?