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 & HelpPrograms › Help with crashing applet
Page Index Toggle Pages: 1
Help with crashing applet (Read 326 times)
Help with crashing applet
Mar 13th, 2008, 7:12am
 
Hello, I have a processing program that reads a text file for a single line with an integer and it is crashing/stops communicating over serial after a while. It runs for a good 5 - 10 min and then stops sending serial data.

The text file is being written to by another processing app, that merely increases the number in the text file each time the counter program is run. That works fine. The problem lies with the following program.

// RileyHarmon.com
// University of Oklahoma School of Art

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

void setup()
{
 size(100,100);
 frameRate(12);
 println(Serial.list());
 port = new Serial(this, Serial.list()[3], 9600);
}

void draw()
{
 String lines[] = loadStrings("output.txt");
 int kills = int(lines[0]);
 
 if (kills > lastCount)
     {
     port.write('H');
     lastCount = kills;
 } else
   {
     port.write('L');
   }
}



It is sending the serial commands to an arduino and is only doing that. The arduino is just receiving those commands and doing a simple digitalWrite. Any ideas as to why the app above stops talking to the ardunio. Here is the arduino code below, even though I think the problem is with the code above.

//RileyHarmon.com
//University of Oklahoma School of Art

char val; // Data received from the serial port
int ledPin = 13; // Set the pin to digital I/O 4
int dripPin = 7;

void setup() {
 pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
 pinMode(dripPin, OUTPUT);
 Serial.begin(9600); // Start serial communication at 9600 bps
}

void loop() {
 if (Serial.available()) { // If data is available to read,
   val = Serial.read(); // read it and store it in val
 }
 if (val == 'H') { // If H was received
   digitalWrite(ledPin, HIGH);
   digitalWrite(dripPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   digitalWrite(dripPin, LOW);
   delay(1000);
 } else {
   digitalWrite(ledPin, LOW);
   digitalWrite(dripPin, LOW);
 }
}



Any ideas? Need help soon as this is class project due soon. Thanks!
Re: Help with crashing applet
Reply #1 - Mar 13th, 2008, 8:16am
 
I added a delay(100); to the end of my draw loop and it seems to have fixed the problem. Almost like a resistor in an analog circuit. Smiley
Page Index Toggle Pages: 1