Problem with PHP serial on Ubuntu

Hello,

I want to interface arduino with the web for some project and as I do not have an ethernet shield I want to use my computer to host a website and control the serial port of my computer through the website.

Now, I have this website hosted on my PC and I followed this tutorial : http://www.bushveldlab.com/Bushveld_Labs/Blog/Entries/2011/3/13_Controlling_Arduino_with_PHP_in_Ubuntu.html for communication with the serial port. But still when somebody opens the webpage nothing happens, there is no signal on the serial port. Serial monitor works fine so it means the serial port is working and I am sending the commands to the correct port.

Has somebody have any experience with PHP serial? Am I missing something ?

Am I missing something ?

This post is. Like the Arduino code and the PHP script.

Sorry, the code was in the link with other steps I had taken that is why I didn't post here. I am posting the details here now from that link.

I have already installed apache and PHP5 and have done port forwarding and other stuff that was needed for the website hosting part. I have also copied "php_serial.class.php" file in the "/var/www" folder.

Arduino Code:

  int ledPin = 13;

    int number_in = 0;


    void setup() {

      pinMode(ledPin, OUTPUT);

      Serial.begin(115200);

    }


    void loop() {

      if (Serial.available() > 0) {

        number_in = Serial.read();

      }

 

      if (number_in > 0) {

           digitalWrite(ledPin, HIGH);

           delay(300);

           digitalWrite(ledPin, LOW);

           delay(300);

      }

      number_in = 0;

    }

PHP Code:

<p>LED is flashing...<p>


<?php


// Nonzero number to be sent to Arduino

$c = 1;

// Include the PHP serial class

include "php_serial.class.php";


// Start a new serial class

$serial = new phpSerial;


// Specify the device being used

$serial->deviceSet("/dev/ttyS1");


// Set baud rate

$serial->confBaudRate(115200);

$serial->confParity("none");

$serial->confCharacterLength(8);

$serial->confStopBits(1);

$serial->confFlowControl("none");


// Open the device

$serial->deviceOpen();


// Write to the device

$serial->sendMessage(chr($c));


// Close the port

$serial->deviceClose();


?>

(I am using here "/dev/ttyS1" because I have my arduino connected to the serial port and not the USB port.)

I have done this as well :

The last thing left to do, which took the most time to figure out, was to give Apache permission to use the serial port. I did this in terminal with the following command:

sudo adduser www-data dialout

You’ll then be prompted to type in your root password. Basically what this command does is add the user ‘www-data’, which runs Apache, to the ‘dialout’ group, which has access to the serial ports.

Once this is done, you need to restart Apache with the following terminal command:

sudo /etc/init.d/apache2 restart

$serial->deviceOpen();

Which, unless you have modified the Arduino, causes a reset.

$serial->sendMessage(chr($c));

The Arduino may not be ready to receive data yet. It is restarting, after all.

$serial->deviceClose();

Which causes another reset.

When I manually reset the arduino one LED blinks (pin13). But when I access the webpage nothing happens to the arduino LEDs so I am not sure if serial PHP is actually able to access the serial port at all.

Which, unless you have modified the Arduino, causes a reset.

Can you tell what kind of modifications are needed?

(I am using here "/dev/ttyS1" because I have my arduino connected to the serial port and not the USB port.)

Is that what also shows up in the Tools + Serial Port menu?

Can you tell what kind of modifications are needed?

Start here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1204641836

Is that what also shows up in the Tools + Serial Port menu?

Yes that is what shows up checked in the menu and when I send something from the serial monitor in the arduino IDE arduino responds to it but not to the PHP.

Going through the link now.

I am now inserting a 2 second delay before sending the message from the PHP to the serial port so that the arduino has enough time to reset. But still its not working. And secondly I think if it was resetting then the LED13 should have blinked.

Also I tried after removing the auto-reset jumper from my board and it is still not responding to the PHP