We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Sorry kfrajer for my post, publication is correct now
Hi,
i've this code for to read in processing two arduino's separately.
First arduino is a multiples sensors, second arduino have an gps.
My serial data have this format:
For arduino sensors:
85,89,120
For arduino gps have this format (gps string)
$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
Here my code but don't run properly, because i've just Serial portOne run impossible to run two ports...
import processing.serial.*;
Serial portOne; // the first serial port
Serial portTwo; // the second serial port
void setup() {
size(800, 480);
// list the serial ports
println(Serial.list());
// open the serial ports:
portOne = new Serial(this, Serial.list()[0], 115200);
portTwo = new Serial(this, Serial.list()[1], 115200);
portOne.bufferUntil('\n');
portTwo.bufferUntil('\n');
}
void draw() {
}
void serialEvent(Serial thisPort) {
// read the incoming serial data:
String input1 = thisPort.readStringUntil('\n');
if (input1 != null) {
input1 = trim(input1);
String[] values1 = split(input1, ",");
// if the string came from serial port one:
if (thisPort == portOne) {
if(values1.length == 3){
int a1 = int(values1[0]);
int a2 = int(values1[1]);
int a3 = int(values1[2]);
print(a1);
print(",");
print(a2);
print(",");
println(a3);
}
}
// read the incoming serial data:
String input2 = thisPort.readStringUntil('\n');
if (input2 != null) {
input2 = trim(input2);
String[] values2 = split(input2, ",");
// if the string came from serial port two:
if (thisPort == portTwo) {
if(values2.length == 3){
int b1 = int(values2[0]);
int b2 = int(values2[1]);
int b3 = int(values2[2]);
print(b1);
print(",");
print(b2);
print(",");
println(b3);
}
}
}
}
}
If someone has an idea please help me.
Regards, and sorry for my english....
Alfred
Answers
Please edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.
Kf
Try the concept below. When you do
println(portOne.list);
in setup(), do you get both ports?Also if you try running each port by itself, does it run without any problems?
Kf
KF, When I put println (Serial.list ()); In the setup, I see COM4 COM11, but likewise there is only one port (the first) that works ...println (portOne.list); error
@bbjodel Just to clarify on your solution, you got it to work by checking which port to process the data from? Good to her is working. Thanks for sharing your solution.
Kf