Pages: [1]   Go Down
Author Topic: php with arduino  (Read 1080 times)
0 Members and 1 Guest are viewing this topic.
Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Vancouver, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 164
Arduino 4 Prez
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
-
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?



Logged

Grenoble/Lyon - France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 363
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


0
Offline Offline
Newbie
*
Karma: 1
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: December 12, 2009, 01:58:08 pm by marcoseduardo » Logged

Pages: [1]   Go Up
Jump to: