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.
IndexProgramming Questions & HelpElectronics,  Serial Library › problems sending ints from wiring to processing
Page Index Toggle Pages: 1
problems sending ints from wiring to processing (Read 598 times)
problems sending ints from wiring to processing
Nov 18th, 2008, 1:56pm
 
hi there

I have problems sending ints from wiring to processing
using the serial library. bytes work, as do strings, but
if I send ints, I always get the same range of numbers
(bewteen maybe 45 and 55), no matter what kind of number
I send.

Do you have any idea what I am doing wrong? I posted the
code of both wiring and processing here:

---------------------------------------------------
wiring code:
---------------------------------------------------
int val;

void setup() {
 Serial.begin(9600); //start serial comm
}

void loop() {
 
val = analogRead(0);
Serial.print(val, DEC);
Serial.print(char(10));

delay(100);

}
---------------------------------------------------
processing code:
---------------------------------------------------
import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
 size(200, 200);
 frameRate(100);

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


void draw()
{
  background(val);
  rect(50, 50, 100, 100);
}


void serialEvent(Serial myPort) {
 
 val = myPort.read();
 print(val);
 print(char(10));
 
}
---------------------------------------------------

Thanks for your help!
yves
Page Index Toggle Pages: 1