Go Down

Topic: Arduino serial comunication with php (Read 585 times) previous topic - next topic

Ervin

Dec 08, 2012, 04:38 pm Last Edit: Dec 08, 2012, 04:44 pm by Ervin Reason: 1
Hi everyone!

How i can comunicate on serial port with Arduino Uno board without serial monitor is turned on?
I have a php script with i can turn on and off a led on Arduino board, but this work just when the Serial Monitor is turned on.

my arduino code

Code: [Select]
const int ledPin = 12;
int incomingByte;      

void setup() {
 // initialize serial communication:
 Serial.begin(9600);
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
}

void loop() {
 // see if there's incoming serial data:

   // read the oldest byte in the serial buffer:
   incomingByte = Serial.read();
   // if it's a capital H (ASCII 72), turn on the LED:
   if (incomingByte == 'H') {
     digitalWrite(ledPin, HIGH);
   }
   // if it's an L (ASCII 76) turn off the LED:
   if (incomingByte == 'L') {
     digitalWrite(ledPin, LOW);
   }
 
}


my php code


 
Code: [Select]

       public function actionTurnLed()
       {
           error_reporting(E_ALL);
           if( !empty($_GET["state"]) )
           {
               
               $serial = new phpSerial();
              $serial->deviceSet("/dev/ttyACM0");
              $serial->confBaudRate(9600);
              $serial->confParity("none");
               $serial->confCharacterLength(8);
               $serial->confStopBits(1);
               
                $serial->deviceOpen();
                if( $_GET["state"] == "1" )
                {
                    $serial->sendMessage("H");
                }
                else if($_GET["state"] == "2" )
                {
                    $serial->sendMessage("L");
                }
           }
           $this->render("led");
       }

( Sorry for my English )

PaulS

There are a number of things that the Serial Monitor does to configure the serial port. You need to make sure that your PHP script does all the same things. I don't think that the correct number of bits per word is a smiley face.

What other methods does the phpSerial class have?

billroy

You need to delay 2 seconds after opening the serial port before sending the first command to the arduino.  Otherwise the command is eaten by the bootloader, and the arduino looks unresponsive, as in this case.

-br

zoomkat

Unless times have changed, php communicates with the serial port in a open port > send data > close port method. When php opens the serial port, it causes the arduino to reset/reboot. Disabling the auto reset of the arduino might be3 a workaroung for reset issues.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Ervin


Unless times have changed, php communicates with the serial port in a open port > send data > close port method. When php opens the serial port, it causes the arduino to reset/reboot. Disabling the auto reset of the arduino might be3 a workaroung for reset issues.


Thank you ! The problem was with automatic reset, i disabled it with a 10uF condenzator on board and it works without serial monitor.

Go Up