When programming with php, in cases, we need to communicate between pcDuino and the external Arduino Uno through the virtual COM port. In previous posts, we discussed how to install PHP on pcDuino, and how to connect external Arduino Uno to pcDuino. In this post, we are going to use PHP Serial class to implement the serial communication of PHP on pcDuino with the external Arduino Uno.
The hardware setup and pass through code for Arduino Uno can be found at the post titled serial terminal for pcDuino.
To use the PHP serial class, we need to download the PhpSerial.php from: https://github.com/Xowap/PHP-Serial/blob/develop/src/PhpSerial.php and put into the same directory where we will add our code, which is /var/www.
The test file named index.html has the following content:
<?php include 'PhpSerial.php'; $serial = new PhpSerial; $serial->deviceSet("/dev/ttyACM0"); $serial->confBaudRate(9600); $serial->confParity("none"); $serial->confCharacterLength(8); $serial->confStopBits(1); $serial->confFlowControl("none"); $serial->deviceOpen(); for (;1;) { $serial->sendMessage("Hello say!"); } echo "I've sended a message! \n\r"; ?>
When we run the code by “$sudo php index.html’, we will see the output at the serial terminal on PC side:
Twitter: @pcDuino_NO1
Facebook: https://www.facebook.com/YannyGuoYunyan
Leave a Reply
You must be logged in to post a comment.