Skip to content

Commit 210ed28

Browse files
authored
Create README.md
Updated readme
0 parents  commit 210ed28

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

0 commit comments

Comments
 (0)