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 › Weird value differences when reading from Wiring
Page Index Toggle Pages: 1
Weird value differences when reading from Wiring (Read 470 times)
Weird value differences when reading from Wiring
Mar 5th, 2008, 9:17pm
 
Hi,

I am trying to send data from Wiring to Processing. I find out that in some way the values send from Wiring are different if I send them with a delay. When I use a delay in Wiring, it seems Processing gets the correct ASCII-number (number 49, which is "1") from the serial connection. When I don't delay after one loop, I only get the number 138 in Processing.

I would appreciate if someone can take a look at my simple code below:

WIRING:

int LEDPin = 48;
long blinkTimer = 0;
int blinkInterval = 1000;
int status = 1;

void setup() {
 pinMode(LEDPin, OUTPUT);
 Serial.begin(9600);
}

void loop() {
 Serial.print(status);
 
 if (millis() - blinkTimer >= blinkInterval / 2) {
   digitalWrite(LEDPin, HIGH);
 }
 
 if (millis() - blinkTimer >= blinkInterval) {
   digitalWrite(LEDPin, LOW);
   blinkTimer = millis();
 }
 
 delay(250); // if no delay is added, the program doesn't give right data
}

PROCESSING:

import processing.serial.*;
Serial port;
int statusVal = 0;

void setup()
{
 background(#222222);
 fill(255);
 size(200, 200);
 noStroke();
 frameRate(10);  
 PFont font;
 font = loadFont("ArialMT-10.vlw");
 textFont(font);
 println(Serial.list());
 port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {  
 showStatus();
}

void showStatus() {
 background(#222222);
 if (port.available() > 0) {
   statusVal = port.read();
   println(statusVal);
   text(statusVal, 8, 16);
 }
}

Has anyone an idea what causes the different values?

Thank you in advance.

Jeroen

Page Index Toggle Pages: 1