Variables for every button/joystick on wiichuck

edited March 2017 in Arduino

Hello! I hope I made the post in the correct forum -- I've read the rules, but I do apologize if I made a mistake! I've searched the forums and Google for any help, but the one possible post that could have helped is deleted! D'oh!

Anyway, I've been working on a class project where I want to be able to draw freehand in Processing. This project contains two parts: connecting the wiichuck to the Arduino, and then using the Serial/drawing in Processing. The first works, but the second one is giving me problems. Admittedly, before this class, I've never heard nor used Processing, so I'm pretty much an idiot wandering blind as a bat here.

I got as far as having lines appear, but anytime I try to edit or add variables, it goes poof. I honestly just want to be able to have some freehand lines so that they can be manipulated with the wiichuck controls. That's really the only piece of code I want to learn to use and have for this.

Here's the code, in its current state:

   import remixlab.bias.*;
    import remixlab.bias.event.*;
    import remixlab.dandelion.constraint.*;
    import remixlab.dandelion.core.*;
    import remixlab.dandelion.geom.*;
    import remixlab.fpstiming.*;
    import remixlab.proscene.*;
    import remixlab.util.*;


    import net.java.games.input.*;
    import org.gamecontrolplus.*;
    import org.gamecontrolplus.gui.*;

    import at.mukprojects.console.*;


    // Processing sketch to draw line that follows nunchuck data
    import processing.serial.*;
    float accy;
    float accx;
    float zbut;
    float x1, x2;
    float y1, y2;
    float cbut;


    //adding a custom font

    PFont font;
    // creates a processing font value named font
    import fontastic.*;

    Serial myPort;  // Create object from Serial class
    public static final short portIndex = 1;

    void setup()
    {
        size(500, 500);
      // Open whatever port is the one you're using - See Chapter 4
      myPort = new Serial(this,Serial.list()[0], 9600);

      font = loadFont("ArtistampMedium-40.vlw");
      textFont(font);
      text("Style is influence is style", 26, 30, 260, 200);
      /*
      assigns the font stored in the
      font variable to textFont
      */

      strokeWeight(3);
      x1= cos(accy);
      y1= cos(accx);
    }


    void draw()
    { 

      if ( myPort.available() > 0) {  // If data is available,
        int y = myPort.read();        // read it and store it in val
        int x = myPort.read();        // read it and store it in val
        int z = myPort.read();        // read it and store it in val
        int c = myPort.read();        // read it and store it in val

        background(255);              // Set background to white
      x1= cos(accy);
      y1= cos(accx);
      line(x1, y1, x2, y2);
    }
    }

Any help would be appreciated. Thank you!

Tagged:

Answers

  • It will be great to see your arduino code. What are those imports on top of the code? If you are receiving the data trough your arduino via serial, then I doubt you need any other library unless you want to use any provided library to manipulate data streamed through the arduino unit. Could you clarify on those imports lines, what are they use for? Or did you just copy them as part of a previous example?

    Alternative, you could describe what data will arrive via serial and how to precisely use this data to produce lines.

    A final point and to complement your post, what arduino unit are you using and how does it interact with your wiichuck device?

    Kf

  • edited March 2017

    No problem! Here's my Arduino code -- I added the y,z and c in the get_data line group, but more or less I've left it intact:

    /*
     * nunchuck_lines sketch
     * sends data to Processing to draw line that follows nunchuk movement
     */
    #include <Wire.h> // initialize wire
    #include "nunchuck_funcs.h"
    byte accx,accy,zbut,cbut;
    void setup()
    {
      Serial.begin(9600);
      nunchuck_setpowerpins();
      nunchuck_init();
    }
    void loop()
    {
      nunchuck_get_data();
      accx  = nunchuck_accelx();
      accy  = nunchuck_accely();
      zbut  = nunchuck_zbutton();
      cbut  = nunchuck_cbutton();
      if( accx >= 75 && accx <= 185)
      {
        // map returns a value from 0 to 63 for values from 75 to 185
        byte  y = map(accx, 75, 185, 0, 63);
        Serial.print(y);
      }
      delay(100); // the time in milliseconds between redraws
    }
    

    I'm using the Arduino UNO unit and I'm using a Wiichuck Adapter so it can interact with my wiichuck. EDIT: Forgot to add that, all the numbers in the serial monitor work whenever I manipulate the wiichuck.

    The imports on the top of the code are imports that allow for any game console to be used and proscene, which allows for more interactivity? That's what I understood. I downloaded/installed them directly from Processing's libraries. The initial base code worked just fine without them, but I added them because I thought maybe they'd allow me more control in lineart variables than what I have right now, haha.

    The data I want to receive through Arduino is basically accelerometer data (I hope I used that right), which would allow anyone to manipulate a line in Processing, in the way you would with a tablet in any art program. If you use the z or c button to fill in for example, and the x and y axis to draw the lines. I suppose more like a less-expensive glorifed Cintiq! Does that help clarify things?

  • edited March 2017

    Not sure how the forum feels about double posting, but I thought I should update: I changed the code in the Arduino to see if I could get my Processing code to work. While it hasn't done anything (in other words, I'm still stuck on my original problem), I'm posting the new code here:

        /*
         * NunchuckPrint
         *
         * 2007 Tod E. Kurt, http://todbot.com/blog/
         *
         * The Wii Nunchuck reading code is taken from Windmeadow Labs
         *   http://www.windmeadow.com/node/42
         */
    
        #include <Wire.h>
    
        void setup()
        {
          Serial.begin(19200);
          nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr
          nunchuck_init(); // send the initilization handshake
          Serial.print ("Finished setup\n");
        }
    
        void loop()
        {
          nunchuck_get_data();
          nunchuck_print_data();
          delay(100);
        }
    
    
        //
        // Nunchuck functions
        //
    
        static uint8_t nunchuck_buf[6];   // array to store nunchuck data,
    
        // Uses port C (analog in) pins as power & ground for Nunchuck
        static void nunchuck_setpowerpins()
        {
        #define pwrpin PORTC3
        #define gndpin PORTC2
            DDRC |= _BV(pwrpin) | _BV(gndpin);
            PORTC &=~ _BV(gndpin);
            PORTC |=  _BV(pwrpin);
            delay(100);  // wait for things to stabilize        
        }
    
        // initialize the I2C system, join the I2C bus,
        // and tell the nunchuck we're talking to it
        void nunchuck_init()
        { 
          Wire.begin();                  // join i2c bus as master
          Wire.beginTransmission(0x52);  // transmit to device 0x52
          Wire.write(0x40);    // sends memory address
          Wire.write(0x00);    // sends sent a zero.  
          Wire.endTransmission();  // stop transmitting
        }
    
        // Send a request for data to the nunchuck
        // was "send_zero()"
        void nunchuck_send_request()
        {
          Wire.beginTransmission(0x52);  // transmit to device 0x52
          Wire.write(0x00);    // sends one byte
          Wire.endTransmission();  // stop transmitting
        }
    
        // Receive data back from the nunchuck, 
        int nunchuck_get_data()
        {
            int cnt=0;
            Wire.requestFrom (0x52, 6);  // request data from nunchuck
            while (Wire.available ()) {
              // receive byte as an integer
              nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
              cnt++;
            }
            nunchuck_send_request();  // send request for next data payload
            // If we recieved the 6 bytes, then go print them
            if (cnt >= 5) {
             return 1;   // success
            }
            return 0; //failure
        }
    
        // 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 nunchuck_print_data()
        { 
          static int i=0;
          int joy_x_axis = nunchuck_buf[0];
          int joy_y_axis = nunchuck_buf[1];
          int accel_x_axis = nunchuck_buf[2]; // * 2 * 2; 
          int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
          int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;
    
          int z_button = 0;
          int c_button = 0;
    
          // byte nunchuck_buf[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 ((nunchuck_buf[5] >> 0) & 1) 
            z_button = 1;
          if ((nunchuck_buf[5] >> 1) & 1)
            c_button = 1;
    
          if ((nunchuck_buf[5] >> 2) & 1) 
            accel_x_axis += 2;
          if ((nunchuck_buf[5] >> 3) & 1)
            accel_x_axis += 1;
    
          if ((nunchuck_buf[5] >> 4) & 1)
            accel_y_axis += 2;
          if ((nunchuck_buf[5] >> 5) & 1)
            accel_y_axis += 1;
    
          if ((nunchuck_buf[5] >> 6) & 1)
            accel_z_axis += 2;
          if ((nunchuck_buf[5] >> 7) & 1)
            accel_z_axis += 1;
    
          Serial.print(i,DEC);
          Serial.print("\t");
    
          Serial.print("joy:");
          Serial.print(joy_x_axis,DEC);
          Serial.print(",");
          Serial.print(joy_y_axis, DEC);
          Serial.print("  \t");
    
          Serial.print("acc:");
          Serial.print(accel_x_axis, DEC);
          Serial.print(",");
          Serial.print(accel_y_axis, DEC);
          Serial.print(",");
          Serial.print(accel_z_axis, DEC);
          Serial.print("\t");
    
          Serial.print("but:");
          Serial.print(z_button, DEC);
          Serial.print(",");
          Serial.print(c_button, DEC);
    
          Serial.print("\r\n");  // newline
          i++;
        }
    
        // 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;
        }
    

    I'm still using the same board and adapter, by the by!

  • edited March 2017

    YOu should check any of the previous serialEvent posts. For example, here is one: https://forum.processing.org/two/discussion/comment/92348/#Comment_92348

    You need to adapt your code in arduino and then in processing. I looked at you code from the first two posts and there is no connection between those two codes. Then you last post of arduino looks more promising but then your processing code needs to be adapt it.

    But then before you implement any changes, you need to learn how the serialEvent works. For this, you need to read all the entries in the Processing's webpage under libraries >> Serial. This is a good start to understand the tools you will be using for your task. Also study the example in the link I provided you. Although the example uses an arduino unit, the process of sending data would be the same. Keep in mind I am assuming the wiichuck controller is sending data as you described in your posts. You can always provide a link to your resources and any other documentation and any forum goer will be able to assist you better.

    Here is an example of how your wiichuck loop should look like:

    void loop()
    {
      nunchuck_get_data();
      accx  = nunchuck_accelx();
      accy  = nunchuck_accely();
      zbut  = nunchuck_zbutton();
      cbut  = nunchuck_cbutton();
    
      print(accx);
      print(',');
      print(accy);
      print(',');
      print(zbut);
      print(',');
      println(cbut);
    
      delay(100); // the time in milliseconds between redraws
    }
    

    Kf

  • Okay, maybe I am too stupid for this project in general more than I thought :-S

    So I read over the Serial library like you told me to, and while I'm beginning to understand what does what, anytime I try to adapt it for the wiichuck, nothing seems to work. If anything, Processing tells me that part of the Serial codes like buffer are invalid! :\ It's not the first time the program has told me that codes for it are invalid...

    I will try to see what it is I'm doing wrong (because again, I'm too stupid), but yeah, let me leave what it is I'm using for resources and documentation!

    In the attached files, is the Arduino code with the wiichuck loop and Arduino telling me to declare the scope even though I have? And the other file is what I would like the end product to be: a canvas where you can doodle or draw anything you want.

    arduino bytes test with drawing

    So in that sense, I want to do something like this: https://processing.org/examples/continuouslines.html

    The second Arduino code I posted comes from here: https://github.com/olavolav/MIDIDance/blob/master/sendOneNunchuckData/sendOneNunchuckData.ino

    (There's another version here, but that seems to be for Processing, based on the .pde extension. Hmmm.) https://todbot.com/arduino/sketches/NunchuckPrint/NunchuckPrint.pde

    Meanwhile, the Processing code I used in my first post (albeit without the added imports and such) came from the Arduino Cookbook by Michael Margolis, pg.397-401. From his section on the Wiichuck Accelerometer.

  • Post your latest code please.

    Kf

  • Start by using the code in your arduino from your prev post: https://todbot.com/arduino/sketches/NunchuckPrint/NunchuckPrint.pde

    In processing use:

    import processing.serial.*; 
    
    Serial myPort;
    
    void setup() {
      String portName = Serial.list()[0];
      myPort = new Serial(this, portName, 9600);
    
    } 
    
    void draw() { }
    
    void serialEvent(Serial myPort){
      String val = myPort.readStringUntil('\n');
    
      if(val==null)
        return;
    
      println(frameCount + " : " + trim(val));
    
    }
    

    This will test what data is arriving from your Arduino or at least that the data is being transferred.

    Kf

  • Oops, I actually forgot to put the code in my previous post! Sorry about that, here's the Arduino version (which only has the nunchuck_get data added in)

        /*
         * NunchuckPrint
         *
         * 2007 Tod E. Kurt, http://todbot.com/blog/
         *
         * The Wii Nunchuck reading code is taken from Windmeadow Labs
         *   http://www.windmeadow.com/node/42
         */
    
        #include <Wire.h>
    
        void setup()
        {
          Serial.begin(19200);
          nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr
          nunchuck_init(); // send the initilization handshake
          Serial.print ("Finished setup\n");
        }
    
        void loop()
        {
          nunchuck_get_data();
          accx  = nunchuck_accelx(10);
          accy  = nunchuck_accely(50);
          zbut  = nunchuck_zbutton(100);
          cbut  = nunchuck_cbutton(150);
    
          print(accx);
          print(',');
          print(accy);
          print(',');
          print(zbut);
          print(',');
          println(cbut);
    
          delay(100); // the time in milliseconds between redraws
        }
    
    
        //
        // Nunchuck functions
        //
    
        static uint8_t nunchuck_buf[6];   // array to store nunchuck data,
    
        // Uses port C (analog in) pins as power & ground for Nunchuck
        static void nunchuck_setpowerpins()
        {
        #define pwrpin PORTC3
        #define gndpin PORTC2
            DDRC |= _BV(pwrpin) | _BV(gndpin);
            PORTC &=~ _BV(gndpin);
            PORTC |=  _BV(pwrpin);
            delay(100);  // wait for things to stabilize        
        }
    
        // initialize the I2C system, join the I2C bus,
        // and tell the nunchuck we're talking to it
        void nunchuck_init()
        { 
          Wire.begin();                  // join i2c bus as master
          Wire.beginTransmission(0x52);  // transmit to device 0x52
          Wire.write(0x40);    // sends memory address
          Wire.write(0x00);    // sends sent a zero.  
          Wire.endTransmission();  // stop transmitting
        }
    
        // Send a request for data to the nunchuck
        // was "send_zero()"
        void nunchuck_send_request()
        {
          Wire.beginTransmission(0x52);  // transmit to device 0x52
          Wire.write(0x00);    // sends one byte
          Wire.endTransmission();  // stop transmitting
        }
    
        // Receive data back from the nunchuck, 
        int nunchuck_get_data()
        {
            int cnt=0;
            Wire.requestFrom (0x52, 6);  // request data from nunchuck
            while (Wire.available ()) {
              // receive byte as an integer
              nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
              cnt++;
            }
            nunchuck_send_request();  // send request for next data payload
            // If we recieved the 6 bytes, then go print them
            if (cnt >= 5) {
             return 1;   // success
            }
            return 0; //failure
        }
    
        // 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 nunchuck_print_data()
        { 
          static int i=0;
          int joy_x_axis = nunchuck_buf[0];
          int joy_y_axis = nunchuck_buf[1];
          int accel_x_axis = nunchuck_buf[2]; // * 2 * 2; 
          int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
          int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;
    
          int z_button = 0;
          int c_button = 0;
    
          // byte nunchuck_buf[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 ((nunchuck_buf[5] >> 0) & 1) 
            z_button = 1;
          if ((nunchuck_buf[5] >> 1) & 1)
            c_button = 1;
    
          if ((nunchuck_buf[5] >> 2) & 1) 
            accel_x_axis += 2;
          if ((nunchuck_buf[5] >> 3) & 1)
            accel_x_axis += 1;
    
          if ((nunchuck_buf[5] >> 4) & 1)
            accel_y_axis += 2;
          if ((nunchuck_buf[5] >> 5) & 1)
            accel_y_axis += 1;
    
          if ((nunchuck_buf[5] >> 6) & 1)
            accel_z_axis += 2;
          if ((nunchuck_buf[5] >> 7) & 1)
            accel_z_axis += 1;
    
          Serial.print(i,DEC);
          Serial.print("\t");
    
          Serial.print("joy:");
          Serial.print(joy_x_axis,DEC);
          Serial.print(",");
          Serial.print(joy_y_axis, DEC);
          Serial.print("  \t");
    
          Serial.print("acc:");
          Serial.print(accel_x_axis, DEC);
          Serial.print(",");
          Serial.print(accel_y_axis, DEC);
          Serial.print(",");
          Serial.print(accel_z_axis, DEC);
          Serial.print("\t");
    
          Serial.print("but:");
          Serial.print(z_button, DEC);
          Serial.print(",");
          Serial.print(c_button, DEC);
    
          Serial.print("\r\n");  // newline
          i++;
        }
    
        // 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;
        }
    

    and the Processing code I've been working as I try to understand the Serial libraries further:

        import processing.serial.*;
    
        // The serial port:
        Serial myPort;       
        String inString;  // Input string from serial port
    
        static final int VALUES = 3, PORT_IDX = 0, BAUDS = 9600;
        int[] vals = new int[VALUES];
        boolean dataArrived;
    
        void setup (){
        size(400,200);
        frameRate(30);
    
          // List all the available serial ports:
        printArray(Serial.list());
    
        // Open the port you are using at the rate you want:
        myPort = new Serial(this, Serial.list()[0], 9600);
    
        // Send a capital A out the serial port:
        myPort.write(185);
        }
    
        void draw() {  
        boolean a = false; 
        if (!a) {  
        a = true; 
        if (a) { 
          random(0, 10) ; 
        } 
    
          while (myPort.available() > 0) { // returns the number of bytes available
            int inByte = myPort.read(); //    Returns a number between 0 and 255 for the
           // next byte that's waiting in the buffer. Returns -1 if there is no byte, 
           // although this should be avoided by first cheacking available() to see if data is available. 
            println(inByte);
          }
    
        void serialEvent(Serial p) { 
          inString = p.readString(); 
        }
        }
    

    So I've tried the Processing code you posted and am receiving the following in BAUDRATE 19200, which compared to 9600 LOOKS a lot better, haha.

        98 : 213,113    but:1,1
        98 : 62 joy:254,128     acc:153,93,97   but:1,1
        98 : 1,1
        98 : 60 joy:139,128     acc:200,113,116 but:1,1
        98 : 61 joy:254,128     acc:166,93,113  but:1,1
        98 : 62 joy:254,128     acc:153,93,97   but:1,1
        98 : Finished setup
        99 : 0  joy:255,255     acc:258,258,258 but:1,1
        105 : 1 joy:0,128   acc:174,111,138 but:1,1
        111 : 2 joy:128,128     acc:166,132,126 but:1,1
        117 : 3 joy:128,128     acc:217,165,176 but:1,1
        123 : 4 joy:128,128     acc:181,130,125 but:1,1
        129 : 5 joy:128,128     acc:179,130,121 but:1,1
        136 : 6 joy:128,128     acc:181,131,121 but:1,1
        142 : 7 joy:128,128     acc:179,131,121 but:1,1
        148 : 8 joy:128,128     acc:182,132,123 but:1,1
        154 : 9 joy:128,128     acc:181,132,121 but:1,1
        160 : 10    joy:128,128     acc:181,130,121 but:1,1
        166 : 11    joy:128,128     acc:179,130,121 but:1,1
        172 : 12    joy:128,128     acc:181,130,121 but:1,1
        179 : 13    joy:128,128     acc:179,132,121 but:1,1
        185 : 14    joy:128,128     acc:179,132,121 but:1,1
        191 : 15    joy:128,128     acc:181,132,121 but:1,1
        197 : 16    joy:128,128     acc:179,130,121 but:1,1
        203 : 17    joy:128,128     acc:179,132,121 but:1,1
        209 : 18    joy:128,128     acc:181,132,121 but:1,1
        215 : 19    joy:128,128     acc:181,132,123 but:1,1
        221 : 20    joy:128,128     acc:179,130,121 but:1,1
        227 : 21    joy:128,128     acc:181,130,123 but:1,1
        234 : 22    joy:128,128     acc:181,132,121 but:1,1
        240 : 23    joy:128,128     acc:181,132,121 but:1,1
        246 : 24    joy:128,128     acc:179,132,123 but:1,1
        252 : 25    joy:128,128     acc:181,130,123 but:1,1
        258 : 26    joy:128,128     acc:181,132,123 but:1,1
        264 : 27    joy:128,128     acc:179,132,123 but:1,1
        270 : 28    joy:128,128     acc:181,130,123 but:1,1
        277 : 29    joy:128,128     acc:179,132,123 but:1,1
        283 : 30    joy:128,128     acc:181,130,123 but:1,1
        289 : 31    joy:128,128     acc:179,130,123 but:1,1
        295 : 32    joy:128,128     acc:181,132,123 but:1,1
        301 : 33    joy:128,128     acc:179,132,123 but:1,1
        307 : 34    joy:128,128     acc:181,130,123 but:1,1
        313 : 35    joy:128,128     acc:181,130,123 but:1,1
        320 : 36    joy:128,128     acc:181,132,123 but:1,1
        326 : 37    joy:128,128     acc:181,132,123 but:1,1
        332 : 38    joy:128,128     acc:179,130,123 but:1,1
        338 : 39    joy:128,128     acc:181,130,123 but:1,1
        344 : 40    joy:128,128     acc:181,130,123 but:1,1
        350 : 41    joy:128,128     acc:179,132,123 but:1,1
        356 : 42    joy:128,128     acc:179,132,123 but:1,1
        363 : 43    joy:128,128     acc:179,132,123 but:1,1
        369 : 44    joy:128,128     acc:179,130,123 but:1,1
        375 : 45    joy:128,128     acc:179,132,123 but:1,1
        381 : 46    joy:128,128     acc:179,132,123 but:1,1
        387 : 47    joy:128,128     acc:179,130,123 but:1,1
        393 : 48    joy:128,128     acc:179,130,123 but:1,1
        399 : 49    joy:128,128     acc:181,130,123 but:1,1
        406 : 50    joy:128,128     acc:179,132,123 but:1,1
        412 : 51    joy:128,128     acc:179,132,123 but:1,1
        418 : 52    joy:128,128     acc:179,130,123 but:1,1
        424 : 53    joy:128,128     acc:181,130,123 but:1,1
        430 : 54    joy:128,128     acc:181,132,123 but:1,1
        436 : 55    joy:128,128     acc:179,132,123 but:1,1
        442 : 56    joy:128,128     acc:179,132,123 but:1,1
        448 : 57    joy:128,128     acc:179,130,123 but:1,1
        455 : 58    joy:128,128     acc:179,130,123 but:1,1
    

    and BAUDRATE 9600 -- which was much more longer, but I put a snippet of it here just so you can see how it looked for rows and rows of code:

            99 : ½Äþ½Ä§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠjŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)(ˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þŠŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠjŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)(ˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þ??1kúÿ¼§!L)
            99 : Œ
            99 : Œ
            153 : ŒüO•=þ?§¥Š!)ˆˆHˆŒüO•?þ¼§¥ŠÉˆˆHŠŒüO•?þ§¥Š)ˆˆkŠŒüO•?þ¼§¥Š)ˆˆHŠHˆüO•?þħ¥Š)ˆˆHŠŒüO•?þ¼§¥Š)ˆˆHŠŒüO•?þ"§¥Š)ˆˆHŠŒüO•?þ¼§¥Š)ˆˆHŠHŒüO•?þ?§¥
            1694 : )ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆªHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆHŠŒüO•#þ½Ä§¥Š)ˆˆHŠŒüO•?þµÄs¥Š)ˆˆHŠŒüO•?þ½Ä§¥lŠ)ˆˆHŠŒüO•?þ¥Ä§¥Šc)ˆˆHŠŒüO•?þ­Ä§¥Š)*ˆHŠŒüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠlüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüO•?þjt§¥Š)ˆˆHŠŒüO•?þzħeŠ)ˆˆHŠŒüO•?þjħ¥Š)ˆˆHŠŒüï•?þzħ¥ŠÉˆˆHŠŒüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠhŒüO•?þ!œ§¥*)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•?þ¡œ§¥Š)HŒHŠŒüO•?þ)œ§¥Š)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•"þ)œ§¥Š)ÈŒHŠHˆüO•?þ)œ§¥Š)ˆˆHªŒüO•?þ1œ§¥Š)ˆˆHŠŒüO•?þ1œ§¥Šc)ˆˆHŠŒüO•?þKħ¥Š)*ˆHŠŒüO•?þ[ħ¥Š)HŒHŠŒüO•?þKħ¥Š)ˆˆHŠlüO•?þ[ħ¥Š()ˆˆHŠŒüO•?þkħ¥Š)ˆˆHŠŒüO•?þ{ħ¥Š)HŒhŠHˆüO•?þkħ¥Š)ˆˆHŠküO•?þ{ħ¥Š)ˆˆHŠŒüO•?þKħ¥Š)ˆˆHŠŒüO•?þ[ħ¥Š)HŒHŠŒüO•?þˆ¼§¥Š)ˆˆHŠhŒüO•?þˆ¼§¥Š)ˆˆHŠŒüO•?þŠ¼§¥Š)ˆˆHŠŒüO•?þk¼§¥Š)ˆˆHŠŒüO•?þˆ¼§¥Š)ˆˆHŠkŒüO•?þˆ¼§¥Š)ˆˆHŠŒüO•?þŠ¼§¥Šd)HŒHŠŒüO•?þŠ¼§¥Š)ˆˆHŠŒüO•?þŒ¼§¥Š)HŒHªHˆüO•?þŒ¼§¥dŠ)HŒHŠHˆüO•?þKħ¥Š)ˆˆHŠŒüO•?þ[ħ¥Š)ˆˆHŠŒüO•?þKħ¥Š)ˆˆHˆŒüO•?þ[ħ¥Š)ˆˆHŠlüO•?þkħ¥Š)ˆˆHŠŒüO•?þ{ħ¥Š)ˆˆHŠŒüO•?þkt§¥Š)ˆˆHŠŒüO•?þ{ħeŠ)ˆˆHˆHˆüO•?þKħ¥Š!)ˆˆHˆŒüO•?þ[ħ¥ŠÉˆˆHˆHˆüO•?þˆ¼§¥Š)ˆˆHˆHˆüO•?þˆ¼§RŠ)HŒHŠŒüO•?þŠ¼§¥Š)ˆˆHŠHˆüO•?þŠ¼§¥Š)ˆˆHŠŒüO•?þˆ¼§¥Š)ˆªHŠHˆüO•?þˆ¼w¥Š)ˆˆHˆHˆüO•?þŠ¼§¥Š)HŒHˆŒŒO•?þŠ¼§¥Š)ˆˆHŠŒüO•?þŒ¼§¥Š)ˆHŠŒüO•?þŒ¼§¥Š)ˆˆHªŒüO•?þJħ¥Š)ˆˆHŠHˆüO•?þZħ¥Š)ˆˆHŠŒüOe?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüO•?þjħ¥Š)ˆˆHŠlüO•?þzħ¥Š)ˆˆHŠHˆüO•?þjħ¥Š©ˆˆHŠHˆüO•?þzħ¥Š)ˆˆhŠŒüO•?þJħeŠ)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüï•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠhŒüO•?þ­Ä§¥*)ˆˆHˆŒüO•?þµÄ§¥Š)ˆˆHŠŒüO•þ]ħ¥Š)ˆˆHŠŒüO•?þµÄg¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥?§¥Š)ˆˆHŠlüO•?þ¥§¥Š()ˆˆHŠŒüO•?þ¥§¥Š)HŒHˆHˆüO•?þ¥Ä§¥Š)HŒjŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)HŒHŠŒüO•?þ¥Ä§¥Š)ˆˆHˆŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥?§¥Š)ˆˆHˆ*ˆüO•?þ­Ä§¥Š)ˆˆHˆŒüO•?þ­?§¥Š)ˆˆHŠHˆüO•%þ­§¥Š)ˆˆHˆHˆüO•?þ­§¥Š)ˆˆH¨HˆüO•?þ­Ä§¥Š)HŒHŠHˆ…O•?þ­Ä§¥Š)ˆˆHŠŒüOu?þ­Ä§¥Š)êŒHŠŒüO•?þ­Ä§¥Š)ˆˆHˆŒüO•?þ­Ä§¥Š)HŒHŠHˆüO•?þ­?§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥ŠéˆˆHŠHˆüO•?þ¥?§¥Š)ˆˆkŠHˆüO•?þ¥§SŠ)ˆˆHŠHˆüO•?þ¥§¥Š)ˆˆHŠHˆüå•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥Š)ˆˆHŠHˆ„O•?þ¥Ä§¥Šd)ˆˆHˆHˆüO•?þ¥?§¥Š)(ˆHŠŒüO•?þ­Ä§¥Š)ˆˆHˆHˆüO•?þ­?§¥Š)ˆˆHˆHˆüO•?þ­§¥Š)ˆˆHŠHˆüO•?þ­§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHˆŒüO•?þ­Ä§eŠ)HŒHŠHˆüO•?þ­Ä§¥Š)ˆˆHŠŒüï•?þ­Ä§¥ŠÉˆˆHŠŒüO•?þ­#§¥Š)ˆˆHˆŒüO•?þ­?§¥Š)ˆˆHŠHˆüO•?þµÄ§¥Š)HŒHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•%þU§¥Š)ˆˆHŠHˆüO•?þµs¥Š)ˆˆHŠHˆüO•?þµÄ§¥lŠ)HŒHŠHˆüO•?þµÄ§¥Š)ˆˆHŠŒüOu?þµÄ§¥Š)*ˆHŠŒüO•?þµÄ§¥Š)ˆˆHˆŒüO•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ?§¥Š()ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠHˆüO•?þ½?§¥Š)ˆˆkŠŒüO•?þ½§¥Š)ˆˆHˆHŒüO•?þ½§¥*)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHˆHˆüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½Äw¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠHˆŒO•?þ½Ä§¥Šd)ˆˆHŠHˆüO•?þC?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ?§¥eŠ)ˆˆHˆŒüO•?þµ§¥Š)ˆˆHŠHˆüOc?þµ§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆhŠŒüO•?þµÄ§eŠ)ˆˆHŠŒüO•?þµÄ§¥Š)HŒHŠŒüï•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ#§¥Š)ˆˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHˆHˆüO•?þ½?§¥Š)HŒHŠHˆüO•-þ½§¥Š)ˆ©HŠHˆüO•?þ½§¥Š)ˆˆHŠHˆüO•?þ½Ä§¥lŠ)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHˆŒüOU?þ½Ä§¥Š)èŒHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠLüO•?þ½?§¥Š()ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥?§¥Š)ˆˆhŠHˆüO•?þ¥§UŠ)ˆˆHŠŒüO•?þ¥§¥Š)ˆˆHˆHˆüç•?þ¥Ä§¥ŠÎˆˆHˆHˆüO•?þ¥Ä§¥Š)ˆ¨HŠHˆüO•?þ¥Äg¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒ¼O•?þ¥Ä§¥ŠD)ˆˆHˆHˆüO•?þe?§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠŒüO•?þ­?§¥dŠ)ˆˆHŠŒüO•?þ­§¥Š)ˆˆHŠŒüOe?þ­§¥Š)+ˆHŠHˆüO•?þ­Ä§¥Š)ˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠHhüO•?þ­Ä§¥Š )ˆˆHŠHˆüO•?þ­Ä§¥ŠÉˆˆHŠŒüO•?þ­Ä§¥Š)ˆˆHŠHˆüO•?þ­?§SŠ)ˆˆHŠHˆüO•?þJ¼§¥*)ˆˆHŠŒüO•?þJ?§¥Š)ˆˆHŠŒüO•?þJ¼§¥Š)ˆªHŠHˆüO•?þJw¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒ„O•?þJħ¥Š)ˆˆHˆHˆüO•?þJ¼§¥Š)(ˆHŠHˆüO•?þJħ¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒüO•?þJ?§¥Š)ˆˆHŠHˆüOb?þZ¼§¥Š)ˆˆHˆHˆüO•?þZ?§¥Š)HŒHˆŒüO•?þZ¼§¥Š)ˆˆHŠHˆüO•?þZ§¥Š)ˆˆHŠŒüï•?þZ¼§¥ŠÏˆˆHŠHˆüO•?þZħ¥Š)ˆˆHŠHˆüO•?þZ¼§¥Š)ˆˆHŠ*ˆüO•?þZħ¥Š)ˆˆHŠHˆ¼O•?þZ¼§¥ŠD)ˆˆHŠŒüO•?þŠ?§¥Š)HŒHˆHˆüO•?þJ¼§¥Š)ˆˆHˆŒüO•?þJ?§¥Š)HŒHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒüO•?þJ§¥Š)ˆˆHŠŒüO•?þJ¼§¥Š)ˆˆHˆHˆüO•?þJħ¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š )ˆˆHŠŒüO•?þJħ¥ŠéˆˆHŠŒüO•?þJ¼§¥Š)ˆˆkŠHˆüO•?þJ?§¥Š)ˆˆHŠHˆüO•?þZ¼§¥*)ˆˆHŠHˆüO•?þZ?§¥Š)ˆˆHŠHˆüO•=þZ¼§¥Š)ˆ¨HŠHˆüO•?þZw¥Š)ˆˆHŠHˆüO•?þZ¼§¥Š)ˆˆHŠHˆüO•?þZħ¥Šd)ˆˆHŠHˆüO•?þZ¼§¥Š)(ˆHŠHˆüO•?þZħ¥Š)ˆˆHªHˆüO•?þZ¼§¥eŠ)ˆˆHŠHˆüO•?þZ?§¥Š)HŒHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þj?§¥Š)ˆˆhŠHˆüO•?þj¼§¥Š)ˆˆHˆHküO•?þj§¥Š)ˆˆHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þjħ¥Š)ˆ¨HˆŒüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þjħ¥Š)ˆˆHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þj?§¥Š)ˆˆHˆHˆüO•?þz¼s¥Š)ˆˆHŠHˆüO•?þz?§¥lŠ)HŒHŠHˆüO•?þz¼§¥Š)HŒHŠHˆüOu?þz§¥Š)ˆˆHŠHˆüO•?þz¼§¥Š)ˆˆHŠŒüO•?þzħ¥Š)ˆˆHŠlüO•?þz¼§¥Š )HŒHŠHˆüO•?þzħ¥ŠéˆˆHŠHˆüO•?þz¼§¥Š)ˆˆkŠHˆüO•?þz?§¥Š)ˆˆHŠHˆüO•?þj¼§¥
    

    If I'm not mistaken, considering how the 19200 one went, I suppose it means I can edit it to the point where I can do my original purpose with it, right? (Though honestly I'm just happy the data is FINALLY being seen in Processing! That was the only part I never saw in all my attempts.)

  • Answer ✓

    You should match the baud rate between units. In your nunchuck code line 14 you have 19200 so your Serial code in Processing should be also 19200 (Line 19 in the Serial function)

    Ok, so now it seems everything is working when using the proper baud rate. Good news! Keep working in the code. Whatever you send from your first code, check if you receive it in your second code. After you make sure all your data that you need is send and received properly, then you could work in the processing part as drawing lines or working in any other advanced features. If you get stuck, post your questions and details below.

    Kf

  • Thank you so much really for all your help! :D I'm really glad this has worked, but I definitely still keep getting stuck :\ Here's what I've been tinkering with the Processing code. I keep trying to add values that can match the ones in Arduino, like you mentioned (which I hadn't noticed before!!) but Processing keeps telling me it doesn't work, even though it has in the examples codes I've gotten from other sites like the Cube for Wii (I'll post that after my own code):

        import processing.serial.*; 
    
        Serial myPort;
    
         //adding a custom font
    
        PFont font;
        // creates a processing font value named font
        import fontastic.*;
    
        int accx = 0;
        int accy = 0;
        int zbut = 0;
        int cbut = 0;
    
    
        void setup() {
          String portName = Serial.list()[0];
          myPort = new Serial(this, portName, 19200);
    
          size(640,360);
          strokeWeight(10);
        } 
    
        void draw() { 
        background(0);
          stroke(255);
            line(0,0,0,1);
    
          int accx (0-20);
          int accy (20-100);
          int zbut (101-120);
          int cbut (121-185);
    
        }
    
        void serialEvent(Serial myPort){
          String val = myPort.readStringUntil('\n');
    
          if(val==null)
            return;
    
          println(frameCount + " : " + trim(val));
    
        }
    

    The Cube:

        /**
         * wii controlled
         * RGB Cube.
         * 
         * The three primary colors of the additive color model are red, green, and blue.
         * This RGB color cube displays smooth transitions between these colors. 
         */
    
        float xmag, ymag = 0;
        float newXmag, newYmag = 0; 
    
        int sensorCount = 5;
        //int sensorCount = 4;
        // number of values expected:
        // use 5 if using code from First Example - accelerometers
        // use 4 if using code from Second Example - joystick
    
        import processing.serial.*;
        Serial myPort;                // The serial port
    
        int BAUDRATE = 115200; 
        char DELIM = ','; // the delimeter for parsing incoming data
    
    
        void setup() 
        { 
          size(200, 200, P3D); 
          noStroke(); 
          colorMode(RGB, 1); 
          myPort = new Serial(this, Serial.list()[0], BAUDRATE);
          // clear the serial buffer:
          myPort.clear();
    
        } 
        float x, z;
    
        void draw() 
        { 
          background(0.5, 0.5, 0.45);
    
          pushMatrix(); 
    
          translate(width/2, height/2, -30); 
    
          newXmag = mouseX/float(width) * TWO_PI;
          newYmag = mouseY/float(height) * TWO_PI;
    
          float diff = xmag-newXmag;
          if (abs(diff) >  0.01) { 
            xmag -= diff/4.0; 
          }
    
          diff = ymag-newYmag;
          if (abs(diff) >  0.01) { 
            ymag -= diff/4.0; 
          }
    
    
        //  if ((sensorValues[1] > 15) && (sensorValues[1] < 165)) {
            z = sensorValues[0] / 180 * PI ;
            x = sensorValues[1] / 180 * PI;
         // }
    
           rotateZ(z); 
           rotateX(x); 
          scale(50);
          beginShape(QUADS);
    
          fill(0, 1, 1); 
          vertex(-1,  1,  1);
          fill(1, 1, 1); 
          vertex( 1,  1,  1);
          fill(1, 0, 1); 
          vertex( 1, -1,  1);
          fill(0, 0, 1); 
          vertex(-1, -1,  1);
    
          fill(1, 1, 1); 
          vertex( 1,  1,  1);
          fill(1, 1, 0); 
          vertex( 1,  1, -1);
          fill(1, 0, 0); 
          vertex( 1, -1, -1);
          fill(1, 0, 1); 
          vertex( 1, -1,  1);
    
          fill(1, 1, 0); 
          vertex( 1,  1, -1);
          fill(0, 1, 0); 
          vertex(-1,  1, -1);
          fill(0, 0, 0); 
          vertex(-1, -1, -1);
          fill(1, 0, 0); 
          vertex( 1, -1, -1);
    
          fill(0, 1, 0); 
          vertex(-1,  1, -1);
          fill(0, 1, 1); 
          vertex(-1,  1,  1);
          fill(0, 0, 1); 
          vertex(-1, -1,  1);
          fill(0, 0, 0); 
          vertex(-1, -1, -1);
    
          fill(0, 1, 0); 
          vertex(-1,  1, -1);
          fill(1, 1, 0); 
          vertex( 1,  1, -1);
          fill(1, 1, 1); 
          vertex( 1,  1,  1);
          fill(0, 1, 1); 
          vertex(-1,  1,  1);
    
          fill(0, 0, 0); 
          vertex(-1, -1, -1);
          fill(1, 0, 0); 
          vertex( 1, -1, -1);
          fill(1, 0, 1); 
          vertex( 1, -1,  1);
          fill(0, 0, 1); 
          vertex(-1, -1,  1);
    
          endShape();
    
          popMatrix(); 
        } 
        float[] sensorValues = new float[sensorCount];  // array to hold the incoming values
    
        void serialEvent(Serial myPort) {
          // read incoming data until you get a newline:
          String serialString = myPort.readStringUntil('\n');
          // if the read data is a real string, parse it:
    
          if (serialString != null) {
            //println(serialString);
            //println(serialString.charAt(serialString.length()-3));
            // println(serialString.charAt(serialString.length()-2));
            // split it into substrings on the DELIM character:
            String[] numbers = split(serialString, DELIM);
            // convert each subastring into an int
            if (numbers.length == sensorCount) {
              for (int i = 0; i < numbers.length; i++) {
                // make sure you're only reading as many numbers as
                // you can fit in the array:
                if (i <= sensorCount) {
                  // trim off any whitespace from the substring:
                  numbers[i] = trim(numbers[i]);
                  sensorValues[i] =  float(numbers[i]);
                }
                // Things we don't handle in particular can get output to the text window
                print(serialString);
              }
            }
          }
        }
    

    I even tried going into the H file of the Nunchuck library in Arduino to see if maybe there's a hint I'm missing and I found it weird that part of it looked more like Processing but that's just me mixing everything up at this point probably.

        #ifndef Nunchuck_h
        #define Nunchuck_h
        #include "Accessory.h"
    
    
        // see http://wiibrew.org/wiki/Wiimote/Extension_Nunchuck
        #define joyXBytes     UNUSED, 0, 0, UNUSED ,0   , 0   , BYTE0, BIT0, BIT7
        #define joyYBytes     UNUSED, 0, 0, UNUSED ,0   , 0   , BYTE1, BIT0, BIT7
        #define accelXBytes   UNUSED, 0, 0, BYTE2  ,BIT0, BIT7, BYTE5, BIT2, BIT3
        #define accelYBytes   UNUSED, 0, 0, BYTE3  ,BIT0, BIT7, BYTE5, BIT4, BIT5
        #define accelZBytes   UNUSED, 0, 0, BYTE4  ,BIT0, BIT7, BYTE5, BIT6, BIT7
    
        #define buttonCBits   BYTE5,BIT1,true
        #define buttonZBits   BYTE5,BIT0,true
    
    
        class Nunchuck : public Accessory
        {
        public:
            Nunchuck(uint8_t data_pin, uint8_t sclk_pin);
            void printInputs(Stream& stream);
    
            int getJoyX();
            int getJoyY();
    
            int getRollAngle();
            int getPitchAngle();
            int getAccelX();
            int getAccelY();
            int getAccelZ();
    
    
            boolean checkButtonC();
            boolean checkButtonZ();
    
    
            class joyX : public Accessory::Mapping
            {
            public:
                joyX(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                joyX(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                unsigned int  mapVar();
                void printMap(Stream& stream);
                const uint16_t myMin = 0;
                const uint16_t myZero = 125;
                const uint16_t myMax = 255;
    
            };
    
            class joyY : public Accessory::Mapping
            {
            public:
                joyY(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                joyY(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                unsigned int  mapVar();
                void printMap(Stream& stream);
                const uint16_t myMin = 0;
                const uint16_t myZero = 125;
                const uint16_t myMax = 255;
            };
    
            class roll : public Accessory::Mapping
            {
            public:
                roll(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                roll(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                unsigned int  mapVar();
                void printMap(Stream& stream);
                const int16_t myMin = -180;
                const int16_t myZero = 0;
                const int16_t myMax = 180;
            };
    
    
            class pitch : public Accessory::Mapping
            {
            public:
                pitch(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                pitch(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                unsigned int  mapVar();
                void printMap(Stream& stream);
                const int16_t myMin = -180;
                const int16_t myZero = 0;
                const int16_t myMax = 180;
            };
    
    
            class buttonC : public Accessory::Mapping
            {
            public:
                buttonC(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                buttonC(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                void printMap(Stream& stream);
                unsigned int  mapVar();
            };
    
            class buttonZ : public Accessory::Mapping
            {
            public:
                buttonZ(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min) : Mapping( chan, max, zero, min) {};
                buttonZ(uint8_t chan,uint8_t max,uint8_t zero,uint8_t min, uint16_t cooldown) : Mapping( chan, max, zero, min, cooldown) {};
    
                void printMap(Stream& stream);
                unsigned int  mapVar();
            };
    
        };
    
        #endif
    

    It likely has nothing to do with this in the end, but I'm just getting frustrated at my stupidity. I hate it when I know (hope?) I'm close but every drawing code is made for a mouse and people's custom Nunchuck codes aren't working despite otherwise.

  • @kfrajer: I feel so bad after every piece of help you've given me but the deadline for this is only in a couple of hours and at this rate, I may have to call it "as is." At least I learned enough that I can explain my own goal and process. (And luckily I am not the only one in the class who had some trouble but still, I detest my "incomplete" situation!)

    Again, thank you so much! I'm just going to have to chalk this up to technology + my own stupidity going against me this time.

  • Unfortunately my help is limited as I do not own an unit to test the code on. In cases when you are dealing with hardware (or even software), documentation is key. Yes, using somebody else code works but that is only if the code is up to date and compatible with your unit.

    The cube code above seems alright. Notice in that example they have the option to use accelerometers or joystick. Mixing these two sensors could work for this example, but most of the time mixing sensors that way doesn't work. One reason is that you need to be aware of the units each sensor sends. For example, if you are tapping into an android phone, you can use the accelerometer of this device, or you can inquire for temperature, gps coordinates, etc. Each value returned has their own units (acceleration could be in units of force, gps coordinates in degrees or in UTM, temperature in Celsius or Kelvin, etc) For this reason it is important to get your hands in the documentation. In the documentation it will provide all these details to be able to use your sensor in your application.

    For example, from this site: http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck

    SX,SY are the Analog Stick X and Y positions, while AX, AY, and AZ are the 10-bit accelerometer data (in the same format as described in Wiimote#Accelerometer).
    The values returned by the analog stick in the nunchuk enclosure do not encompass the full possible range, but rather have upper and lower bounds. These bounds seem to be in the same range across Nunchuks, but there is some variation. Analog stick X returns data from around 35 (fully left) to 228(fully right), while analog stick Y returns from around 27 to 220. Center for both is around 128.
    The accelerometer data uses the full range of 0-1024. However, the full range is only seen when moving or rotating the Nunchuk sharply. To measure still Nunchuk rotation in space, the following approximate bounds apply: X goes from around 300 (fully tilted left) to 740 (tilted right), turning further starts bringing the value closer to 512 (neutral position). Similarly, Y goes from around 280 (tilted backwards) to 720 (forwards). Z goes from 320 (upside-down) to 760 (right-side up).

    I don't know if this applies to your unit, further investigation required. From the serial printout you provided above, it seems you were getting the right values. If you are interested to pursue this, please provide the latest arduino and processing code.

    Kf

Sign In or Register to comment.