The code below requires "php_serial.class.php". Download it to the same folder where you save this code:
// hello from php.php
<?php
if(isset($_REQUEST['message'])){
$msg=$_REQUEST['message'];
require("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0"); // Arduino usb-port
$serial->confBaudRate(115200); //baud rate
$serial->confParity("none"); //Parity
$serial->confCharacterLength(8); //Character length
$serial->confStopBits(1); //Stop bits
$serial->confFlowControl("none");
$serial->deviceOpen(); // open connection
$serial->sendMessage($msg); //send the message
}
?>
<html><body>
<h3>If you're running Linux: remember to give permissions to www-data to access usbport ($ sudo chmod 777 /dev/ttyACM0)</h3>
<a href="hello_from_php.php?message=HelloFromPhp">Send hello message</a>
</body></html>If you are not getting any data to Arduino, you must first (and every time you connect usb) give permissions to www-data to access your Arduino usb-port.
Try the example above with "Arduino: How to read serial to string" for best results!