system
December 26, 2009, 2:00am
1
hello, im new with arduino and im trying to cotrole a arduino with php - i whon turn on/off pin 2, from serial monitor all work but from php not . can some one help with php?
sory about bad eng....
<?php
if (!$_GET['caracter'])
{
$val = 50;
}
else
{
$val = $_GET['caracter'];
}
$fp = fopen ("COM6", "w");
if (!$fp)
{
echo "Port not opened.";
}
else
{
$string = chr($val);
echo "caracter: ".$string;
fputs ($fp, $string);
fclose ($fp);
}
?>
ON
OFF
arduino code :
int mainigais;
int pin2 = 2;
int pin7 = 7;
void setup()
{
Serial.begin(9600);
pinMode(pin2, OUTPUT);
pinMode(pin7, OUTPUT);
}
void loop() {
if (Serial.available() > 0)
{
mainigais = Serial.read();
if (mainigais == '1')
{
Serial.print("pin2 on , mainigais : ");
Serial.println(mainigais);
digitalWrite(pin2, HIGH);
}
else if (mainigais == '2')
{
Serial.print("Manigais : ");
Serial.println(mainigais);
digitalWrite(pin2, LOW);
}
if (mainigais == '3')
{
Serial.print("pin7 on , mainigais : ");
Serial.println(mainigais);
{
digitalWrite(pin7, HIGH);
delay(500);
digitalWrite(pin7, LOW);
}
}
}
}
system
December 26, 2009, 1:18pm
2
What is the problem with the php script? Is the port opened? If so, it appears as though you are sending '1' and '2' with no delay.
In the future, use the # button above to post code. And, don't change the color. That green was very hard to read.
system
December 26, 2009, 5:46pm
3
the port is opened , php send to arduino , but pin2 not work - from serial monitor it work when i send 1 or 2
system
December 26, 2009, 6:09pm
4
In the php script, you should add some code to read what is written by the Arduino to the serial port, and show it in the browser.
Then, in the Arduino script, add some Serial.print statements to echo what was read from the serial port. If it isn't obvious what is wrong, post the output, and we'll offer more suggestions.
system
December 26, 2009, 8:21pm
5
mybe yo can help with code add ?
system
December 26, 2009, 9:39pm
6
when i write arduino code like this - if (mainigais != '1') i can turn pin 2 on from php but cant turn pin 2 off...
system
December 27, 2009, 1:37pm
7
Well, that would imply that you are not sending the Arduino (just) a '1'.
system
December 27, 2009, 7:02pm
8
that i know - but where is error in php ?I've tried many versions but nothing works ... what am I doing wrong?
system
December 27, 2009, 7:16pm
9
how do I know which number Arduino get? What could look Arduino and the PHP code?