Nunchuck WII

Salve a tutti. La mia domanda è:
Ho un Nunchuck sto lavorando alla costruzione di un quadricottero ma prima voglio iniziare dalle basi.
In molte guide ho visto un metodo che usa il telecomando della wii per calibrarsi vorrei fare una piccola prova nel collegare il gioistic ad arduino e riportare i dati nella finestra "serial monitor" come guida ho trovato questo --> http://www.alfonsomartone.itb.it/rkxncv.html ma per primo non so se mi fa la visuale "serial monitor" e secondo riportandolo nel programma di arduino mi compare un errore nella riga

void nunchuck_ack()                 // acknowledge a Nunchuck packet
{
  Wire.beginTransmission(0x52);     // send a zero to device 0x52
  Wire.send(0); // L'ERRORE E' QUI <---------------------------
  Wire.endTransmission();
}

Mi sapreste aiutare :slight_smile:

PS. AIUTATEMI SE SAPETE DI LABVIEW VORREI SE E' POSSIBILE UNA GUIDA PER UN'INTERFACCIA CON LABVIEW SAREBBE MAGNIFICO E' IL MIO SOGNIO XD

Sicuro dei collegamenti?
Che modello di Arduino usi?

uso arduino uno ma non ho messo ancora niente dentro perché non me lo permette per l'errore che ho segnato sopra anche nella verifica me lo segna come errore. prova a copiare tutto il codice dal sito che ho messo sopra e a provare una verifica :slight_smile: a me non mi lascia

Ok, quando torno a casa provo.
Non ho un Arduino qui.

grazie :slight_smile:

Il problema è nella riga

 beginSerial(115200);              // console init

Deve essere

Serial.begin(115200);

Poi si riesce a compilare.

Ciao
QP

mi dispiace modifiche riportate in effetti oltre alla mia c'era anche quella risolto al 100% il consiglio ma ugualmente non mi lascia upluodare e mi segna in aranciane la riga Wire.send(0); e sotto mi scrive

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

:-/

Nel sito indicato viene usata la vecchia libreria Wire.

Sostituisci a tutte le Wire.send con Wire.write e Wire.receive con Wire.read

Ciao
QP

ho fatto come dici ora ho scritto

//
//  nunchuck.pde
//

#include <Wire.h>

uint8_t buf[6];     // buffer for the six-bytes packet coming from Nunchuck
int cnt=0;          // count of bytes in the buffer
int readcnt=0;      // number of times we read a packet from Nunchuck
int ledPin=13;      // which pin will host the blinking LED


uint8_t nunchuk_decode(uint8_t x)   // decode nunchuck data
{
  return (x^0x17)+0x17;             // not that an hard encryption...
}


void nunchuck_ack()                 // acknowledge a Nunchuck packet
{
  Wire.beginTransmission(0x52);     // send a zero to device 0x52
  Wire.write(0);
  Wire.endTransmission();
}


void setup()                        // initialization
{
  int n;
  digitalWrite(ledPin, HIGH);       // turn on LED
  
  for(n=0; n<6; n++) buf[n]=0;      // fill buffer with zero values
  
 Serial.begin(115200);              // console init

  Wire.begin();                     // TWI init
  
  Wire.beginTransmission(0x52);     // nunchuck init
  Wire.write(0x40);
  Wire.write(0);
  Wire.endTransmission();

  digitalWrite(ledPin, LOW);        // turn off LED
  
  Serial.print("!-- start\n");
}


void loop()                         // main loop
{
  Wire.requestFrom(0x52, 6);        // request data from nunchuck
  while(Wire.available())           // read data and light the LED
  {
    buf[cnt++] = nunchuk_decode(Wire.read());
    digitalWrite(ledPin, HIGH);
  }

  if(cnt>=6)                        // an entire Nunchuck packet was read?
  {
    printdata();                    // yes, print it
    cnt=0;                          // clear buffer counter
    nunchuck_ack();                 // acknowledge received packet
    digitalWrite(ledPin, LOW);      // turn off the LED
    delay(800);                     // wait 800msec before next loop
  }
}


void printdata()                    // print out the values
{
  int n;   // note: the 123,131,524,597... depend on my Nunchuck calibration
 
  Serial.print(++readcnt, DEC);

  Serial.print("\t");               // joystick x/y values
  Serial.print((int)buf[0]-123);
  Serial.print("\t");  
  Serial.print((int)buf[1]-131);
  
  n=(buf[2]<<2)+((buf[5]>>2)&3)-524;  // accel X
  Serial.print("\t");  
  Serial.print(n);

  n=(buf[3]<<2)+((buf[5]>>4)&3)-597;  // accel Y
  Serial.print("\t");  
  Serial.print(n);

  n=(buf[4]<<2)+((buf[5]>>6)&3)-668;  // accel Z
  Serial.print("\t");  
  Serial.print(n);

  Serial.print(buf[5]&1 ? "\t- " : "\t[z] ");
  Serial.print(buf[5]&2 ? "-" : "[c]");

  Serial.print ("\r\n");
}

ora però come errore mi segna

sketch_mar01a.cpp: In function 'void nunchuck_ack()':
sketch_mar01a:21: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note:                 size_t Print::write(const char*)
sketch_mar01a.cpp: In function 'void setup()':
sketch_mar01a:39: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note:                 size_t Print::write(const char*)

se vuoi lasciar stare fai pure sono un caso disperato :slight_smile: non avete un altra guida aggiornata magari ?? grazie per l'aiuto

ilmandorlone:
ho fatto come dici ora ho scritto

Lo sketch è stato scritto per il vecchio IDE 0022 o 0023, per usarlo con la 1.0 devi apportare svariate modifiche, compilalo con la 0023 e vedrai che non ci sono problemi.

sono molto duro di comprendono sai indicarmi come si fa?? per favore

ilmandorlone:
sono molto duro di comprendono sai indicarmi come si fa?? per favore

Scarica la versione 0023 dell'IDE e usa quella invece della 1.0 che stai usando adesso.

Ho provato con la 1.0 dopo aver apportato le modifiche e la compilazione ha avuto successo.

//
//
//  nunchuck.pde
//

#include <Wire.h>

uint8_t buf[6];     // buffer for the six-bytes packet coming from Nunchuck
int cnt=0;          // count of bytes in the buffer
int readcnt=0;      // number of times we read a packet from Nunchuck
int ledPin=13;      // which pin will host the blinking LED


uint8_t nunchuk_decode(uint8_t x)   // decode nunchuck data
{
  return (x^0x17)+0x17;             // not that an hard encryption...
}


void nunchuck_ack()                 // acknowledge a Nunchuck packet
{
  Wire.beginTransmission(0x52);     // send a zero to device 0x52
  Wire.write((byte) 0);
  Wire.endTransmission();
}


void setup()                        // initialization
{
  int n;
  digitalWrite(ledPin, HIGH);       // turn on LED
  
  for(n=0; n<6; n++) buf[n]=0;      // fill buffer with zero values
  
  Serial.begin(115200);              // console init

  Wire.begin();                     // TWI init
  
  Wire.beginTransmission(0x52);     // nunchuck init
  Wire.write(0x40);
  Wire.write((byte) 0);
  Wire.endTransmission();

  digitalWrite(ledPin, LOW);        // turn off LED
  
  Serial.print("!-- start\n");
}


void loop()                         // main loop
{
  Wire.requestFrom(0x52, 6);        // request data from nunchuck
  while(Wire.available())           // read data and light the LED
  {
    buf[cnt++] = nunchuk_decode(Wire.read());
    digitalWrite(ledPin, HIGH);
  }

  if(cnt>=6)                        // an entire Nunchuck packet was read?
  {
    printdata();                    // yes, print it
    cnt=0;                          // clear buffer counter
    nunchuck_ack();                 // acknowledge received packet
    digitalWrite(ledPin, LOW);      // turn off the LED
    delay(800);                     // wait 800msec before next loop
  }
}


void printdata()                    // print out the values
{
  int n;   // note: the 123,131,524,597... depend on my Nunchuck calibration
 
  Serial.print(++readcnt, DEC);

  Serial.print("\t");               // joystick x/y values
  Serial.print((int)buf[0]-123);
  Serial.print("\t");  
  Serial.print((int)buf[1]-131);
  
  n=(buf[2]<<2)+((buf[5]>>2)&3)-524;  // accel X
  Serial.print("\t");  
  Serial.print(n);

  n=(buf[3]<<2)+((buf[5]>>4)&3)-597;  // accel Y
  Serial.print("\t");  
  Serial.print(n);

  n=(buf[4]<<2)+((buf[5]>>6)&3)-668;  // accel Z
  Serial.print("\t");  
  Serial.print(n);

  Serial.print(buf[5]&1 ? "\t- " : "\t[z] ");
  Serial.print(buf[5]&2 ? "-" : "[c]");

  Serial.print ("\r\n");
}
}
D:\ArduinoProject\Temp\Wire\Wire.cpp.o D:\ArduinoProject\Temp\Wire\utility\twi.c.o D:\ArduinoProject\Temp\core.a -LD:\ArduinoProject\Temp -lm 
C:\arduino-1.0\hardware\tools\avr\bin\avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 D:\ArduinoProject\Temp\sketch_mar01a.cpp.elf D:\ArduinoProject\Temp\sketch_mar01a.cpp.eep 
C:\arduino-1.0\hardware\tools\avr\bin\avr-objcopy -O ihex -R .eeprom D:\ArduinoProject\Temp\sketch_mar01a.cpp.elf D:\ArduinoProject\Temp\sketch_mar01a.cpp.hex 
Binary sketch size: 4990 bytes (of a 32256 byte maximum)

Wire.write((byte) 0); // bisogna fare il cast con (byte) altrimenti 0 da solo è ambiguo

Se non va ancora i problemi sono da ricercare altrove. Di più non so.

Ciao
QP

Salve ragazzi anche io sto giocando con il wii nunchuk, e sto utilizzando il codice che posto sotto, però non sono sicuro di come connettere i vari fili del connettore wii.

Ho acquistato un controller cinese e una prolunga, in modo da tagliare e connettere il tutto senza problemi, leggendo in rete ho visto che a volte in base al controller che si acquista (originale o meno), i pin del connettore vanno connessi in modo diverso, ho provato in diversi modi, ma solo in un modo mi viene stampato su serial monitor quello che gli dico io di stampare (come stringhe) ma senza dati dal controller, negli altri modi non stampa proprio nulla sul serial monitor.

Qui ho preso info sul connettore:

http://www.alfonsomartone.itb.it/rkxncv.html
http://wiire.org/Wii/protocols/wiimote_bus

Qui ho preso il file della libreria e il codice dello sketch:

“WiiChuck” Wii Nunchuck Adapter Available – todbot blog

Io ho connesso il tutto così:


| 1 3 5 |
| 2 4 6 |
|---|

1 -> DATA -> ANALOG4
2 -> GROUND -> GND
3 -> NON CONNESSO
4 -> NON CONNESSO
5 -> POWER 3,3V -> 3,3V ARDUINO
6 -> CLOCK ->ANALOG5

Questo è lo sketch che ho utilizzato

/*
 * WiiChuckDemo -- 
 *
 * 2008 Tod E. Kurt, http://thingm.com/
 *
 */

#include <Wire.h>
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx, accy, zbut, cbut;
int ledPin = 13;


void setup()
{
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
    
    Serial.print("WiiChuckDemo ready\n");
}

void loop()
{
    if( loop_cnt > 100 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        zbut = nunchuck_zbutton();
        cbut = nunchuck_cbutton(); 
            
        Serial.print("accx: "); Serial.print((byte)accx,DEC);
        Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
        Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
        Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);
    }
    loop_cnt++;
    delay(1);
}

E questo è l'output che ottengo:

WiiChuckDemo ready
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0
accx: 255 accy: 255 zbut: 0 cbut: 0

Perchè non leggo nessun dato dal joystich???
C'è qualche problema nella connessione dei contatti del connettore del wiimote o c'è qualche problema nella libreria???

Grazie anticipato per l'aiuto

debug86:
Salve ragazzi anche io sto giocando con il wii nunchuk...

Prova questo sketch http://www.robot-italy.net/roboforum/showthread.php?t=4084

Ciao
QP

io non so cosa ha il mio programma per arduino ho provato con gli alti codici ma non è mai contento un errore lo trova sempre :frowning:

Si, è lo stesso tipo di connessione che ho usato io, per ora mi basta vedere i valori presi dal controller sul serial monitor, cosa farci è il passo successivo...

Ragazzi il problema non potrebbe essere dovuto al fatto che sto utilizzando un controller non originale???

Usa questa libreria , é compatibile con l'ide 1.0 ed ha i codici di inizializzazione per il controller tarocchi http://www.gabrielbianconi.com/projects/arduinonunchuk/
Ciao Niko