Skip to content

marabesi/arduino-php-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arduino-php-wrapper

Codacy Badge Build Status Latest Stable Version Total Downloads composer.lock

If you are wondering how to control the Arduino serial port via PHP, here is the solution. The arduino:// wrapper is a easy and straightforward way to write and read data from Arduino.

Usage

to write date on Arduino serial just use the regular I/O functions in PHP such as fwrite or file_put_contents

\Arduino\Wrapper::register(); //reads data from Arduino $resource = fopen('arduino://ttyUSB0', 'r+'); print fread($resource, 1024);

Or if you prefer, you can use file_get_contents and get the same result

print file_get_contents('arduino://ttyUSB0');

To write data in the Arduino serial is as easy as it could be

\Arduino\Wrapper::register(); //writes data to Arduino $resource = fopen('arduino://ttyUSB0', 'r+'); print fwrite('hello Arduino');
\Arduino\Wrapper::register(); print file_put_contents('arduino://hello Arduino');

OOP

You can use in your project in a OOP style

Sending data

$writer = new Arduino\Writer(new Arduino\Wrapper()); $bytes = $writer->out('ttyUSB0', 'from oop');

Reading data

$arduino = new \Arduino\Wrapper(); $writer = new \Arduino\Reader($arduino); while (true) { print $writer->from('/dev/cu.usbmodem1411'); }

Improvements

As you can see is really simple and we can improve it much more as the sensors are identified

About

Simple wrapper to connect with Arduino

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •