PHP serial output problem

Hi.

I have a little project going on. The goal is to make the built-in LED on PIN 13 go on and off when I change the value $c = 0; in the PHP script.
I can see that i have a connection between the Arduino Uno an the web site, because the Rx light is flashing when I refresh the page. But the LED does not turn on and of when i change the value in the PHP script.

Does anybody know what the problem might be? Am I close to reaching my goal? or am I way off?

PHP code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
    //Include the PHP Serial class
    include "php_serial.class.php";
    //Define the serial port to use (in Windows something like 'COM1')
    define('SERIALPORT','/dev/cu.usbmodem3d11');
    //The character to send
    $c = 0;
 
    $serial = new phpSerial; 
    $serial->deviceSet(SERIALPORT);
    $serial->deviceOpen();	
    $serial->sendMessage(chr($c));
?>
</body>
</html>

Arduino code:

int incomingByte;
int ledPin13 = 13;
 
void setup()
{
    Serial.begin(9600); //Start serial connection, 9600 baud
     pinMode(ledPin13, OUTPUT);
}
 
void loop()
{
    if(Serial.available() > 0){
        incomingByte = Serial.read();
        if(incomingByte == '0'){
            digitalWrite(ledPin13, HIGH); //LED on
        }
        else if(incomingByte == '1' ){
            digitalWrite(13, LOW); //LED off
        }
    }
}

It might be that the Arduino resets when the port is opened in PHP ?

What is the default baud rate the php library uses?

As rob suggests, the Arduino is likely resetting when the php script disconnects. So if the LED turns on, it is probably turned off immediately. You might have to look at disabling AUTO-RESET to make this script work.

Thanks for your answers.

I have read a bit about this issue earlier an suspected this could be the problem. The LED actually turns on for a split second when i refresh the php page.How do you disable the AUTO-RESET?

I dont know what the default baud rate for PHP is.

How do you disable the AUTO-RESET?

http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection


Quote
How do you disable the AUTO-RESET?
http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

That tutorial is very picky about the resistor value for some reason. I've used a 100 ohm resistor and it worked on my arduino to prevent the reset. 150 ohm may also work, as well as a large capacitor between the reset pin and ground.

Ok, I have added a 10uF capasitor between the reset pin an GND. I can now turn on and off the LED from the serial monitor in the Arduino software. But i still cant turn it on and off from my PHP site. The RX LED on the Arduino board is flashing when i refresh my php site, so I know i have som kind of contact between the board an the site.

Any ideas?

Any ideas?

I don't know the details of how PHP works, but it appears to be very similar to the way cmd.exe sends bytes to the serial port. It is possible that a carrage return/line feed is being appended to the transmission. Using the serial monitor, chose the option to add the carrage return/line feed and see if your code still works. If you use windows, there is a free application on the net called portmom that will display exactly what is being sent via the serial port.