Hi everyone!
How i can comunicate on serial port with Arduino Uno board without serial monitor is turned on?
I have a php script with i can turn on and off a led on Arduino board, but this work just when the Serial Monitor is turned on.
my arduino code
const int ledPin = 12;
int incomingByte;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
my php code
public function actionTurnLed()
{
error_reporting(E_ALL);
if( !empty($_GET["state"]) )
{
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
if( $_GET["state"] == "1" )
{
$serial->sendMessage("H");
}
else if($_GET["state"] == "2" )
{
$serial->sendMessage("L");
}
}
$this->render("led");
}
( Sorry for my English )