Situation:
I try to receive serial data into processing via LAN from a Raspberry Pi that in turn receives the data from /dev/ttyUSB0 connected Arduino (ADC Data, println every 2ms)
The data looks like that:
Problem:
For some unknown reason I get a blank line between every data line. The blank line does not exist at RaspberryPi side… I checked that with “screen /dev/ttyUSB0 38400”.
Now I use this code in processing to receive the data and output it in the console:
import processing.net.*;
Server myServer;
int port = 5555;
void setup(){
size(2,2);
myServer = new Server(this, port);
}
void draw() {
Client thisClient = myServer.available();
if(thisClient != null){
String whatClientSaid = thisClient.readString();
if(whatClientSaid != null){
println(whatClientSaid);
}
}
}
And the output looks like this:
589
592
602
614
621
622
I cant figure out where in my chain the blank line gets inserted, maybe netcat is doing that. Does anyone have a idea how to get rid of the blank line? Or how to skip those lines in processing since they seem not to match “!=null”…
Any ideas?
On the RaspberryPi I now use “socat” to send the data from “ttyUSB0” to a listen port 5555, then on the ClientPC I use socat again to connect to the raspberryPi and
relay the data to a virtual device called “ttyVUSB0”:
Well, it turned out this approach was also not ideal.
Everytime I stopped processing and started it again it complains
about the port being busy, so I had to stop the whole chain and restart all.
I ended up in using the network way in processing again:
this time only using one socat on the raspberryPi when processing
has been started and is listening for an incoming connection from socat:
println() adds a carriage return and line feed to the console print.
So…
Serial.println("012");
is same as sending: Serial.print("012\r\n");
On the receiving end you were not getting a “blank line” you were printing a string with a carriage return and line feed and printing a carriage return and line feed with:
So if I understand correctly CR+LF is practically two newlines at once?
But why does the ArduinoIDE Serial Monitor not show both too? does it ignore one of it? Also “screen /dev/ttyUSB0 38400” does not show these
double newlines… why does processing show them?
Serial.println(“012”); sends “012” to serial monitor along with a carriage return and line feed from the Serial.println() to serial monitor.
Serial.println(“012”) that is sent as a string to Processing sends “012\r\n”.
If Processing receives this string “012\r\n” and does a print(“012\r\n”) it will print ONEcarriage return and line feed that is already in the string.
If you do a println(“012\r\n”) you have TWOcarriage return and line feeds; ONE from string and TWO from the println();
Just a Serial.println(“”) alone will send a carriage return and line feed.