Lost values :(

Bit of an issue here. I am sending values over Serial from my arduino to processing, but the sketch serial clearly shows that only every third value or so is sent completely. The rest are cut down from having 3 digits to only 2 (so instead of receiving 125, it receives 12). Any way to fix this? No need to give me specific code, just an idea. All I could come up with was printing start and end markers, but I don’t know how to tell processing to listen to values only once it receives a certain value, and only until it receives a different value (so, for example, if i send an X, then say 3 digits, so 125, then an F, it will know to save 125 in a variable. If you guys see this as a good idea, can you post some sample code? Here is what I ahve, hopefully it will help:

import processing.serial.*;

Serial myPort;       

void setup () {
  size(600, 600);        

  myPort = new Serial(this, Serial.list()[1], 9600);

void draw () {


void serialEvent (Serial myPort) {

  int inByte = myPort.read(); 



The values are sent through the following code. I’m including this to show that the values are continuously sent. Also, the values do come out correctly in the arduino serial monitor, so it’s clearly an issue with the processing code.

int gnd = 11;
int pwr = 12;

int xval;
int yval;
int analogValue3;
int analogValue2;

void setup(){
 pinMode(gnd, OUTPUT);
 pinMode(pwr, OUTPUT);
 digitalWrite(gnd, LOW);
 digitalWrite(pwr, HIGH);

void loop(){

  analogValue3 = analogRead(3);
  analogValue2 = analogRead(2);
  if (analogValue3 > 480 && analogValue3 <= 540){  

 yval = map(analogValue3, 481, 540, 1, 100);
  if (analogValue3 >= 420 && analogValue3 < 480){
   yval = map(analogValue3, 479, 420, 1, 100);
  if (analogValue3 == 480){
    yval = 0;
  if (analogValue3 > 540){ 
   yval = 100; 
  if (analogValue3 < 420){
   yval = 100; 
 //Serial.print(254, BYTE);
 //Serial.print("X Val = ");
 //Serial.print(xval, BYTE);
// delay(10);
// Serial.print(255, BYTE);
 //Serial.print("    Y Val = ");


WHat happens if you increase the delay?

of what? the sender or processing? I played with both of these values earlier, and all I saw was a slight change in which values come in and which are half lost. I dont think delay is the solution… unless of course you can tell me specifically what the delay should be to make this work

I was wondering if you were not giving enough time for the signals to come in over serial by polling too quickly.

I went and grabbed a section of code where I was pulling arduino numbers from an accelerometer. You can ignore the guff about separating which axis it is but you can see that I had to consciously assemble an ascii string representing the readings then convert to an int. There was never any suggestion of dropping values.Any help?

If you want to work with binary values, have a look at the oscilliscope example and see how he does it.

// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) { //assemble the non-terminator characters into a string
buf += char(c);
if (c == lf) {
int val = int(buf); //extract the numerical value from the string
if (val < (501)) { //if x axis gives input
xval = val;
if ((val > (500)) && (val<(1001))) { //if y axis gives input
yval = val;
if (val > (1000)) { //if z axis gives input
zval = val;
buf = “”; //clear the buffer
println(“xval=”+xval+" yval="+yval+“zval=”+zval);

You may want to refer back to the Processing documentation for the Serial library. Pay special attention to readBytesUntil() and readStringUntil().

Alright guys, thanks for the feedback, I will see what I can do.