0

Arduino Serial Control Problem (PHP)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Serial Control Problem (PHP)

by unmanaged on Sun May 03, 2009 8:43 pm

I am trying to use the arduino as a controller for a robot. I need to control it via the web and am trying to use the serial port but it does not seem to work correctly.

Here is the code...


Code: Select all | TOGGLE FULL SIZE
byte incoming1;
byte incoming2;

void setup()               
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);   
}

void loop() {
    if (Serial.available() > 0) {
    incoming1 = Serial.read();
    incoming2 = Serial.read();
           if (incoming1 == 1)
            {
             digitalWrite(13, HIGH);
            delay (900);
           
          }
          if (incoming2 == 2)
          {
            digitalWrite(13, LOW);
            delay(900);
          }
           
           
  }
}



Here is the PHP code...

Code: Select all | TOGGLE FULL SIZE
<?php
    require("php_serial.class.php");
    $serial = new phpSerial();
    $serial->deviceSet("COM2");
    $serial->confBaudRate(9600); //Baud rate: 9600
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
    $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    $serial->sendMessage("1");
    $serial->deviceClose();
?>


I am not a coder so I am not sure what is up and any help would be much app...

:P

unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Re: Arduino Serial Control Problem (PHP)

by franklin97355 on Sun May 03, 2009 8:57 pm

I'm not a coder either but it looks like you are sending an ascii 1 (49) and comparing it with a numeric 1 which will never be true.

franklin97355
 
Posts: 21488
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Arduino Serial Control Problem (PHP)

by unmanaged on Sun May 03, 2009 9:01 pm

I changed the code around to use ascii 49 for '1' and it still is no go...


Code: Select all | TOGGLE FULL SIZE
byte incoming1;

void setup()               
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);   
}

void loop() {
    if (Serial.available() > 0) {
    incoming1 = Serial.read();
           if (incoming1 == 49)
            {
             digitalWrite(13, HIGH);
            delay (900);
           
          }
          if (incoming1 == 50)
          {
            digitalWrite(13, LOW);
            delay(900);
          }
           
           
  }
}

unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Re: Arduino Serial Control Problem (PHP)

by adafruit on Sun May 03, 2009 10:34 pm

you should, of course, have it print out what it IS getting

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Arduino Serial Control Problem (PHP)

by unmanaged on Sun May 03, 2009 10:48 pm

How do I have the serial monitor open and print it out I have tried and the com port is in use....

unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Re: Arduino Serial Control Problem (PHP)

by unmanaged on Sun May 03, 2009 11:08 pm

if I use the serial monitor to test it it works but when I use php it does not work... any ideas on how to get a clue to what php is doing? I have written what php is sending to a file and it looks fine...

:!:

unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Re: Arduino Serial Control Problem (PHP)

by unmanaged on Mon May 04, 2009 12:49 am

Looks like i compiled todbots code with cygwin and it works ... I had to switch from pin 13 to another pin to make it work correctly ...

unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Please be positive and constructive with your questions and comments.