Hi guy's. I started to mess with the perfect pixel example and use PHP to communicate with my arduino. It seems that once all the code is properly setup and I trigger the communication, it loads endlessly and locks up the arduino software/serial monitor. any ideas? attached is my code...
PHP
$serial = new phpSerial();
$serial->deviceSet("/dev/tty.usbmodemfa131");
//Set the serial port parameters. The documentation says 9600 8-N-1, so
$serial->confBaudRate(9600); //Baud rate: 9600
//Now we "open" the serial port so we can write to it
$serial->deviceOpen();
//Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
if ($_GET['action'] == "redon") {
//to turn the RED LED ON, we issue the command
$serial->sendMessage("2\r");
}
//We're done, so close the serial port again
$serial->deviceClose();
Arduino Code
int incomingByte; // a variable to read incoming serial data into
void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(19, OUTPUT); // initialize the red LED pin as an output
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
incomingByte = Serial.read(); // read the oldest byte in the serial buffer
if (incomingByte == '2') {
digitalWrite(19, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250);
digitalWrite(19, LOW); // turn the LED on (HIGH is the voltage level)
}
}
}