control windows with Gobetwino

I found this application online but it doesn't seem to work with the arduino, I am obviously doing sth wrong. Does anyone know how to use it? please tell me step by step what I should do... I am interested particularly with the command SENDK .

really never used it, even if it's sooo interesting.
maybe these lesson report are helpful?

https://sites.google.com/a/divinechildhighschool.org/electronics/Home/Arduino-Lessons/using-gobetwino-to-control-windows-through-arduino

Fixed URL is https://sites.google.com/a/divinechildhighschool.org/electronics/Home/Arduino-Lessons/using-gobetwino-to-control-windows-through-arduino

If you could tell a bit more about your problem, i might be able to help you. I can guarantee that it works with Arduino, 'cause thats what i made it for :slight_smile:

Did you try the sample code for the SENDK command ?

As I said I'm obviously doing sth wrong... this application is great though it's exactly what I needed for a project I'm working on. which would be great if ever get it to work. However I'm still facing some technical problems .... such as not being able to upload the code

ERROR:
avrdude: stk500_getsync(): not in sync: resp=0xe0
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

I hope if this gets fixed the application will run fine.

ok so I have managed to run GoogleEarth with Gobetwino, but I also want to be able to move the earth around with a button, ie. the right button. however it doesn't read the code after void loop. any ideas?

const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
Serial.println("#S|GOOGLE|[]#");
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);

}
else {
// turn LED off:
digitalWrite(ledPin, HIGH);
Serial.println("#S|SENDK|[0&{RIGHT}]#");
}

}

I can't help you with your gobetwino problem, but...

The loop method is called in an infinite loop, thousands of times a second.

Unless you are holding the button down, the command you are sending will be sent many, many times per second.

I suspect you only want to send the command when the button is pressed, not when it is released.

And, you probably only want to send the command once per button press, not continuously while the button is held down.

It's possible that gobetwino can't keep up with the stream of data you are sending it.

I changed the code to work with notepad... what should I do for it to press Enter whenever I press the push button once or keep pressing Enter if the push button is pressed continuously?

const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
Serial.println("#S|NOTEPAD|[]#");
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);
Serial.println("#S|SENDK|[0&{ENTER}]#");
}
else {
// turn LED off:
digitalWrite(ledPin, HIGH);
}

}

First thing you should do is to learn how to post code correctly. Before pasting code, select the # button on the top row. The cursor will be left between the characters added. Then, paste your code.

Or, paste the code, then select it, then press the # button.

To make the program send a command continuously when the button is pressed, continue doing what you are doing now.

To send the command once per button press, you need to keep track of the button state, so you can detect when the button state changes.

int oldButtonState = LOW;

void loop()
{
   int newButtonState = digitalRead(buttonPin);
   if(newButtonState != oldButtonState)
   {
       if(newButtonState == HIGH)
       {
           // Do something when the button is pressed
       }
       else
       {
           // Do something when the button is released
       }
   }
   oldButtonState = newButtonState;
}

You also need to check up on debouncing buttons, otherwise you will get cofusing results.

Also you need some kind of delay in the loop(), otherwise your Arduino will try to send data to GoBetwino many many times a second, much faster than the serial line can handle, and much faster than GoBetwino can handle it too.

Lady ADA has a really good tutorial explaining what debouncing is and why it is required:

http://www.ladyada.net/learn/arduino/

I tink it's in lesson 5

I used the code from Lady ADA but still nothing happens.

const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
// variables will change:
int buttonState;// = LOW;         // variable for reading the pushbutton status
int val;
int val2;

void setup() {                   // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);        // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
Serial.begin(9600);  

Serial.println("#S|NOTEPAD|[]#"); 

     
     
              
}
void loop()
{
  val = digitalRead(buttonPin);
  delay(10);
  val2 = digitalRead(buttonPin);
  if (val == val2) {
    if (val != buttonState) {
      buttonState = val ;                   // read the state of the pushbutton value:

  // check if the pushbutton is NOT pressed.
  // if it is, the buttonState is LOW:

 if (buttonState == HIGH) {         // turn LED on:    
    digitalWrite(ledPin, LOW); 
  
} 
  else {
    // turn LED off:
    digitalWrite(ledPin, HIGH); 
Serial.println("#S|SENDK|[0&{ENTER}]#");
 
  }
  
    }
  }
}

I'm pretty new to this so forgive any mistakes... but I am open to any suggestions.

That's a very strange way to debounce buttons...

If you open the serial monitor from the Arduino IDE, do you see the Serial.println output?

It prints #S|SENDK|[0&{ENTER}]# continuously and when I press the button it stops and nothing else happens.

Try this:

int oldButtonState = LOW;

void loop()
{
   int newButtonState = digitalRead(buttonPin);
   if(newButtonState != oldButtonState)
   {
       if(newButtonState == HIGH)
       {
           // Do something when the button is pressed
            Serial.println("#S|SENDK|[0&{ENTER}]#");
       }
       else
       {
           // Do something when the button is released
       }

         delay(20);
   }
   oldButtonState = newButtonState;
}

This should print the message once each time the button is pressed, and then wait 20 milliseconds (long enough to stop any bouncing) for another button press.

const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
// variables will change:
int ButtonState = 0;         // variable for reading the pushbutton status
int ledState = 0;
int oldButtonState = LOW;

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
 // pinMode(ledPin, INPUT);
Serial.begin(9600);  

Serial.println("#S|NOTEPAD|[]#"); 

}

void loop() {
  
  int newButtonState = digitalRead(buttonPin);
   if(newButtonState != oldButtonState)
   {
       if(newButtonState == HIGH)
       {
           digitalWrite(ledPin, HIGH);  // Do something when the button is pressed
            Serial.println("#S|SENDK|[0&{ENTER}]#");
       }
       else
       {
         digitalWrite(ledPin, LOW); 
   // Do something when the button is released
       }

         delay(20);
   }
   oldButtonState = newButtonState;
}

nothing happens and I get this error

Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:215)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

What am I doing wrong?

When you do it with GoBetwino, does anything happen in the top text area where the commands usually show up ?

Please remember that you can not have the Arduino serial monitor and GoBetwino running at the same time!

EDIT:

Does notepad start up when you send the first command from your setup ?

I am aware about the serial monitor and Gobetwino. It does open the notepad, although not always...

It depends after which "if" statement I put the Serial.println("#S|SENDK|[0&{ENTER}]#"); command.

Sometimes Gobetwino reads once the code and then stops or it continues to read (by 'read' I mean a lot of text appears in the text window of Gobetwino) until I press the push button, then it just stops and nothing else happens, no matter how may times i press it.

Sometimes it even presses enter once automatically after the notepad opens. but the push button never works.

That is all I have tried though, moving around the Serial.println("#S|SENDK|[0&{ENTER}]#"); command, or alternating the HIGH and LOW variables.

Does GoBetwino say that the commandstring recieved is not ok?

Try to put a delay(500); after Serial.println("#S|SENDK|[0&{ENTER}]#");

to slow things down so it is easier to figure out what is happening.

It is strange that notepad does not allways start though.

Using the code I pasted above everything is ok acording to Gobetwino except from the fact that pressing the button nothing happens, no Enter command whatsoever takes place. I think it doesn't read the void loop part... I also tried giving another command after else such as pressing spacebar. Still nothing happened.

Could you try to send just some ordinary text in stead of {enter}

and put the delay i mentioned in my previous post.