File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ # arduino-php-wrapper
2+
3+ If you are wondering how to control the Arduino serial port via PHP, here is the solution.
4+ The ** arduino://** wrapper is a easy and straightforward way to write and read data from Arduino.
5+
6+ ## Usage
7+
8+ to write date on Arduino serial just use the regular I/O functions in PHP such as ** fwrite** or file_put_contents**
9+
10+ ``` php
11+ //reads data from Arduino
12+ $resource = fopen('arduino://ttyUSB0', 'r+');
13+ print fread($resource, 1024);
14+ ```
15+
16+ Or if you prefer, you can use ** file_get_contents** and get the same result
17+ ``` php
18+ print file_get_contents('arduinno://ttyUSB0');
19+ ```
20+
21+ To write data in the Arduino serial is as easy as it could be
22+
23+ ``` php
24+ //writes data to Arduino
25+ $resource = fopen('arduino://ttyUSB0', 'r+');
26+ print fwrite('hello Arduino');
27+ ```
28+
29+ ``` php
30+ print file_put_contents('hello Arduino');
31+ ```
32+
33+ ## Improvements
34+
35+ As you can see is really simple and we can improve it much more as the sensors are identified
You can’t perform that action at this time.
0 commit comments