hello,
I m working on GUI controller for UGV rover.
i have problem in processing code, i want to print sensors serial data continuously in processing in new window when we click button .
Arduino code
<>
////$GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75
#include <SoftwareSerial.h>
char message[100]="$GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75";//declare an array to hold the complete message
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
//
// {
// byte n = Serial.available(); //to check that a charterer has come from Serial Monitor
// if (n != 0)
// {
// // char message = Serial.read(); //a character has come; read it and save in variable x
// byte numBytesReceived = Serial.readBytesUntil('\n', message, 100);
// message[numBytesReceived] = '\0'; //null terminate message
// Serial.print(message); //send the received character back at the OutputBox of Serial Monitor
// }
// }
Serial.println();//
char*next;// pointer to substring (token)
float value;
next = strtok(message, ","); //splitting string by "," and get 1st substring token
Serial.println(next);// print $GPGSV
Serial.print("NO.of Satellites: ");// NO. of satellites for full data
(next = strtok(NULL, ",")); // print next string and remove previous string
//value=atoi(next);
Serial.println(next);
Serial.print("Sentence No: ");
(next = strtok(NULL, ","));
// value=atof(next);
Serial.println(next);
Serial.print("satellites in View: ");
(next = strtok(NULL, ","));
//value=atof(next); - cut this to get exact value from sentence
Serial.println(next);// get exact "08" of sentence
Serial.print(" satellite PRN number: ");
(next = strtok(NULL, ","));
//value=atof(next);
Serial.println(next );
Serial.print("Elevation: ");// print elevation in degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("Azimuth: ");// print Azimuth in Degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("SNR: ");// print SNR higher is better
(next = strtok(NULL, ","));
Serial.println(next);
// add some logics here to reduc code
Serial.print(" satellite PRN number: ");
(next = strtok(NULL, ","));
//value=atof(next);
Serial.println(next );
Serial.print("Elevation: ");// print elevation in degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("Azimuth: ");// print Azimuth in Degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("SNR: ");// print SNR higher is better
(next = strtok(NULL, ","));
Serial.println(next);
Serial.print(" satellite PRN number: ");
(next = strtok(NULL, ","));
//value=atof(next);
Serial.println(next );
Serial.print("Elevation: ");// print elevation in degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("Azimuth: ");// print Azimuth in Degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("SNR: ");// print SNR higher is better
(next = strtok(NULL, ","));
Serial.println(next);
Serial.print(" satellite PRN number: ");
(next = strtok(NULL, ","));
//value=atof(next);
Serial.println(next );
Serial.print("Elevation: ");// print elevation in degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("Azimuth: ");// print Azimuth in Degree
(next = strtok(NULL, ","));
Serial.print(next);
Serial.print("");// ASCII VALUE FOR = (ALT +428)
Serial.println(" ");
Serial.print("SNR: ");// print SNR higher is better
(next = strtok(NULL, "*"));
Serial.println(next);
Serial.print("check sum : ");//print check sum data
(next = strtok(NULL, "*"));
Serial.print("*");
Serial.println(next);
}
}
</>
processing code
<>
import processing.serial.*;
Serial myserial;
String message;//"$GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75";
byte i=100;
void setup(){
size(650,360);
String myport= Serial.list()[0];//find correct serial port
myserial=new Serial(this,myport,9600);
myserial.bufferUntil(i);
}
void draw(){
background(230,250,550);
///char[] array = message.toCharArray();
System.out.println(message);
fill(0,255,0);
text("Data:"+ message,150,70);
}
void serialEvent(Serial p) {
message = p.readString();
}
</>