Pages: [1]   Go Down
Author Topic: PHP: read / write to / from Arduino - Genaral Steps - please free complete it  (Read 999 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Afternoon, the purpose of this is understand and then use PHP with Arduino.
So, following the steps that I know that are necessary for work with PHP and Arduino, please free complete what is missed in order to have only one topic with all necessary to work with it. I have seen several topic on the forum  and i think is good have only one that resume that.

Software needed:(of course depend which OS are you using)

- Windows xp --> Apache Server correctly installed and configured
- Ubuntu --> Lamp correctly installed and configured
- Mac --> MAMP --> correctly install configured

- php_serial.class.php


well now we can proceed to do the php code FOR SEND DATA TO ARDUINO:

Code:
<html>
<body>
<h1>Works with php</h1>
<p>First Page in PHP</p>



<?php
require("php_serial.class.php"); 

$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(9600);
$serial->deviceOpen();
$serial->sendMessage("c");
       
$serial->deviceClose();

?>


<p>Sent Data to arduino should see blik a led on arduino </p>

</body>
</html>

well now can proceed to RECEIVE data from Arduino should be use the simple instruction

Code:
$read = $serial->readPort();




So now, reading several post on the forum it's clear that ARDUINO when we open a communication from PHP will be reset and need time be realign with the php code.

If not understand bad we have to ways for proceed:

   a) put a sleep() function inside php code after port opening

   b) remove auto-reset from Arduino following this guide : http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

What I tried is the option a) without success, Im not able to get a answer from arduino the variable read is always void. I've used this code:



Code:
int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
pinMode(13,OUTPUT);     // used for see if arduino received data from php
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();
                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
Serial.write("test");   // write on serial "test"
        }
}


Please there is someone that can add a simply working php and arduino skecth that is working for read data from arduino ?

I think is the basilar thing necessary for managed php and Arduino,

Thanks for the collaboration,

Gnusso







Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 124
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow that's interesting...I didn't know you could use Serial ports directly from PHP. I guess this can be made so that you can have a real web server at home instead of an ethernet shield that can only handle a four TCP connections at once.
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8922
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I didn't know you could use Serial ports directly from PHP.

In the windows environment, PHP apparently does not support reading from the serial port, only writing to the serial port.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it correct due the fact using Windows and PHP encouter issues to read the serial port. :-(

Thanks
Andrea
Logged

Pages: [1]   Go Up
Jump to: