Why not opening a program from void setup()

Hi:

This is a real one.
I’m trying to open my webcam program from Arduino. If I place the code in the void loop() area it opens the program and as it is a loop is hard to close because it will open again. I have to force close Gobgetwino to end it. The problem is that if I cut the code from there and paste it in the void setup() area the program does not open. The Gobgetwino screen just shows that the comunication port has been open and nothing else.
Here is the code:
Serial.begin(9600);//begins serial Communication with computer
Serial.println("#S|CAM|#");//Opens Webcam program
CAM was already defined as a command and actually works in the void loop() area
Why it works on void loop() and not in void setup()???
Please help
Thanks,
Adrian

Try running it from setup() but with a delay added.

Serial.begin(9600);//begins serial Communication with computer
delay(1000);  //one second delay to let things settle before sending to PC
Serial.println("#S|CAM|[]#");//Opens Webcam program

Lefty

Hi:

Thanks for your prompt response. Yes it opens even with a delay of 200ms; but the problem is it does not open as soon as I open the Gobgetwino soft. I have to reset the Arduino board manually from the pushbutton. I think it's because by the time the Gobgetwino opens the Arduino skecth already did the setup(). Am I right?. How can I make it open as soon as i open the Gobgetwino?. The problem is that I can't upload the sketch with Gobgetwino openned because the arduino sketch sais (basically) COM4 is in use by another prog (Gobgetwino)
Help please
Thanks,
Adrian

arduinoadrian:
Hi:

Thanks for your prompt response. Yes it opens even with a delay of 200ms; but the problem is it does not open as soon as I open the Gobgetwino soft. I have to reset the Arduino board manually from the pushbutton. I think it's because by the time the Gobgetwino opens the Arduino skecth already did the setup(). Am I right?.

Correct.

How can I make it open as soon as i open the Gobgetwino?.

No way from just within a sketch. I'm not experienced with Gobetwino (but know what it is), does it have a command to reset an attached arduino? If not, then you need to have some way for Gobetwino to send some communications to the arduino to tell it is ready to play and in your sketch not try and do anything else until you hear back from Gobetwino. You could always send a message to the author of the program, he was very friendly when he first announced his project on this forum and I'm sure he might give you a hint or solution.

The problem is that I can't upload the sketch with Gobgetwino openned because the arduino sketch sais (basically) COM4 is in use by another prog (Gobgetwino)

Understood about the comm port conflict, that's normal.

Good luck

Lefty

Help please
Thanks,
Adrian

Thanks Lefty. I'll try to contact him.

Adrian

I'm right here :slight_smile:

As far as i remember, at least with the older Arduinos, they would reset when you open the serial port on the PC.
So (in theory) if you hook up your Arduino to your PC before starting GoBetwino, the Arduino wold reset when you start GoBetwino and setup() should run and you should not hav any problems.

I don't know if the newer Arduinos do the same.

I moved to a new house recently and all my stuff is still in storage, so i don't have an Arduino to test with right now.

Hi:

Thanks for your amaizing software man.
I'm using Arduino Duemilanove. Unfortunately is not resetting. I have to do it manually. When I open Gobetwino, the status screen shows the port was openned for communication; but nothing else. It does not open my cam program unless I reset arduino manually.

If you find out why let me know as it is kind of inconvenient this way.

Thank you so much,
Adrian

I will look into it when i get my to my stuff.

Problem solved.

I don't know why; but this morning when I opened Gobetwino after powering up Arduino; it worked fine and my programs all openned as soon as I openned Gobetwino. The request to open the programs is still in void setup() as they should be. Interesting though, I did not upload the sketch again to Arduino today. I used the last version it already had in its memory.

Thanks,
Adrian