PHP serial port data return from Arduino
I assume you work on linux.
First setup your serial port:
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
Then you can use good old fashion fread/fwrite
$fp =fopen("/dev/ttyACM0", "w+");
if( !$fp) {
echo "Error";die();
}
fwrite($fp, $_SERVER['argv'][1] . 0x00);
echo fread($fp, 10);
fclose($fp);
There is only one thing you have to remember. Arduino will restart on every connection. If you don't know that It will confuse you. For instance if you connect (fopen) and instantly send data Arduino will miss it because it's booting (which takes a sec or two). Experiment with sleep to give it some time. If you want to disable restarting use 10uF capacitor from GRD to RST.
Good luck
ps. you can troubleshoot with "screen"
screen /dev/ttyACM0 9600
Post about setting PHP with Arduino http://systemsarchitect.net/connecting-php-with-arduino-via-serial-port-on-linux/ and one more here http://systemsarchitect.net/arduino-and-php-serial-communication-with-a-protocol/.
Serial Communication Arduino to PHP
the php_serial.class.php is kind of broken, i had to adapt it to get a reading out of it, so instead of using the following from the reader method:
$content = ""; $i = 0;
if ($count !== 0)
{
do {
if ($i > $count) $content .= fread($this->_dHandle, ($count - $i));
else $content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
else
{
do {
$content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
i used just this
//trigger_error("reading 0 ".$i, E_USER_WARNING);
$content .= fread($this->_dHandle, $count);
return str_split($content);
then reconstruct the byte string in php
Related Topics
How to Pass Get Parameters to Laravel from with Get Method
When *Not* to Use Prepared Statements
Asynchronous Function Call in PHP
What Do the Ent_Html5, Ent_Html401, ... Modifiers on HTML_Entity_Decode Do
How to Switch from Post to Get in PHP Curl
Creating a Mechanism to Validate Emails
How to Get File Url Using Storage Facade in Laravel 5
How to Generate an Excel Document with Multiple Worksheets from PHP
How to Count the Numbers of Rows That a MySQL Query Returned
Codeigniter Routes Regex - Using Dashes in Controller/Method Names
How to Write a Stored Procedure in PHPmyadmin
How to Set Time Zone in Codeigniter
PHP Flush That Works... Even in Nginx
How to Delete MySQL Row After Time Passes
When Should I Use Stdclass and When Should I Use an Array in PHP Oo Code
Case Insensitive Xpath Searching in PHP
Count and Limit the Number of Files Uploaded (HTML File Input)