Arduino Forum

Forum 2005-2010 (read only) => Software => Interfacing => Topic started by: jakewaldron on Nov 09, 2006, 04:21 pm

Title: Serial and Processing
Post by: jakewaldron on Nov 09, 2006, 04:21 pm
I have a pot hooked up to my Arduino sending the value over serial to my computer. In the Arduino serial monitor the values come back the way they are supposed to, but when I do serial.read() in processing the values jump between random values, even when Im not moving the pot. Even when I do move the pot it still jumps between the same random values. Am I doing something wrong in processing? I basically have it set up like val=port.read(); println(val); If anyone has any ideas to what Im doing wrong, let me know. Thanks.
Title: Re: Serial and Processing
Post by: neillzero on Nov 09, 2006, 06:41 pm
Have you had a look at this potentiometer + arduino + processing tutorial?
http://webzone.k3.mah.se/projects/arduino-workshop/projects/arduino_meets_processing/instructions/poti.html

The framerate() function was renamed frameRate() recently.  Other than that the downloadable code should still work.
Title: Re: Serial and Processing
Post by: mellis on Nov 09, 2006, 09:13 pm
I think the problem is that you're sending from Arduino a string of digits - e.g. 123 would be sent as the three bytes '1', '2', '3' (which have ASCII values of 49, 50, and 51) - but reading in Processing only a byte at a time.  What you need to do is read the incoming bytes as characters in Processing, collect them until you reach a newline or carriage return and then convert the accumulated string to an integer.  The link neillzero mentioned has some code for this.