We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys.. i am new to processing IDE. I have a code of a basic Radar spotting template. when using Arduino IDE i can see the values coming back from sensor using serial print. But in processing this code is not drawing the objects detected in a range. Please help what changes i have to make. in this code.. i got this code from website..
import processing.serial.*; Serial port; Serial port2; String data = ""; String Radius = ""; String Theta = ""; int index = 0; float distance = 0; float angle = 0; float pi = 22.0/7; void setup() { size(1000,1000); background(255,255,255); ellipse(500,500,1000,1000); line(500,0,500,1000); line(0,500,1000,500); line(500,500,1000,0); line(500,500,0,0); port = new Serial(this, "COM3", 9600); port.bufferUntil('.'); } void draw() { } void serialEvent(Serial port) { data = port.readStringUntil('.'); data = data.substring(0, data.length() - 1); index = data.indexOf(","); Radius = data.substring(0, index); Theta = data.substring (index+1 , data.length()); translate(500,500); point (0,0); distance = float(Radius); angle = float(Theta) /180 * pi; fill(30,200,30); ellipse(distance * cos(angle) , -1 * distance * sin(angle) , 5,5); }
Any suggestions is worth a gold... Thank you
Answers
See How to format code and text, particularly about the order of operations...
i corrected it.. please help me
anyone please help people
I know nothing about serial port and Arduino, not having one. BTW, this should be in the Arduino category. I will move it.
But are you use the COM10 port is the right one?
its COM3
Its actually processing code.. but only link is that it reads the values from arduino UNO board serially
can you post the arduino code?
( Arduino category just means it's Arduino related)
There is a PI constant you can use instead of defining it yourself.
In fact there's a degree () / radians () method you can use for converting between the two (line 47)
Try printing out Radius and Theta and paste the values here.
@Chrisir Here is the Arduino code
@koogs here is the angle and Radius values
after 37 do a println(data);
do println distance * cos(angle
also try trim on data after line 37
do you receive anything at all?
are those newlines in the data or just part of your formatting? because they could cause parse errors.
i always print delimiters around things so that i can see - println("Data [" + data + "]");
try, as chrisir points out, printing the derived values - angle and distance. we only need a dozen, not 200 8)
guys its actually printing in the graph but its printing in the top left corner of the window the image is shown below
thanks for the support guys i understood how to fix it.. here i am submitting a correct code here
so the issue was to have it in
draw()
is better than to have it inserialEvent()
?another thing - the translate() in serialEvent() would be cumulative
ah, good one!
Ya@ Chirsir
And @ koogs cumulative you mean? I am quite confused now.
basically in the old version the translate do add up, because they never get resetted - so it would be soon outside the window
nvm
in the new version it takes place in draw which runs on and on but resets the matrix every new loop
oh okay.. got it..