web controlling with php


i working on web controlled rover , trying control arduino duemilanove php on win xp. know people have done before, , having trouble getting work me. have wamp installed , here php using:

code: [select]
<?php


$verz
="0.0.2";
$comport "com3"/*change to correct com port */


if (isset($_post["rcmd"])) &#123;
      
$rcmd $_post["rcmd"];
switch (
$rcmd) &#123;
 
   case stop:
       
 $fp =fopen($comport"w");
            
fwrite($fpchr(1)); /* this is the number that it will write */
            
fclose($fp);
      
      
            break;
 
   case go:
       
 $fp =fopen($comport"w");
            
fwrite($fpchr(2)); /* this is the number that it will write */
            
fclose($fp);
            break;
      default:
            die(
'???');
      &
#125;
&#125;
?>

<html>
<head><title>barbie rover control</title></head>
<body>
<center><h1>barbie rover control</h1><b>version <?php echo $verz?></b></center>

<form method="post" action="<?php echo $php_self;?>">
<table border="0">
     <tr>
           <td></td>
           <td>
                 
           </td>
           <td></td>
     </tr>
     <tr>
           <td>
                 <input type="submit" value="stop" name="rcmd"><br/>
                 
           </td>
           <td></td>
           <td>
                 <input type="submit" value="go" name="rcmd"><br />
                 
           </td>
     </tr>
     <tr>
           <td></td>
           <td><br><br><br><br><br>
           </td>
           <td></td>
     </tr>
</table>
</form>
</body>
</html>


and here arduino code using:

code: [select]

//arduino code

//this listens serial port (usb) , stuff based on hearing.

int motor1pin = 13; //the first motor's port number
int motor2pin = 12; //the second motor's port number
int usbnumber = 0; //this variable holds reading serial


void setup() { //call once @ beginning
   pinmode(motor1pin, output);
     //tell arduino motor pins going outputs
     pinmode(motor2pin, output);      
   serial.begin(9600); //start serial port
   serial.println("finished setup , started serial");
}

void loop() { //main loop
   if (serial.available() > 0) { //if there on serial port, read it
       usbnumber = serial.read(); //store in usbnumber variable
       serial.println("serial port availible");
   }

   if (usbnumber > 0) { //if read something
   serial.println("read something");
       if (usbnumber == 49){
           digitalwrite(motor1pin, low);
           digitalwrite(motor2pin, low); //if read 1, stop
           serial.println("read ascii 1");
                 }
     if (usbnumber == 50){
           digitalwrite(motor1pin, high);
           digitalwrite(motor2pin, high); //if read 2, drive forward
             serial.println("read ascii 2");
                 }
           }
       usbnumber = 0; //reset
       serial.println("reset usbnumber variable");
     }



i noticed when don't have serial monitor going, tx , rx lights blink whenever press button on php page. when have monitor going, part prints "resetting usbnumber variable". blinking rx , tx lights make me think close, have suggestions?

ok, turns out that code kinda works. reset arduino , started working. can't use serial debugging while runs though, because other stuff using it. however, there still problem. using led in place of motor, , blink instead of stay on. read that may because board resets every time serial connection opened. same post said if put 47ohm resistor across reset , 3.3v pins, can keep happening. tried , didn't work (the led didn't come on @ all). missing error in code, or resistor thing wrong?


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > web controlling with php


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums