Problem: Values in Processing from Arduino - no stability?

Hi,

In Processing I am receiving values from Arduino with a light sensor - but the values are not stable, even though I am not changing the amount light:

How do I get stable values in Processing?

They are jumping like this:

140
49
52
48
13
10
140
49
52
48
13

In Arduino they are quite stable (printed in the serial monitor)..

Thanks.

The numbers that you have posted above look very much like ASCII values. How are you sending the values ?

I am a complete rookie - The code in Arduino looks like this:

void setup() {

Serial.begin(9600);
}

void loop() {
:
int sensorValue = analogRead(A0);

Serial.println(sensorValue/4);
Serial.write(analogRead(A0)/4);
delay(1);
}

And in Processing:

import processing.serial.*;

Serial port;
int val;

void setup()
{
size(400, 400);
noStroke();
frameRate(10);

port = new Serial(this, "COM3", 9600);
}

void draw() {
if (0 < port.available()) {
val = port.read();
println(val);
}

background(204);
fill(val);
rect(100, 100, 300, 300);

}

(deleted)

ASCII		Character
140
49			1
52			3
48			0
13			carriage return
10			linefeed
140
49			1
52			3
48			0
13			carriage return

Looks a lot like ASCII characters to me.

UKHeliBob:
Looks a lot like ASCII characters to me.

Yep, except it's printing the ascii for 140 (not 130), the same as the value that serial.write is putting out. :slight_smile:

Mixing ASCII data (print() and println()) and binary date (write()) is really not a good idea.

It works! Thank you very much...