We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hy,
I'm on Linux kubuntu. I would like receive data from an arduino nano (3 axis motion for head tracking). The arduino code works because I can read data with Pure Data (Pd). The arduino is on port [32] (/dev/ttyUSB0)
I use the common code:
// Example by Tom Igoe
import processing.serial.*;
int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // The serial port
void setup() {
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[32], 9600);
myPort.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
myString = myPort.readStringUntil(lf);
myString = null;
}
void draw() {
println(myPort.available());
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
println(myString);
}
}
}
But myPort.available is always 0. I can't read anything.
Can someone help me ?
thanks
Answers
Dunno whether it's gonna be of any help to ya.
But here's a more efficient Serial reading, based on bufferUntil() + serialEvent():
Plus noLoop() + redraw() too: :D
For me it was COM16 in the arduino IDE but i had to use
Serial.list()[1]
in processing... Why don't you try it out and also post theprintArray(Serial.list());
results.you wrote printArray(Serial.list());(another option is to write println(Serial.list()); to view your serial port , post your results like alex_pr said , i had the same problem ....and tried different ports , also you have to close anyprogram that uses your serial port for example arduino serial monitor, hyperterminal ,etc,etc , usually (i am windows user) , the list port name is not the same that your port for example in my case the available port in serial.list is [0] although i have the com 8 so , for me this code works
myPort = new Serial(this, Serial.list()[0], 9600);
Here is the printArray(Serial.list()):
I don't know how to insert an image in this forum (I have to enter an image url ?). When I unplug the arduino kit, the list finishes at [31] and an error occurs: ArrayIndexOutOfBoundsException:32
So I think it is the good port. If I do:
println(myPort);
This returns:processing.serial.Serial@61e0aea1
but no serial port available...
The sketch given by GoToLoop gives:
I think it is the same problem...
I find the blue button... for the image.
Here is the pure data patch which works:
we can see (with good eyes) the port is 32. Then the data are reading from arduino and send to OSC. I would like directly receive the data with processing without pure data and OSC messages.
I will try on another computer, to see if it works...
I tried on windows, same problem...
Recently a class for a plug&play was posted here. Don't you want to try it - you can run code without arduino attached and then plug it and it should work automatically. That's just a option, cause it seams to me that for some reason you just can't identify the right port.
I just try... It finds /dev/ttyUSB0... Same problem. Can the problem come because the arduino is a clone one (CH340) ? Why does it work on Pure Data (pd-extended) ? any idea ?
Maybe go throught the wiki. What can I think about is maybe you don't close Pure Data when running sketch (or some other software uses the port) and it stays unavailable for processing.
same problem with windows (it's on com 5, port [2]). All applications are closed. There is no error when I run the sketch. I don't understand why processing can't read anything...
Not sure if this is helpful, but it might give you an insight on what devices are using what USB ports. Not sure if Windows port assignments translate to linux, but hey, it's a tool to try. http://www.nirsoft.net/utils/usb_devices_view.html It's free, no install, just unzip and run. It helped me work out a problem on Win7 when I couldn't link to my mobile device in Android mode.
Hi. I think I got the GoToLoop program working. No errors and I am sure it is connecting, but no serial output from COM3 (in my case with PORT_IDX == 1).
I notice .bufferUntil(ENTER); and I know that I have no CR or LF with my input data. How should I modify??? Regards JC.....