PHP script <-> Apache2 <-> ttyUSB0

i would greatly appreciate any help here on three issues:

  1. I’m trying to get a PHP/HTML script talking with my arduino. I’d like to control the board remotely.
    the following script is able to SET dev/ttyUSB0, but can’t seem to open it in the next line.
<?php

include "php_serial.class.php";

// Let's start the class
$serial = new phpSerial;

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyUSB0");

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("Hello !");

// Or to read from
$read = $serial->readPort();

// If you want to change the configuration, the device must be closed
$serial->deviceClose();

// We can change the baud rate
$serial->confBaudRate(9600);

// etc...
?>
  1. i also messed around with udev to try and create a fixed device name, (arduino), so i don’t have to keep chmod’ing tyUSB0.
 BUS=="usb", SYSFS{idProduct}=="6001", SYSFS{idVendor}=="0403", SYSFS{serial}=="A20029rE", NAME="arduino", MODE="666"

i saved the above line in 99-udevmonitor.rules – no luck

  1. it seems that the arduino and a processing sketch can’t both be connected to ttyUSB0 at the same time? Shure would be easier to edit the sketch and the PHP script together? any suggestions?

again, thanks in advance for any help

Paul

i don't know how Processing and another process could connect to the same serial port simultaneously. i haven't been successful with that.

can you connect to the same serial port using another app? from the terminal? in other words, can you isolate the problem to the php module?

It has been working just fine with Python. So i know the ports are working etc.

thanks

Paul

Try adding these parameters

$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")

I've got basically the same set up using a LAMP stack on OSX. It also didn't work first time, so I changed the device name trying several different formats, and for "no reason", it decided to start working using the original name format. Not exactly confidence inspiring, but it makes the process of scripting Arduino and sending and receiving real-time data under php, nice and tidy and cuts out processing as the middle man between server and hardware.

Here's another interesting issue.

When the Apache server is turned off, then back on again - the script gets stuck waiting for localhost.

The only solution I have found so far, is to fire up the Arduino IDE, turn on the serial monitor, then close the IDE. Then, the script works fine again.

I've tried it several times, and it's the same every time.