Go Down

Topic: PHP - Readport issues (Read 2730 times) previous topic - next topic


Hi all,
I've did this I can send data to the port but I'm not able to reach the answer from arduino maybe there is something that I've missed ? Im using ubuntu configured well below the code :
Code: [Select]
<h1>It works!</h1>

<p>dentro allo script</p>


$read "Initial Value";

$serial = new phpSerial();

           for (
$i=0$i<strlen($str); $i++){
$read $serial->readPort();


$tmptext "12345ABCDE";
"<H3> Get back the value from arduino $read </H3>\n"); 


Arduino code:

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

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps

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.write(45); // send a byte with the value 45
                int bytesSent = Serial.write("hello");

could you help me ? thanks gnusso


Every time you open and close the serial port, you reset the Arduino. With that code, the Arduino has barely had time to start collecting the input data when you reset it by closing the serial port.

Obviously, it does not have time to collect the data and formulate a reply, let alone send the reply. That is why you can't read the response.
The art of getting good answers lies in asking good questions.


Apr 24, 2012, 03:37 pm Last Edit: Apr 24, 2012, 03:39 pm by gnusso Reason: 1
Then If not understand is necessary put a delay somewhere correct ? But from Arduino side i know how to maybe using delay function.
Code: [Select]

but from php side how i can do ? could you give kindly me a tip ? in order to proceed with sense and in the right way ?
at least a simply code example to follow for sycronize trasmission from php and the answer from arduino ...

Thanks 1000 for your help gnusso


PHP has a sleep() function. Time to sleep is in seconds.
The art of getting good answers lies in asking good questions.


Apr 24, 2012, 04:24 pm Last Edit: Apr 24, 2012, 04:39 pm by gnusso Reason: 1
Ok, but in which point I've to put the sleep in my php and delay in arduino code for syncronize everyhting ?



You don't need a delay on the Arduino. It's going to take long enough resetting, as it is.

After you send data to the Arduino, you need to sleep() long enough for the Arduino to reset, read the data that was sent, and generate a response.

Or, you might want to look at some of the ways of preventing the Arduino from resetting.
The art of getting good answers lies in asking good questions.


Apr 24, 2012, 05:14 pm Last Edit: Apr 24, 2012, 05:15 pm by gnusso Reason: 1
I think that for the moment is better use sleep time, but  how know many time I've to sleep ? how I can sure that I received back the message on my php page in the right moment ? and the rest of the php code i think is correct ... fixed this I think that I can start to understand better how it's working thanks for the support ...

I've tried to put sleep(1) between send data and readport, but still to have the variable void ... :-(



is there someone that can help me with this ?


Go Up