We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hai everyone , i want to transmit the location of my point to arduino by using serial write and read it back from the arduino by using serial read in arduino. The problem here is i cannot read the data from serial monitor due to port problem.I really need a solution
processing code:
{
import processing.serial.*;
Serial myPort; // Create object from Serial class
void setup(){
size (800,600);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw(){
background(50);
fill(150);
stroke(255);
ellipse(mouseX,mouseY,40,40);
println(mouseX + " : " + mouseY);
myPort.write(mouseX);
}
}
Arduino code:
{
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
}
Answers
processing code: import processing.serial.*; Serial myPort; // Create object from Serial class
void setup(){ size (800,600); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw(){ background(50); fill(150); stroke(255); ellipse(mouseX,mouseY,40,40); println(mouseX + " : " + mouseY); myPort.write(mouseX); }
Yes, please no pictures or screenshots of your code. Format your code, edit post, select code and hit ctrl+o.
Do you get the same error when you restart your computer? What values do you get from
Serial.list()
. Can you confirm your Arduino is on COM3?Kf
Don't know if that is the source of your problem, but you can only have one connection to your serial-port. So if you open a connection from processing, then you cannot use arduino's serial monitor at the same time (and i guess uploading new code to your arduino wouldn't work as well).
If your processing sketch was already stopped, unplugging the arduino might fix the problem, sometimes changing the usb-port helps too.
@kfrajer yes im very sure the arduino is connected to com3..sorry fr the screen shot,.,ill put it in editable format.
@kfrajer i didnt get any value from the serial.list().
@benja so how can i know if the arduino received the location that i transmit through processing.Is there any other method than serial monitor to monitor the transmitted data.. Changing the port didnt help me ..
Format your code, edit post, select code and hit ctrl+o. Ensure there is an empty line above and below your code block.
What OS are you working on? What Arduino board do you have?
As benja mentioned, you need to close your arduino API after you load the code into your unit. Then you should reset your arduino either by pressing the reset button or unplugging and plugging the USB back into your computer. After you do this, then run the Processing code and check what
println("Serial list: "Serial.list());
returns.You should run your first processing sketch following the instructions they provide here: https://www.arduino.cc/en/Guide/Arduino101
For Arduino troubleshooting:
https://www.arduino.cc/en/Guide/Troubleshooting
Kf
@kfrajer im using windows 8 arduino uno ..will try ur suggestion,.,tq
i get the results as below after add the serial list code
So does it work if you use the following line?
myPort = new Serial(this,"COM3", 9600);
Please edit your post and format your code.
Kf
While you cannot use several programs using the same serial-port at the same time, you can very well use a single program to send and receive data. So, to make sure that your arduino receives what you are sending, you can send some kind of acknowledgement message from the arduino-side.
Here is an old thread where i posted some example-code, maybe that helps? https://forum.processing.org/two/discussion/14004/sending-a-numerical-variable-from-processing-to-arduino
@kfrajer, @benja yes this line works for me,.tq guys...i already edit my post,.,is that what u mean @kfrajer