Arduino Serial Control Problem (PHP)

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
unmanaged
 
Posts: 8
Joined: Sun May 03, 2009 8:34 pm

Arduino Serial Control Problem (PHP)

Post by unmanaged »

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

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

<?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

User avatar
Franklin97355
 
Posts: 23902
Joined: Mon Apr 21, 2008 2:33 pm

Re: Arduino Serial Control Problem (PHP)

Post by Franklin97355 »

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.

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

Re: Arduino Serial Control Problem (PHP)

Post by unmanaged »

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

Code: Select all

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);
          }
            
            
  }
}

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

Re: Arduino Serial Control Problem (PHP)

Post by adafruit »

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

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

Re: Arduino Serial Control Problem (PHP)

Post by unmanaged »

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

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

Re: Arduino Serial Control Problem (PHP)

Post by unmanaged »

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...

:!:

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

Re: Arduino Serial Control Problem (PHP)

Post by unmanaged »

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 ...

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”