Go Down

Topic: php with arduino (Read 1 time) previous topic - next topic

stealthtransam

I am using the Mac PHP serial class and i can talk to the Arduino USB board but it seams to only work when i have the Arduino software running and using the Arduino Serial port monitor.  If i don't have the Arduino serial port monitor running i can't talk to the Arduino board.  Is there a way to default Arduino to open to the serial monitor or a work around to get the PHP to work with out the Arduino software running?  Basically looking for a simple work around?

lilpunk1302

What's your code,


TO the best of my knowledge, PHP Can't directly talk to the Arduino, it has to be through a backend interface of sorts, PHP talks to IT, and IT talks to the Arduino.

I'm not sure exactly how you;re doing this from within the environment as I don't think the IDE works as a backend, but I may be wrong.

stealthtransam

im using the PHP serial class that is listed here on the arduino forms.

ianc2674

I don't know how to solve the original problem. I am using the arduino serial monitor as well while
my php script runs... guess that will have to do for now.

But a new question...

How do you use fread to read data into a php app?




melka

I guess that you have to run a serial proxy, like the one used for having Adobe Flash to talk with the Arduino.
http://www.arduino.cc/playground/Interfacing/SerialNet
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

marcoseduardo

#5
Dec 12, 2009, 07:55 pm Last Edit: Dec 12, 2009, 07:58 pm by marcoseduardo Reason: 1
Quote

I don't know how to solve the original problem. I am using the arduino serial monitor as well while
my php script runs... guess that will have to do for now.

But a new question...

How do you use fread to read data into a php app?


I am trying to do the same.
In the Serial Monitor, re results returs ok, but with PHP I think I am writing the FREAD() function wrong.

Here are arduino and php code. Sorry, I did not translate the comments to english, but I think you could understand.

Arduino Code:

/*
* Ola Mundo - Hello World
* Explicação do programa:
* Se chegar o valo 1, escreve "Ola Mundo" e acende o LED
* Se chegar outro valor, escreve "Nao veio o valor correto ainda" e apaga o LED
*/

//declara variáveis
int entrada = 0;
int led = 13; //led no pino 13

void setup()                  
{
 Serial.begin(9600);           // Serial library em 9600 bps  
 pinMode(led, OUTPUT);     //configura o LED no pino 13
}

void loop()                       // run over and over again
{
 if (Serial.available() > 0)
 {
       // lê byte entrando
           entrada = Serial.read();
     
           // Se o valor for = 1 escreve Ola Mundo e acende o LED
           if (entrada == '1')
       {
           Serial.print("Ola Mundo: ");
       Serial.println(entrada);
       digitalWrite(led, HIGH);   // liga LED
           }
       else //escreve outra coisa
       {
       Serial.print("Nao veio o valor correto ainda: ");
       Serial.println(entrada);
       digitalWrite(led, LOW);   // desliga LED
     }

  }

} // fim fo loop


How it works with arduino:
- Put a LED in the 13 PIN (digital with builtin resistor).
- Open Serial Monitor (arduino app)
- send 1, it turn the LED on and return "Ola Mundo";
- If you send other caracter (2, 3, 4, 5....), it wil return the other sentence and turn of the LED.


PHP code:

<!-- parte do html -->
<a href="php_serial.php?caracter=1"> Enviar 1 </a>
<br />
<a href="php_serial.php?caracter=2"> Enviar 2 </a>
<br />
<br />
<!-- fim do html -->


<?
`mode com11: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;

if ($port = fopen("COM1", "w+"))
{
     $valor = $_GET["caracter"];
     echo "abriu a porta serial <br>";
     if (fwrite($port, $valor))
     {
     echo "enviou $valor <br>";

           //lendo o retorno
           if ($recebe = fread($port))


           {
           echo "<br> Recebeu:".$recebe;
           }
     }
     else
     {
     echo "não enviou $caracter<br>";
     }
fclose($port);
}
else
{
echo "a porta seral NÃO abriu! <br>";
}

?>



My problem is in the BLUE part of PHP code:

if ($recebe = fread($port))


100% its wrong, but how is the right mode?

Go Up