Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di izzusan
    Registrato dal
    Apr 2003
    Messaggi
    463

    problema con arduino and php

    ciao ragazzi sto sperimentando un po' di roba con arduino e php ma sto impazzendo...

    sto usando la classe php_serial.class.php
    per leggere la porta seriale

    e faccio stampare da arduino un valore 0..

    il problema è che nn stampa proprio nulla!!!

    questo è il codice

    Codice PHP:
    <?php


    /* Simple serial relay script for turning my sprinkler system on and off from the web!

    Utilizes the PHP Serial class by Rémy Sanchez <thenux@gmail.com> (Thanks you rule!!)
    to communicate with the QK108/CK1610 serial relay board!

    */


    //check the GET action var to see if an action is to be performed
    if (isset($_GET['action'])) {
        
    //Action required
        
        //Load the serial port class
        
    require("php_serial.class.php");
        
        
    //Initialize the class
        
    $serial = new phpSerial();

        
    //Specify the serial port to use... in this case COM1
        
    $serial->deviceSet("COM3");
        
        
    //Set the serial port parameters. The documentation says 9600 8-N-1, so
        
    $serial->confBaudRate(9600); //Baud rate: 9600
        
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
        
    $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
        
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
        
    $serial->confFlowControl("none"); //Device does not support flow control of any kind, so set it to none.

        //Now we "open" the serial port so we can write to it
        
    $serial->deviceOpen();

        
    //Issue the appropriate command according to the serial relay board documentation
        
    if ($_GET['action'] == "on") {
            
    //to turn relay number 1 on, we issue the command 
            //$serial->sendMessage("1");
             
         // Or to read from
         
    $ardu $serial->readPort();
         if(
    $ardu == NULL)
             print 
    "vuoto";
        else 
            print 
    "pieno";
        
        
        } else if (
    $_GET['action'] == "off") {
            
    //to turn relay number 1 off, we issue this command
            
    $serial->sendMessage("0");
        }
        
        
    //We're done, so close the serial port again
        
    $serial->deviceClose();

    }


    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Sprinkler System Controller</title>
    </head>
    <body>

    <h1>Sprinkler System Controller</h1>


    [url="<?php print $_SERVER['PHP_SELF'] . "]">Click here to turn the system on.[/url]</p>


    [
    url="<?php print $_SERVER['PHP_SELF'] . "]">Click here to turn the system off.[/url]</p>
    </body>
    </html>

    codice arduino

    Codice PHP:
    int sens1,sens2,sens3,sens4;
    int pinSens1,pinSens2,pinSens3,pinSens4;
    int incomingByte;    // for incoming serial data

    void setup() {
      
    sens1=0;
      
    sens2=0;
      
    sens3=0;
      
    sens4=0;
      
      
    pinSens1=3;
      
    pinSens2=5;
      
    pinSens3=9;
      
    pinSens4=11;
      
      
    pinMode(pinSens1INPUT);
      
    pinMode(pinSens2INPUT);
      
    pinMode(pinSens3INPUT);
      
    pinMode(pinSens4INPUT);
      
      
    incomingByte 0;
      
    Serial.begin(9600); 
    }

    void loop() {
     
    sens1=digitalRead(pinSens1);
     
    sens2=digitalRead(pinSens2); 
     
    sens3=digitalRead(pinSens3); 
     
    sens4=digitalRead(pinSens4);
     
    outSens(sens1sens2sens3sens4); 
     
     if (
    Serial.available() > 0) {
            
    // read the incoming byte:
            
    incomingByte Serial.read();

            
    // say what you got:
            
    Serial.write("ricevuto");
        }

      
    delay(100);
    }




    void outSens(int s1,int s2,int s3,int s4){
     
      if(
    s1==0&&s2==0&&s3==0&&s4==0){
     
    //seduto dx solo culo
       
    Serial.println("0");
     }
     
     else if(
    s1==0&&s2>0&&s3==0&&s4==0){
     
    //seduto dx solo culo
       
    Serial.write("1");
     }
     else if(
    s1==0&&s2>0&&s3>0&&s4==0){
     
    //seduto dx culo+schiena
       
    Serial.write("2");
     }
     else if(
    s1==0&&s2>0&&s3>0&&s4>0){
     
    //seduto dx culo+schiena+gambe
       
    Serial.write("3");
     }
     
     else if(
    s1>0&&s2==0&&s3==0&&s4==0){
     
    //seduto sx
       
    Serial.write("4");
     }
     else if(
    s1>0&&s2>0&&s3==0&&s4==0){
     
    //seduto sx+dx solo culo
       
    Serial.write("5");
     }
     else if(
    s1>0&&s2>0&&s3>0&&s4==0){
     
    //seduto sx+dx culo+schiena
       
    Serial.write("6");
     }
     else if(
    s1>0&&s2>0&&s3>0&&s4>0){
     
    //seduto sx+dx culo+schiena+gambe
       
    Serial.write("7");
     }

    cosa sbaglio^^??

    xke da php con print $serial->readPort(); non stampa nulla???


    aiuto

  2. #2
    Utente di HTML.it L'avatar di izzusan
    Registrato dal
    Apr 2003
    Messaggi
    463
    nessuno??

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.