Pages: [1]   Go Down
Author Topic: Problem with PHP serial on Ubuntu  (Read 1379 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
discovering the fun in electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Am I missing something ?
This post is. Like the Arduino code and the PHP script.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
discovering the fun in electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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 :
Quote
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
« Last Edit: February 13, 2012, 09:39:49 am by mohitdaksh » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
$serial->deviceOpen();
Which, unless you have modified the Arduino, causes a reset.

Code:
$serial->sendMessage(chr($c));
The Arduino may not be ready to receive data yet. It is restarting, after all.

Code:
$serial->deviceClose();
Which causes another reset.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
discovering the fun in electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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.

Quote
Which, unless you have modified the Arduino, causes a reset.
Can you tell what kind of modifications are needed?
« Last Edit: February 13, 2012, 10:38:29 am by mohitdaksh » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
Can you tell what kind of modifications are needed?
Start here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1204641836
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
discovering the fun in electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
discovering the fun in electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: