We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear friends,
Through the following arduino program , I am sending float lat , lng values in string form through arduino serial port, sequentially . This program is working successfully.
String lat="17.372651",lng="78.552167";
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print("lat");
delay(1000);
Serial.print(lat);
delay(1000);
Serial.print("lng");
delay(1000);
Serial.print(lng);
delay(4000);
}
The values of lat and lng , are displayed sequentially in arduino IDE serial monitor.
Through the following processing program, I am able see those values sequentially in processing console window.
import processing.serial.*;
String inBuffer,lat,lng,temp;
int portIndex = 4;
Serial myPort;
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[portIndex], 9600);
}
void draw()
{
while (myPort.available() > 0)
{
inBuffer = myPort.readString();
if (inBuffer != null)
{
temp=inBuffer;
print(temp);
}
}
}
But I like to read and store those values as string variables and use them further in my program. Can you give me the way?
K.Sitarama Rao,
Electronics Engineer and Hobbyist.
Answers
Moved topic & reformatted code => read To newcomers in this forum: read attentively these instructions
If you're talking about sending those values through the arduino as float values and receiving them as Strings, simply cast each float value in your arduino code as a String.
i.e.
I like to read and store those string values received form arduino in string variables in processing program and use them further in my processing program. Can you give me the way?
K.Sitarama Rao, Electronics Engineer and Hobbyist.I
Well you've already declared this statement:
String inBuffer, lat, lng, tmp;
Based on where that is in your processing program, they are global variables meaning that when you use:
tmp = inBuffer;
You're already assigning a String value from the arduino into a String variable (tmp). So you can just use tmp throughout your program.