I2C communication with Nunchuck adapter ONLY works once after sketch uploaded

Hey guys, this is certainly a weird problem. Every time right after I upload the sketch and have NOT removed the USB power, my code has worked fine (serial returns the values that I expect, changing as I move stick/press buttons). However, as soon as I unplug power and then replug it back in, my serial locks up and returns only one set of values (no matter what sticks/buttons I move or press). Does anyone have any idea as to what is going on here?

Sketch:

/*
 * ArduinoNunchukDemo.ino
 *
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 */

#include <Wire.h>
#include <ArduinoNunchuk.h>

#define BAUDRATE 19200

ArduinoNunchuk nunchuk = ArduinoNunchuk();

void setup()
{
  Serial.begin(BAUDRATE);
  nunchuk.init();
}

void loop()
{
  nunchuk.update();

  Serial.print(nunchuk.analogX, DEC);
  Serial.print(' ');
  Serial.print(nunchuk.analogY, DEC);
  Serial.print(' ');
  Serial.print(nunchuk.accelX, DEC);
  Serial.print(' ');
  Serial.print(nunchuk.accelY, DEC);
  Serial.print(' ');
  Serial.print(nunchuk.accelZ, DEC);
  Serial.print(' ');
  Serial.print(nunchuk.zButton, DEC);
  Serial.print(' ');
  Serial.println(nunchuk.cButton, DEC);
}

and the library file:

/*
 * ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
 *
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following resources:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 *
 */

#include <Arduino.h>
#include <Wire.h>
#include "ArduinoNunchuk.h"

#define ADDRESS 0x52

void ArduinoNunchuk::init()
{
  Wire.begin();

  ArduinoNunchuk::_sendByte(0x55, 0xF0);
  ArduinoNunchuk::_sendByte(0x00, 0xFB);

  ArduinoNunchuk::update();
}

void ArduinoNunchuk::update()
{
  int count = 0;
  int values[6];

  Wire.requestFrom(ADDRESS, 6);
  
  while(Wire.available())
  {
    values[count] = Wire.read();
    count++;
  }

  ArduinoNunchuk::analogX = values[0];
  ArduinoNunchuk::analogY = values[1];
  ArduinoNunchuk::accelX = (values[2] << 2) | ((values[5] >> 2) & 3);
  ArduinoNunchuk::accelY = (values[3] << 2) | ((values[5] >> 4) & 3);
  ArduinoNunchuk::accelZ = (values[4] << 2) | ((values[5] >> 6) & 3);
  ArduinoNunchuk::zButton = !((values[5] >> 0) & 1);
  ArduinoNunchuk::cButton = !((values[5] >> 1) & 1);

  ArduinoNunchuk::_sendByte(0x00, 0x00);
}

void ArduinoNunchuk::_sendByte(byte data, byte location)
{
  Wire.beginTransmission(ADDRESS);
  
  Wire.write(location);
  Wire.write(data);

  Wire.endTransmission();

  delay(10);
}

You haven't posted the wiring of your project, so I'm just guessing. Probably the nunchuck is not ready to receive the command bytes when you just plug the Arduino in. That's why it works when uploading the sketch, then the nunchuck has more time to come up to a working state. Try inserting a delay(10000) statement into your setup routine at start, that may solve this issue.

Pylon is correct. But delay(10000) is too much. Try this:

// Setup.  This runs at startup, and initializes the nunchuck
void setup() {
delay(700);
Serial.print("Setup");
  
//Serial.begin(115200);  // Begin serial communication with baud rate at 115200.  For debugging
Serial.begin(9600);  // Begin serial communication with baud rate at 115200.  For debugging
chuck.begin();               // Initialize nunchuck.  This function is located in the WiiChuck.h library
delay(100);
chuck.update();           // Read nunchuck.  This function is located in the WiiChuck.h library
delay(100);
myservo.attach(9);    // ESC attached to 9 pin of Arduino

delay(1000);
}

It works for my code. The only issue now is that if the wii remote is out of range the speed keeps the same… then when wii remote connects back to the nunchuck the speed goes all the way up.