I am trying to use PHP to make my Arduino send out a signal. Whenever I run the code below, it says "Invalid serial port", though it is valid?
<?php
include 'serial_connect.php';
$serial = new phpSerial;
$serial->deviceSet("COM2");
$serial->deviceOpen();
$serial->sendMessage("1000");
$serial->deviceClose();
?>
The serial_connect.php class is php-serial, link here: http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html
Here is my Arduino sketch:
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0) {
int time = Serial.parseInt();
digitalWrite(ledPin, HIGH);
delay(time);
digitalWrite(ledPin, LOW);
}
}
Please help. Thanks.
Check that your COM2 is installed, enabled, and working right in device manager, if you haven't. Also what model of Arduino are you using? I don't think this question can be answered without more information. It might be wise to add that info to your original question. Also, we can't see the source of the php_serial class without registering for an account, which I do not wish to do. I realize this is more of a comment than an answer, but I need a bit more rep to comment (a flaw in S.O.'s reputation system, in my opinion.) But the original question will not get an answer without more information, so I felt it was pertinent to add. Best of luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With