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 & HelpSyntax Questions › serial in/out with Processing and Arduino.
Page Index Toggle Pages: 1
serial in/out with Processing and Arduino. (Read 327 times)
serial in/out with Processing and Arduino.
Mar 1st, 2009, 11:05pm
 
Ok, this is driving me batty.

I have a processing sketch that reads a web page, and determines if that page is displaying a 0 or 1.
I am writing that value to serial COM4. Using "println(lampState);" I can see that the variable is getting set correctly; output is either a 0 or 1.

I have an Arduino sketch that I want to monitor COM4, and if it's a 0, do nothing, and if it's a 1, light the led.

This is my code -

Processing:
import processing.serial.*;
Serial port;

void setup()
{
 port = new Serial(this, "COM4", 9600);  
}

void draw()
{
 // get variable
 int lampState;
 String digit[] = loadStrings("<URL>");
 int num = Integer.parseInt(digit[0]);
 lampState = num;
 
 port.write(lampState);
 println (lampState);
}


Arduino:

int ledPin = 13;
int lampState;

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

void loop()
{
 lampState = serialRead();

if (lampState = 1) {
   digitalWrite(ledPin, HIGH);}
else {
digitalWrite(ledPin, LOW);
}
Serial.flush();
}

Except that ledPin is always HIGH.

Any guidance in getting this to work would be greatly appreciated.
Re: serial in/out with Processing and Arduino.
Reply #1 - Mar 2nd, 2009, 11:39am
 
I know nothing about Arduino, but I am a bit skeptical about your way of getting the information: if you put a loadStrings in draw(), it will called dozens of time per second. I am not sure the Web site can cope with this rate... And if it is a public site, it might be seen as a DoS (denial of service) attack! Smiley

If you really must do periodic checks, do that every n frames (checking frameCount variable).
Re: serial in/out with Processing and Arduino.
Reply #2 - Mar 2nd, 2009, 4:10pm
 
Yes, I did have a delay written into the original Processing sketch; I just forgot to carry that into the revision. I could even move the sketch to the computer that's hosting the file, so that the query wouldn't even run across the network, it does only need to check it every seconds. I couldn't get delay() to work properly, so I used frameRate(1).

Thanks!
Page Index Toggle Pages: 1