Hi... I'm trying to use PHP to command my Arduino. To do this I downloaded a php serial class and put the arduino in serial receive input mode. But when I submit a PHP page to send a value to the Arduino, I get a 550 error.
If I bring up the Arduino monitor and enter an H, my led lights up. Any other
code and it turns off... So I know the arduino / code is working...
If I comment out everything in my PHP page following the initial Hello, the
page will load. Otherwise, it just pukes after the library loads...
Is there anything else I'm missing?
My code examples are below:
here is my php code:
<?php echo ('hello'); include "../php/php_serial.class.php"; //Define the serial port to use (in Windows something like 'COM1') define('SERIALPORT','COM4'); $serial = new phpSerial; $serial->deviceSet(SERIALPORT); $serial->deviceOpen(); $serial->sendMessage("H"); echo ('goodby'); ?>Here is my arduino code:
/*
Analog sensor reader
Language: Arduino/Wiring
read data from the serial and turn On or OFF
a light depending on the value
*/
// data received from the serial port
// set the pin to digital i/o 4
char val;
int ledPin = 4;
void setup() {
pinMode(ledPin, OUTPUT); // set pin as output
Serial.begin(9600); // start serial communication at
// 9600 baud
}
void loop() {
if (Serial.available()){ // if data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 'H') { // if H was received
digitalWrite(ledPin, HIGH); // turn the LED on
} else {
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
}
delay(100); // Wait 100 milliseconds for
// the next reading
}