Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2568 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Problème programme ( raspberry + arduino )

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème programme ( raspberry + arduino )

n°2189043
madmax55
Posté le 05-05-2013 à 19:06:27  profilanswer
 

Bonjours a tous  , j'ai un petit soucie dans mon projet .  :smiley-red:
Le projet : je veut avoir les données d'un accéléromètre a signal analogique sur un Fichier html de ma raspberry pi , or je passe par l'intermédiaire d'une carte arduino .
Voici les programmes que j'ai trouver sur le web :  
 
Programme arduino :

Code :
  1. ------------------------------domotique.ino
  2. // Speak to arduino with PHP
  3. // CC BY-NC-SA 2012 lululombard
  4. // Made to work with statebeta.php and serial.sh
  5. // Not yet commented, it's beta !
  6. void setup() {
  7.  Serial.begin(115200);
  8.  for (byte i = 2; i <= 13; ++i)
  9.    pinMode(i, OUTPUT);  
  10.  }
  11. void loop() {
  12.  if (Serial.available()) {
  13.    byte cmd = Serial.read();
  14.    switch (cmd) {
  15.    case '1':
  16.      Serial.println();
  17.      for (byte i = 2; i <= 13; ++i){
  18.        Serial.print(digitalRead(i));
  19.        if (i != 13)
  20.        Serial.write(';');
  21.      }
  22.      break;
  23.    case '2':
  24.      for (byte i = 0; i <= 25; ++i){
  25.        Serial.println("BOOT FILLING LINES FOR SCREEN" );
  26.      }
  27.      break;
  28.    case 'a'...'l': // GCC only (Not C standard)
  29.      byte pin = cmd - 'a' + 2;
  30.      if (digitalRead(pin) == LOW)
  31.        digitalWrite(pin, HIGH);
  32.      else
  33.        digitalWrite(pin, LOW);
  34.      break;
  35.    }
  36.  }
  37. }


 
Php et fichier sh pour la raspberry pi :

Code :
  1. ---------------------statebeta.php
  2. <?php
  3. // Speak to arduino with PHP
  4. // CC BY-NC-SA 2012 lululombard
  5. // You need serial.sh with chmod 777 in /var/www to use this.  
  6. // You need to disable terminal on /dev/ttyAMA0 : "nano /boot/cmdline.txt", and delete "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200".  CTRL+X to save.
  7. // Then, "nano /etc/inittab", go to the last line and add "#" in front of "2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100"
  8. // Made to work with "domotique.ino", with ardunio connected to rx/tx of the GPIOs
  9. // Not yet commented, as the name says, it's beta !
  10.        $screen_name = "arduino";
  11.        $user = "www-data";
  12.        $list = shell_exec("ls /var/run/screen/S-".$user);
  13.        if (strpos($list, $screen_name) == FALSE) {
  14.                exec('screen15
  15.                -dmS arduino /dev/ttyAMA0 115200');
  16.                sleep(1);
  17.                exec('screen -S arduino -X height 1');
  18.                exec('/var/www/serial.sh 2');
  19.                header('Location: '.$_SERVER['PHP_SELF']);
  20.        }
  21.        elseif ($_GET['pin']) {
  22.                $allowed = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" );
  23.                if (in_array($_GET['pin'], $allowed)) {
  24.                        exec('/var/www/serial.sh '.$_GET['pin']);
  25.                        header('Location: '.$_SERVER['PHP_SELF']);
  26.                }
  27.                else {
  28.                       echo "Caractere non pris en charge.<br />";
  29.                }
  30.        }
  31.         else {
  32.         exec('/var/www/serial.sh 1');
  33.         exec('screen -S arduino -X hardcopy /var/www/status.txt');
  34.         $serial = exec('tail -1 /var/www/status.txt');
  35.         $status = explode(";", $serial);
  36.         $on="ON";
  37.         $off="OFF";
  38.         $checked_pin = 0;
  39.         foreach ($status as $actual_pin) {
  40.                if($actual_pin == 1){$text[$checked_pin]=$off;}else{$text[$checked_pin]=$on;}
  41.                $checked_pin++;
  42.        }
  43.        $pin = 2;
  44.        $checked_pin = 0;
  45.        $pins_order = array("a","b","c","d","e","f","g","h","i","j","k","l" );
  46.        foreach ($text as $actual_pin) {
  47.                echo "PIN ".$pin.": ".$status[$checked_pin]." <a href=\"?pin=".$pins_order[$checked_pin]."\">". $actual_pin ."</a><br />";
  48.                $checked_pin++;
  49.                $pin++;
  50.         }
  51.         }
  52. ?>
  53. -------------------------------serial.sh
  54. #!/bin/bash
  55. # Made to work along with statebeta.sh
  56. if [ $# = 0 ]
  57. then
  58. echo Usage : $0 *data*
  59. else
  60. screen -S arduino -X eval "stuff $1"
  61. echo screen -S arduino -X eval "stuff $1"
  62. fi


 
Voila maintenant la question est comment avoir les données sur un HTML , je voudrais comprendre comment sa marche et que mettre en place pour que cela fonctionne car je débute dans le milieux . Un grand merci pour vos réponses   XD

mood
Publicité
Posté le 05-05-2013 à 19:06:27  profilanswer
 

n°2189147
clovis86
LIfe is hard and so am I
Posté le 06-05-2013 à 20:51:08  profilanswer
 

Salut !  
tu devrais peut etre tenter dans le topic uniquer du raspebrry pi ?  
 
http://forum.hardware.fr/forum2.ph [...] nojs=0#bas


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Problème programme ( raspberry + arduino )

 

Sujets relatifs
projet en programme c en urgence !!probléme d'activation de snmp sous easyphp
Problème affichage de l'heureBeug de programme
[Résolu] Problème de tableau multidimensionnel et associatifAmélioration de programme
Aide programme démineurProbleme redimensionnement balise <object> javascript
Problème python command destroy()Problème sur une boucle
Plus de sujets relatifs à : Problème programme ( raspberry + arduino )


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR