Programmation Arduino pour Nunchuk .

Je ne connais pas le logiciel que tu cites mais c'est tout à fait çà. Tu peux le faire également avec Processing ou tout autre logiciel qui "monitorera" le port série.
Mais de façon plus simple, le logiciel arduino comprend justement un serial monitor :

serial_monitor.jpg
 
Alors dans le serial monitor j'ai ceci (capteur à l'horizontale , immobile)


Finished setup

255 255 1023 1023 1
1
128 134 503 499 1
1
128 134 503 500 1
1


Je ne sais pas lire ces infos , je ne connaissais pas cette fonction .

Peut tu m'explique brièvement ?

A tiens je connais GlovePie , je l'utilise pour faire fonctionner une Wimote sur mon PC , effectivement avec certain script on vois la valeur d'accélération en G de chaque axe . Je suis pas sur de l'intérêt de ceci pour le cas présent , mais peut être connais tu un script qui nous en dit un peu plus ?
 
Je t'ai envoyé un message, on peut voir ça sur msn si tu veux ça sera plus simple.
J'ai été bien trop vite et j'ai vraiment fait n'importe quoi !

De ce que j'ai compris, ces lignes représentes chacune un ensemble de valeurs reçues par ta carte arduino, suite à sa demande.

La première valeur est l'axe x du stick analogique
La 2eme l'axe y du stick analogique
La 3eme X-axis acceleration value
La 4eme Y-axis acceleration value
La 5eme Z-axis acceleration value
La 6eme le bouton z 1=relaché, 0=pressé
La 7eme le bouton c 1=relaché, 0=pressé

Essaye ça, on va finir par y arriver...

Code:
#include <Wire.h>
#include <string.h>

#undef int
#include <stdio.h>

uint8_t outbuf[6];    // array to store arduino output
int cnt = 0;
int ledPin = 13;
int ledPin1 = 11;     // Led broche digital PWM 11 pour visualisation du signal
int nouvelleValeur = 0;

void
setup ()
{
  beginSerial (9600);
  Serial.print ("Finished setup\n");
  Wire.begin ();        // join i2c bus with address 0x52
  nunchuck_init ();                   // send the initilization handshake
  pinMode(ledPin1, OUTPUT);      // configure broche 11 en sortie 

}

 

void
nunchuck_init ()
{
  Wire.beginTransmission (0x52);    // transmit to device 0x52
  Wire.send (0x40);        // sends memory address
  Wire.send (0x00);        // sends sent a zero. 
  Wire.endTransmission ();    // stop transmitting
}

void
send_zero ()
{
  Wire.beginTransmission (0x52);    // transmit to device 0x52
  Wire.send (0x00);        // sends one byte
  Wire.endTransmission ();    // stop transmitting
}

void
loop ()
{
  Wire.requestFrom (0x52, 6);    // request data from nunchuck
  while (Wire.available ())
    {
      outbuf[cnt] = nunchuk_decode_byte (Wire.receive ()); // receive byte as an integer
      digitalWrite (ledPin, HIGH);    // sets the LED on
      cnt++;
    }

  // If we recieved the 6 bytes, then go print them
  if (cnt >= 5)
    {
      print ();
    }

  cnt = 0;
  send_zero (); // send the request for next bytes
  delay (100);
}

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits.  That is why I
// multiply them by 2 * 2
void
print ()
{
  int joy_x_axis = outbuf[0];
  int joy_y_axis = outbuf[1];
  int accel_x_axis = outbuf[2] * 2 * 2;
  int accel_y_axis = outbuf[3] * 2 * 2;
  int accel_z_axis = outbuf[4] * 2 * 2;


  int z_button = 0;
  int c_button = 0;

// byte outbuf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
  if ((outbuf[5] >> 0) & 1)
    {
      z_button = 1;
    }
  if ((outbuf[5] >> 1) & 1)
    {
      c_button = 1;
    }

  if ((outbuf[5] >> 2) & 1)
    {
      accel_x_axis += 2;
    }
  if ((outbuf[5] >> 3) & 1)
    {
      accel_x_axis += 1;
    }

  if ((outbuf[5] >> 4) & 1)
    {
      accel_y_axis += 2;
    }
  if ((outbuf[5] >> 5) & 1)
    {
      accel_y_axis += 1;
    }

  if ((outbuf[5] >> 6) & 1)
    {
      accel_z_axis += 2;
    }
  if ((outbuf[5] >> 7) & 1)
    {
      accel_z_axis += 1;
    }

  Serial.print("Axe x : ");
  Serial.print (accel_x_axis, DEC);
  Serial.print("/");
  Serial.print(accel_x_axis/2);
  Serial.print ("\t");

  Serial.print("Axe y : ");
  Serial.print (accel_y_axis, DEC);
  Serial.print ("\t");
  Serial.print("/");
  valeurRetour = accel_y_axis/2;
  Serial.print (valeurRetour) ;
  Serial.print ("\r\n");

  analogWrite(ledPin1, valeurRetour) ;
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char
nunchuk_decode_byte (char x)
{
  x = (x ^ 0x17) + 0x17;
  return x;
}
 
Ok pour msn MadProf .

Je viens d'essayer le code , j'ai du rajouter " int valeurRetour = 0; " au début sinon ça me sortait une erreur comme quoi valeurRetour n'etais pas déclaré .

Là dans Serial Monitor c'est un peu plus clair :


Finished setup

Axe x : 1023/511 Axe y : 1023 /511

Axe x : 564/282 Axe y : 511 /255

Axe x : 563/281 Axe y : 512 /256

.....

Par contre niveau signal de sortie c'est un peu comme ton premier code .
Mais c'est peut étre normale j'ai pas vu de ligne de commande de ledPin1 ?
 
Haut