Let's Make Robots!

Arduino to processing

So I have a Sharp IR sensor connected to my Arduino, feeding to my pc the values of its analog input, via the Serial connection.

To do this, I'm using the Serial.write() command. I want to be able to read these values into processing, but when I use the Serial.read() command in Processing, the values it picks up are nothing like what the Arduino Serial monitor is giving me, and are unaffected by the IR sensor.

What am I doing wrong, and how can I get processing to read these values from the IR sensor?

Any help is appreciated.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris the Carpenter's picture

Just do serial sends from Processing and receive them in Arduino. Did you see all the examples of this from the arduino website?

ChuckCrunch's picture

in the communication examples for processing the Arduino code is with it it's just commented out :)

flare's picture

How do you do the reverse?

Send data from Processing to the Arduino, to, say, control a servo with the keyboard?

flare's picture

Chris: Thanks, will give that a go.

ChuckCrunch: got no idea. The relevant code is:

value = analogRead(A0);

Serial.write(value);

ChuckCrunch's picture

raw asci value 

 

Serial.write(value/4.BYTE);'//

i forgot that adc was 10bit

Chris the Carpenter's picture

You are trying to send 10 bits (the adc on your arduino is 10 bit (0-1023)). When sending to the serial monitor, the fact that you are not sending 8-bit bytes is sorta taken care of for you. When you get to processing, those extra 2 bits (actually a second byte) is screwing everything up. The easiest solution is to divide your ADC reading by 4 to make it a byte and then send it. If you want more accuracy, you will need to receive 2 bytes on the processing side (high and low) and then put them back together into your big number. 

ChuckCrunch's picture

in what format are you sending the data 

Serial,write(xxx,BYTE/BIN/HEX/DEC/RAW)