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 › Different values on serial monitor and Processing
Page Index Toggle Pages: 1
Different values on serial monitor and Processing (Read 1780 times)
Different values on serial monitor and Processing
May 19th, 2010, 11:05am
 
Hi all,

Recently I'm facing a problem in my project. It was working great for 2 weeks but now it doesn't work properly.

My circuit is very basic, I read data from photocell in my arduino, and if the value is below a number, lets say 200, I send 0,BYTE from serial port.

Code is like this;

Code:
int photocellPin = 0; 
int photocellReading;


void setup(void) {
Serial.begin(9600);
}

void loop(void) {
photocellReading = analogRead(photocellPin);
if (photocellReading<=200) {
Serial.print(0, BYTE);
}
else {
Serial.print(1, BYTE);
}
}


When I check serial monitor, It works great. But when I read this data from serial in Processing it messes up. It always shows 1, when i print the value I get from serial port.

Processing code is like this; (again very simple)

Code:
import processing.serial.*;

Serial myPort;
int ardgelen;

void setup()
{
size(200, 400);
String portName = "COM3";
myPort = new Serial(this, portName, 9600);
}

void draw() {

if(myPort.available()>0) {
ardgelen = myPort.read();
println(ardgelen);
}

}


I was able to get the correct numbes in Processing for two weeks, and very oddly it works well in another computer. But now It decided to not work properly.

What is the thing am i missing?

Re: Different values on serial monitor and Processing
Reply #1 - May 19th, 2010, 12:12pm
 
Well I was missing a delay(100); on arduino part, when I added this, The code started to work properly.
Page Index Toggle Pages: 1