Hi Cinnamon.
I had the same problem but after 4 days of trouble i find the solution.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294421939
i translate with my bad English.
I'll try the same php class but it's not useful form me and an allert tellt that is unbidirectional.
I find the solution for me.
I use webserver with php on win pc and i use Serproxy for connect with com port.
And i write a script that send signal to COM. This method it's bidirectional.
Here the method to put signals with fopen using fsockopen.
Before start php script you must start serproxy.
I use this serproxy for connect to my serial Google Code Archive - Long-term storage for Google Code Project Hosting. (this project is useful for connecting Flash)
This is the PHP code:
<?php
function invia_seriale($messaggio){
$serproxy=true;
if ($serproxy)
{
$fp = fsockopen ("localhost", 5331, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)";
}
else
{
$string = $messaggio;
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
}
}
//catch the variable by lik get example xxx.php?stato=value
$stato=$_GET["stato"];
//execute function
invia_seriale ($stato);
?>
And this is arduino code:
int in = 0;
int ledPin = 13;
int st=LOW;
int sensorPin=A0;
int sensorValue=0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(ledPin,OUTPUT);
}
void loop() {
delay(100);
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue, DEC);
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
in = Serial.read();
if(in==49){
st=LOW;
}
if(in==50){
st=HIGH;
}
// say what you got:
// Serial.print("I received: ");
// Serial.println(incomingByte, DEC);
}
digitalWrite(ledPin,st);
}
For GUI i use this ajax script very beautiful.
http://papermashup.com/jquery-iphone-style-ajax-switch/ and change page on.html and off.html with myPhpToCom.php?stato="Value".
Now i'm searching method to read all string that Arduino put on serial because for example when i read analog in trigger 10K i read sometimes all value and sometimes value is truncate, i'm programming a function that take the serial value that pass on COM.
I think that use php to control Arduino can be intresting because u can use all web service and app that can be interfacing with php (Twitter, Google Calendar, reading and send email ecc..), and it can be possible use mysql db.
I hope thi is useful.
Good Work
