Hi,
Project: Php program that light on a led connected to the Arduino.
So I followed a few tutorials: php_serial.class.php+phpprogram.php+arduinoprogram.ino
I tried the same Arduino code with a python program and it works. Not fot PHP.
The Arduino reacts everytimes a execute the program , but the led doesn't light on.
For the php_serial.class.php, they only thing that needs to be changed is the serial port(I think):
function deviceSet ($device)
{
if ($this->_dState !== SERIAL_DEVICE_OPENED)
{
if ($this->_os === "linux")
{
if (preg_match("@^COM(\d+):?$@i", $device, $matches))
{
$device = "/dev/ttyACM0" . ($matches[1] - 1);
}
if ($this->_exec("stty -F " . $device) === 0)
{
$this->_device = $device;
$this->_dState = SERIAL_DEVICE_SET;
return true;
}
As for the php program :
<?php
include("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0");
$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")
$serial->confFlowControl("none"); //Device does not support flow control of any kind, so set it to none.
//Now we "open" the serial port so we can write to it
$serial->deviceOpen();
$serial->sendMessage("*1" ); //sleep(1); // echo "hi"; $serial->deviceClose();
?>
Arduino code :
int OLight1 = 5 ;
void setup(){
// Open serial connection.
Serial.begin(9600);
pinMode(OLight1, OUTPUT);
}
void loop(){
if(Serial.available() > 0){ // if data present, blink
digitalWrite(OLight1, HIGH);
delay(500);
digitalWrite(OLight1, LOW);
delay(500);
digitalWrite(OLight1, HIGH);
delay(500);
digitalWrite(OLight1, LOW);
}
}
Any idea ? Thank you