hello i'm trying to send array of byte with Serial.Write(buf,Len)
but don't know hot to read this code with receiver.
SENDER code:
byte buf[4]={1,2,3,4};
void setup(){
Serial.begin(250000);
}
void loop(){
Serial.write(buf,4);
}
RECEIVER code (WRONG)
byte buf[4];
void setup() {
Serial.begin(250000); // how suggest
}
void loop() {
int i = 0;
if (Serial.available()) {
Serial.readBytes(buf,4);
Serial.print(buf[0]);
Serial.print(buf[1]);
Serial.print(buf[2]);
Serial.print(buf[3]);
}
}
How to receive this ??
if (Serial.available())
only ensures that you have at least 1 byte inside the serial buffer, not 4. Read hackingmajenkoblog.wordpress.com/2016/02/01/…