We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Choppy incoming data (Read 677 times)
Choppy incoming data
Jan 11th, 2008, 3:42am
 
Hello all!

I recently purchased the Wiring board and a Memsic accelerometer (2axis) from Parallax. I have wired up the accelerometer to the Wiring board, and the incoming digital signal is converted to a number between 1 - 1000. Then I tell Wiring to do:

Serial.print(x_pulse);  //x_pulse is an integer between 1 - 1000
Serial.print(" ");

When I look at the incoming data with Wiring's Serial Monitor the numbers show up like this (normal):

526
527
526
526

Now when I have processing read the incoming data it gives me:

526
5
27
526
526
52
8
527

I don't understand why it is chopping up, and I know that the values are not that small. Also I do not know how read incoming integers. I am reading the data as Strings. :(

This is the code I use to get the incoming data:

void draw() {
 // Expand array size to the number of bytes you expect
 byte[] inBuffer = new byte[3];
 while (myPort.available() > 0)
 {
   inBuffer = myPort.readBytes();
   myPort.readBytes(inBuffer);
   if (inBuffer != null) {
     String myString = new String(inBuffer);
     println(myString);
  }
 }
}
Re: Choppy incoming data
Reply #1 - Feb 2nd, 2008, 12:19am
 
Hi:
Convert your integer into a Byte in wiring, then Serial.print the byte value with no other Serial.print.

Just put:
void draw () {
Serial.print (x_pulse, byte);
}

So you will be writing bytes in a row like this:
255127255127 etc...

but in processing, it reads the serial port one byte at a time, so all you do is read the next byte, and convert that into an integer in processing.

Page Index Toggle Pages: 1