Go Down

Topic: PHP: read / write to / from Arduino - Genaral Steps - please free complete it (Read 1 time) previous topic - next topic


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: [Select]
<h1>Works with php</h1>
<p>First Page in PHP</p>


$serial = new phpSerial();


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


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

Code: [Select]

$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: [Select]
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,



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.


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.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


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


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131