flo125 — 2014-05-12 22:26:22

Bonjour,
Je m'appelle Florent, je suis nouveau sur ce forum, et j'ai un problème, du moins une question à propos de processing. En téléchargeant la librairie Firmata de arduino, j'ai vu ce programme:

arduino_output

Demonstrates the control of digital pins of an Arduino board running the
StandardFirmata firmware.  Clicking the squares toggles the corresponding
digital pin of the Arduino.  

To use:
* Using the Arduino software, upload the StandardFirmata example (located
  in Examples > Firmata > StandardFirmata) to your Arduino board.
* Run this sketch and look at the list of serial ports printed in the
  message area below. Note the index of the port corresponding to your
  Arduino board (the numbering starts at 0).  (Unless your Arduino board
  happens to be at index 0 in the list, the sketch probably won't work.
  Stop it and proceed with the instructions.)
* Modify the "arduino = new Arduino(...)" line below, changing the number
  in Arduino.list()[0] to the number corresponding to the serial port of
  your Arduino board.  Alternatively, you can replace Arduino.list()[0]
  with the name of the serial port, in double quotes, e.g. "COM5" on Windows
  or "/dev/tty.usbmodem621" on Mac.
* Run this sketch and click the squares to toggle the corresponding pin
  HIGH (5 volts) and LOW (0 volts).  (The leftmost square corresponds to pin
  13, as if the Arduino board were held with the logo upright.)
  
For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

color off = color(4, 79, 111);
color on = color(84, 145, 158);

int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };

void setup() {
  size(470, 200);
  
  // Prints out the available serial ports.
  println(Arduino.list());
  
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  
  // Alternatively, use the name of the serial port corresponding to your
  // Arduino (in double-quotes), as in the following line.
  //arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
  
  // Set the Arduino digital pins as outputs.
  for (int i = 0; i <= 13; i++)
    arduino.pinMode(i, Arduino.OUTPUT);
}

void draw() {
  background(off);
  stroke(on);
  
  for (int i = 0; i <= 13; i++) {
    if (values[i] == Arduino.HIGH)
      fill(on);
    else
      fill(off);
      
    rect(420 - i * 30, 30, 20, 20);
    text(""+i,420 - i * 30, 30);
  }
}

void mousePressed()
{
  int pin = (450 - mouseX) / 30;
  
  // Toggle the pin corresponding to the clicked square.
  if (values[pin] == Arduino.LOW) {
    arduino.digitalWrite(pin, Arduino.HIGH);
    values[pin] = Arduino.HIGH;
  } else {
    arduino.digitalWrite(pin, Arduino.LOW);
    values[pin] = Arduino.LOW;
  }
}

Ce code est déja très complet et je ne vois pas quoi mettre comme code sur la arduino.

Et je me pose une question, quel code faut il mettre  sur la carte arduino pour que ce programme fonctionne car je n'arrive à contrôler aucune LED. Ce code défini déjà les sorties de l'arduino, faut-il les redéfinir sur la arduino?

En réalité, ce que j'aimerai, ça serait de me passer du Serial.read() afin de ne pas décomposer le mot binaire envoyé et de contrôler en direct une arduino depuis mon ordinateur pour pouvoir être plus libre au niveau des programmes.

J'espère que j'ai été clair et que vous pourrez m'aider.

Olivier — 2014-05-12 23:25:24

citation :

je ne vois pas quoi mettre comme code sur la arduino.

To use:
* Using the Arduino software, upload the StandardFirmata example (located
  in Examples > Firmata > StandardFirmata) to your Arduino board.

:rolleyes:

Bon courage... :)

fabrice54 — 2014-05-13 05:06:56

Bonjour.

Un programme qui te permet de commander les pattes digital de l'arduino et d'allumer des leds .

Code (P5) :

flo125 — 2014-05-13 21:22:58

Je vous remercie énormément pour les conseils que vous m'avez donné. Il m'ont été très utiles et maintenant je peux controler une arduino depuis mon ordinateur sans être limiter par la mémoire de la arduino :)

fabrice54 — 2014-05-14 05:19:08

un petit programme toujours avec Firmata pour les pattes analogiques.

Code (P5) :

import processing.serial.*;  
import cc.arduino.*;  
Arduino arduino;  
float[] val=new float[5];  
int i;  
void setup() {  
  size(800,700);  
   println(Arduino.list());  
   arduino = new Arduino(this, Arduino.list()[0], 57600);  
}  
  void draw() {  
    background(255);  
  for(int i=0;i<5;i++)  
{  
    val[i]= arduino.analogRead(i+1);  
   fill(0);  
 rect(100,100+100*i,255,15);  
 fill(255,0,0);  
  val[i]=map(val[i],0,1024,0,255);     
 rect(100,100+100*i,val[i],15);  
 }  
  }
flo125 — 2014-05-14 19:06:36

Je ne vois à quoi sert ce code...:/

fabrice54 — 2014-05-16 07:46:56

Ce programme permet de lire des valeurs analogiques par intermédiaire de firmata ,à condition de brancher des potars ou des capteurs renvoyant des valeurs analogiques sur les pattes de la carte arduino .

flo125 — 2014-05-18 18:37:21

Mais est ce qu'on peut lire des valeurs digitales même si on définit un port en OUTPUT?

fabrice54 — 2014-05-19 05:24:02

Si tu définis un port en OUTPUT c'est que tu veux écrire une donnée dans la carte arduino  pour les données analogiques il y a les instructions "arduino.analogWrite"qui se font sur les pattes pwm sinon pout lire la valeur d'un potar "potar= arduino.analogRead(n° de la patte analogique que tu veux lire);   et println(potar)la valeur que tu liras
sera entre 0 et 1024 se qui correspond à une tension entre 0 et 5 volts sinon pour les pattes digitales tu as un état bas ou haut ; mais je ne sais pas si j'ai bien compris ta question?.