Let's Make Robots!

2 way instructions: Arduino to PC and back again

Ahoy hoy. Back again. had a break of a week to have a play with processing, but now im BACK. i can hear the collective sigh of relief (or was it exasperation)

I have struggled to find a nice simple serial tutorial, for making processing talk to an arduino and back again (via a cable)

I am looking to do the following process:

Connect (obviously, i kind of understand the "handshake" procedure required)

Transmit a value, between 0 and 255, to the arduino.

have the arduino deal with the data, and respond that it is ready for the next value (send back a signal of some sort)

I also want to be able to send instructions from the PC, in addition to the values. ideally (in my mind) they would be in text format eg: "End" but i realise this may complicate things, so i might be better going for a single ascii character? "A" or "X"

If anyone knows of a good example, and could point me in the right direction, or summarise the sketch for both ends of the setup it would be greatly appreciated!

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I was using the appropriate ide for each part, but i did have both ides open while trying to get it to work. I will try your suggestion birdmun. Is there a serial window in the processing one? Or is it just presented in the black box at the bottom(as i have noticed it does when looking up the the port list)

My my this is frustrating.

Having not had my code working, i stripped it back to a super simple version of my code, which didnt work.

then loaded the example from the serialcallresponse tutorial, which ALSO doesnt work, despite copy and paste. Which means (as far as i can see) that after all that, it is a problem with processing and the arduino mixing up the serial ports.

needless to say, not best pleased :(

Was this attempt made in the Processing IDE or the Arduino fork?

I loaded the Processing section into the processing window, uploaded the arduino section onto an arduino, setup as in the diagram, reset both, then ran the processing jobby.

It came up with this error:

"RXTX fhs_lock() Error: creating lock file: /var/lock/LCK..ttyS0: File exists
RXTX fhs_lock() Error: creating lock file: /var/lock/LCK..ttyS0: File exists"

not sure if its a linux/ubuntu, though i couldnt get it to work in windows either...

When you say:

"I loaded the Processing section into the processing window, uploaded the arduino section onto an arduino, setup as in the diagram, reset both, then ran the processing jobby."

Does that mean you tried to use Processing to upload the sketch to the Arduino board?  If so I can see it not responding without using the actual Arduino IDE version to do it.  For the link I posted earlier, You only need the Arduino IDE.  Did you load the source code on that page into a black window or a green one?

that he had both Processing and the Arduino IDE opened. I imgagine that with bdk6's explanation, if OllyR would close the Arduino IDE, he could make the connection.

The above is just a guess. I may be reading too much in to what he was saying.

That sorted it! (on the example version at least)

BirdMun to the rescue again!

In my defense, i dont THINK it actually specifies how to use processing with an arduino anywhere ;-)

SO now to translate what i have learnt across to my sketch......

 

Yeah...I really need a video screen cap to figure this one out.

This is more of a symptom than a problem.  The lockfile is a method to keep more than one process or program from opening a device at once.  Each process that wants to open the device, like the serial port, checks for the lockfile first.  If it is there, it can't open the device.  If not, it creates it then opens the device to prevent others from opening it.  It then removes the lockfile when it closes the device.  If the program exits improperly, it can  leave the lockfile.  Or if the program is running more than once, or another program is running that is trying to use it, you will get this error.  If you are sure there is only one program (processing) trying to use it, you can go to the command line and erase the file.  You may have to become root ( sudo rm /var/lock/...whatever).  But, since you say it doesn't work on Windows as well, it could be there are more than one copy of processing running or your program is trying to open it more than once.

It sounds like you're reinventing the wheel. The Arduino IDE is Processing (specifically a "fork" of Processing.) If you have an Arduino, you should already be able to do what I understand you to be saying you want to do just by uploading a sketch that involves the serial line and monitor. Here is an example that is maybe even more complicated than what you're describing but still simple enough to demonstrate how to do what you want to do (I think):

Serial Call Response