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 › do serial ports go into a sleep-mode after awhile
Page Index Toggle Pages: 1
do serial ports go into a sleep-mode after awhile (Read 1341 times)
do serial ports go into a sleep-mode after awhile
Nov 5th, 2008, 2:25am
 
I am working with some code that receives a signal from the Arduino board (a button connected to the Arduino gets pressed and sends an ascii character over the USB port) and then runs an applescript.  The whole thing works beautifully when I first run it and for the for quite some time after that. however after I leave it alone for about 4 to 5 hours and come back to it, I press the button that is connected to the arduino and about 30 seconds later the applescript runs(when the processing application is first opened and for around 3 hours after that , the script will run almost immediately after the button is pressed..like 1 to 2 seconds) . This delay is non nonexistent for the first little while , as I mentioned.  are the USB ports going to sleep after some time? does the serial event listener go to sleep after awhile? I have looked around for others with the same problem and it seems some have a similar issue only it happens constantly (where as mine seems to happen after the program has been running for an approximate amount of time)
I am pretty sure the problem isn't with the arduino code because the LED light I have connected to it always changes its state immediately after I press the button, no matter how long it has been connected, this is why I suspect it to be either the serial ports themselves or the processing code.


thanks in advance.

-Sean
Re: do serial ports go into a sleep-mode after awh
Reply #1 - Nov 6th, 2008, 6:10am
 
after some further testing it was found that itunes was the reason for the large delay.  seems that the looping playlist that contained a 10 second movie that continually looped until the next time a applescript was run, was the cause .   for some reason, after some time , the system resources that were being used by itunes would shoot way up as the loop continued on and on.  I guess iTunes can't handle looping a movie of such a short duration for much longer than a few hours(on OSX, even). thanks to any of you that were considering and/or working on this problem.
Re: do serial ports go into a sleep-mode after awhile
Reply #2 - Sep 5th, 2009, 4:51am
 
for the beginners who are looking for the code;
button connected to arduino and sending data to processing:

(code from processing and arduino site)


Processing code:

import processing.serial.*;

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

void setup()
{
 size(400, 400);
 String portName = Serial.list()[0];  // same port you are using in the arduino program
 myPort = new Serial(this, portName, 9600);
}

void draw()
{
 if ( myPort.available() > 0) {  // If data is available,
   val = myPort.read();         // read it and store it in val
 }
 background(255);             // Set background to white
 if (val == 0) {              // If the serial value is 0,
   fill(0);                   // set fill to black
 }
 else {                       // If the serial value is not 0,
   fill(204);                 // set fill to light gray
 }
 rect(50, 50, 200, 200);
}

arduino code:
#include <Button.h> // button library @ http://www.arduino.cc/playground/Code/Button

//create a Button object at pin 12
/*
|| Wiring:
|| GND -----/ ------ pin 12
*/
Button button = Button(12,PULLUP);
 
void setup(){

 Serial.begin(9600);

}

void loop(){
 if(button.isPressed()){
 Serial.print(1, BYTE);               // send 1 to Processing
 } else {                               // If the switch is not ON,
   Serial.print(0, BYTE);               // send 0 to Processing
 }
 delay(100);                            // Wait 100 milliseconds
}


Page Index Toggle Pages: 1