Wii Nunchuck 2.4Ghz to Brushed Car ESC now working.

Hi

Goal :
Wireless Wii Nunchuck -> send data to Wii Dongle -> dongle connected to Adruino Nano V3 (ive been able to get other sketches working) -> Adruino Nano V3.0 sends control signals to 2 esc's for bi directional motor control.

Briefly, i volunteer at a disabled sailing club which operates thru out the world, my branch is http://www.sailabilitygc.org - Sailability Gold Coast.

At our club we have a great many disabled sailors (up to 100+ every week) some of them like to take control of the steering or sail control or both.

For this purpose we have winches that operate the control ropes. (sheets for the nautically minded)
Winches are turned on an off with heavy duty micro switches with an Arcade style heavy duty joystick.

And that works ok but as it has to be bolted down and some people cant reach it comfortably.

The wireless Nunchuck is the ideal tool to get around this problem (also opening up the possibility that a quadriplegic sailor might gain some access ability)

(I have a brain injury myself, i have managed to get various sketches to work but need the calibration functions within wiinunchuk.h V0.9 * Author: Tim Teatrodo )

This is the code i have adapted/butchered to purpose.

I can get it to compile and upload to the adruino nano V3 but as yet no movement and the serial monitor is blank.

If you have time would you mind casting your eyes over it and adding any ; or = or - i have missed ?

/*
 Written by: Mujahed Altahle
 Butchered by : Tony Matthews aka gcebiker
 This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ 
 or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 
 */
/* A Project for Remote Controlling with wireless wii Nunchuck generic brand. 
 Nuncuck is attached to Gnd, Pwr, scd, scl.
 Two ESC's are attached : one to pin 3, one to pin 5 to provide bidirectional dc motor control
 
 The Rx rules is to output the received parameters to port 3 and 6 where the Servo and the ESC are are attached
 a condition is required to prevent the controller from transmitting values that is not useful (like 1480-1530 for ESC and 88-92 for Servo) to save more power as much as we can
 */

#include <Wire.h>
#include <Servo.h> 
#include <wiinunchuk.h>


Servo escone; // Electronic Speed Controller One declaration 
Servo esctwo; // Electronic Speed Controller Two declaration

int pinEscone = 3;
int pinEsctwo = 5;
//
// Setup
//

void setup(void)
{
  nunchuk_init();
  delay(50);
  nunchuk_calibrate_joy();

// i need to be able to program in here a 'dead' spot. to allow for any palsy tremmors the disabled sailors might have.

  delay(3000); //wait until the esc starts in case of Arduino got power first
  escone.attach(3);  // attaches the servo on pin 3 to the servo object 
  esctwo.attach(5);  // attaches the ESC on pin 6 to the ese object  
  //servo.write(90);

  // Print preamble


  Serial.begin(57600);
  // printf_begin();
  
}


void loop(){

  nunchuk_get_data(); // receives 6 data bytes from controller
  if (nunchuk_zbutton() == 1){

    // attach servos if not done yet
    if (escone.attached() == 0){
      escone.attach(3);
    };
    if (esctwo.attached() == 0){
      esctwo.attach(5);
    };

    delay(5);     

    
    // write data to servos
    escone.write(3);
    esctwo.write(5);

  }
}

Sincerely
Tony Matthews
Gold Coast, Australia.

just tried small changes .
uncomment and set both escs to neutral ?

delay(3000); //wait until the esc starts in case of Arduino got power first
escone.attach(3); // attaches the servo on pin 3 to the servo object
esctwo.attach(5); // attaches the ESC on pin 6 to the ese object
escone.write(90);
esctwo.write(90);

// write data to servos
escone.write(joy_x);
esctwo.write(joy_y);

still no love :frowning:

How do you know the upload is working ?

Try a simple sketch, like blinking the led, and check that works.

And then try a simple sketch, like "hello world", to check your serial monitor functionality.

Your not seeing anything in the serial monitor because your not writing anything to it! And as that code does not tell the servos to move then of course they wont regardless of the value of nunchuk_zbutton(). If you tell a servo to go to the position its allready in it does not move.

    // attach servos if not done yet
    if (escone.attached() == 0){
      escone.attach(3);
    };
    if (esctwo.attached() == 0){
      esctwo.attach(5);
    };

The above is pointless and can be removed it does nothing!.

Mark

Code i am working with now till i can find the right variable to call from wiinunchuk.h

#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>


Servo escone; // Electronic Speed Controller One declaration
Servo esctwo; // Electronic Speed Controller Two declaration

void setup(void)
{
nunchuk_init();
delay(50);
nunchuk_calibrate_joy();

// i need to be able to program in here a 'dead' spot. to allow for any palsy tremmors the disabled sailors might have.
// this would go much later, in the loop()

delay(3000); //wait until the esc starts in case of Arduino got power first
escone.attach(3); // attaches the servo on pin 3 to the servo object
esctwo.attach(5); // attaches the ESC on pin 6 to the ese object
escone.write(90);
esctwo.write(90);


Serial.begin(57600);
}

void loop() {

nunchuk_get_data(); // receives 6 data bytes from controller
Serial.print("X = ");
Serial.println(joy_zerox);
Serial.print("Y = ");
Serial.println(joy_zeroy);
delay(20); // ESCs will only change every 20ms
}

Ive had other sketches working but without calibration for the joystick.

  • i am going super simple..if i can.

A guy is helping out via pm,

This code is working, providing serial output consistent with joystick deflection.

#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>


Servo escone; // Electronic Speed Controller One declaration
Servo esctwo; // Electronic Speed Controller Two declaration

void setup(void)
{
nunchuk_init();
delay(50);
nunchuk_calibrate_joy();

delay(3000); //wait until the esc starts in case of Arduino got power first
escone.attach(3); // attaches the servo on pin 3 to the servo object
esctwo.attach(5); // attaches the ESC on pin 6 to the ese object
escone.write(90);
esctwo.write(90);
delay(3000); // let the ESCs sync


Serial.begin(57600);
}

void loop() {

nunchuk_get_data(); // receives 6 data bytes from controller
Serial.print("X = ");
Serial.println(nunchuk_cjoy_x());
Serial.print("Y = ");
Serial.println(nunchuk_cjoy_y());
delay(20); // ESCs will only change every 20ms
}

All seems to be working.

Found the esc needed writeMicroseconds() to find neutral.
Now just trying to get the loss of signal code sorted out.

As this will be used for remote winches on a disabled sailing boat i need the winches to stop when LOS occurs and automatically start back to thumb stick value when signal is reacquired.

Range inside my house thru three walls was 17feet approx, being that the sailors will be quite near the reciever i dont see LOS ever actually occurring whilst the transmitter nunchuck is in the boat...this is more to make provision for if a volunteer puts the reciever on the dock some where and it gets knocked accidentally into the water.

Hey it happens, we've lost a few wheelchairs, radios , volunteers ..plastic chairs , over the edge of the pontoon one time or another.

Code so far.

#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>

// #define TREMOR_LIMIT 64

Servo escthree; // Electronic Speed Controller One declaration
Servo escfive; // Electronic Speed Controller Two declaration
int los;


void setup(void)
{
  nunchuk_init();
  delay(50);
  nunchuk_calibrate_joy();

  delay(3000); //wait until the esc starts in case of Arduino got power first
  escthree.attach(3, 700, 2000); // attaches the esc to digital pins and 
  escfive.attach(5, 700, 2000); // sets max values and by accident the neutral area
  
  escthree.writeMicroseconds(1650); //neutral for my esc's
  escfive.writeMicroseconds(1650); //not working so i commented it out
  delay(3000); // let the ESCs sync


  Serial.begin(57600);
}

void loop() {

  nunchuk_get_data(); // receives 6 data bytes from controller
  int cnt;
  int losVal=1650; //loss of signal neutral value for esc i am using
  // insufficient data , cease movement.
  if (cnt > 5); 
        {
         losVal = nunchuk_cjoy_x();
         losVal = nunchuk_cjoy_y();
        }
   // end loss of data function
   
  Serial.print("X = ");
  Serial.println(nunchuk_cjoy_x());
  Serial.print("Y = ");
  Serial.println(nunchuk_cjoy_y());

  {
    escthree.write(nunchuk_cjoy_x());
  }

  {
    escfive.write(nunchuk_cjoy_y());
  }

  delay(20); // ESCs will only change every 20ms
}

Below is code that is now working with the Wii Nunchuck 2.4ghz version.

For use in Disabled sailing vessels for spinal injury sailors with little or no use of their hands.

As it plugs into any esc , could be used for other applications.

// Notes
// This sketch was tweaked to operate BRUSHED X-45 Hobby King ESC from a car.
// To operate winch motors on a disabled sailing dinghy.

// == The different limit values for the Nunchuck are deliberate. 
// compensating for the ESC's 50% reduction in power when in 'reverse'
// Values from the wii nunchuck were also a little erratic in reverse,
// The if , if else , statements also helped with this.

// As this particular ESC reads neutral immediately upon start up
// and the Adruino is powered from the esc, the mapping was the only way to get neutral reliably.
// This Sketch was written for Sailability Gold Coast by Tony Matthews with
// Help from 'AustinDavid' - endless sphere forums.


#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>



Servo escnine; // Electronic Speed Controller One declaration
Servo escfive; // Electronic Speed Controller Two declaration
int neu = 128; // default zero value for X, Y axis


void setup(void)
{
  nunchuk_init();
  delay(50);
  nunchuk_calibrate_joy();

  delay(20); //wait until the esc starts in case of Arduino got power first
  escnine.attach(9, 300, 2000); // attaches the esc to digital pins and 
  escfive.attach(5, 300, 2000); // sets max values and the neutral area
 
 delay (1000); //  arming sequence - let esc arm 
  escnine.write(neu); // set neutral val
  delay(20);

  Serial.begin(57600);
  }

  void loop() {

  nunchuk_get_data(); // receives 6 data bytes from controller

  Serial.print("X = ");
  Serial.print(nunchuk_cjoy_x());
  Serial.print("   Y = ");
  Serial.println(nunchuk_cjoy_y());



  // Stabilize Wii output and 
  // set Max values for Wii X to counter the esc 50% reduction in reverse
  if (nunchuk_cjoy_x() <= 75) 
    escnine.write(75);

  else if (nunchuk_cjoy_x() >= 155)
    escnine.write(155);

  else {
    escnine.write(nunchuk_cjoy_x()); 
  }

  // Stabilize Wii output and 
  // set Max values for Wii Y to counter the esc 50% reduction in reverse
  if (nunchuk_cjoy_y() <= 75) 
    escfive.write(75);

  else if (nunchuk_cjoy_y() >= 155)
    escfive.write(155);

  else {
    escfive.write(nunchuk_cjoy_y()); 
  }

  delay(20); // ESCs will only change every 20ms
}

Hi Dave,

The arming code is the bit you posted to me plus the last two lines below.

delay(20); //wait until the esc starts in case of Arduino got power first
escnine.attach(9, 300, 2000); // attaches the esc to digital pins and
escfive.attach(5, 300, 2000); // sets max values and the neutral area

delay (1000); // Arming sequence - let esc arm
escnine.write(neu); // set neutral val (This should of read - send neutral value...)
delay(20);

Sorry , i am new to writing code for the arduino and i am still not quite sure of where to put the notes on what each line does.

Its a self centering esc, so i just resend the 'neutral' for my in put device, being the Wii Nunchuck.

With out that line of code it still arms, but only after you give it some input from your control device :slight_smile:

Cheers
Tony

For more info and build pictures of my RC controller please see my build thread over on the Sailability Gold Coast Website http://sailabilitygc.org/wireless-control-for-access-dinghies-and-bigger-boats/

...the page is still being written so its a bit messy at the moment but I've uploaded a lot of pictures to go with the code here, I dont have code posted on that page yet.

Tony

In on boat testing today,

The X Car Brushed ESC, with the settings in my last code to balance the forward/reverse power.
Only served to provide insufficient power to drive the winch.

Removing the limiting code only increased the erratic esc behaviour when in reverse.

I took out the X Car ESC from Hobby King and put in a Losi LOSB9522 Brushed ESC. worked much better, the neutral position was different but other than that it worked very well.

Changes made to the Wii Nunchukc 2.4ghz wireless model to LOSB9522 Brushed electronic speed controller are listed below.

// Wii Nunchuck 2.4ghz wireless to Losi LOSB9522 Brushed ESC
// The values below work for my Losi Strike Brushed ESC

#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>



Servo escnine; // Electronic Speed Controller One declaration
Servo escfive; // Electronic Speed Controller Two declaration
int neu = 128; // default zero value for X, Y axis


void setup(void)
{
  nunchuk_init();
  delay(50);
  nunchuk_calibrate_joy();

  delay(20); //wait until the esc starts in case of Arduino got power first
  escnine.attach(9, 700, 2000); // attaches the esc to digital pins and 
  escfive.attach(5, 700, 2000); // sets max values and the neutral area
  
  
  escnine.write(neu); // Write neutral value.
  delay(20);

  Serial.begin(57600);
  }

  void loop() {

  nunchuk_get_data(); // receives 6 data bytes from controller

  Serial.print("X = ");
  Serial.print(nunchuk_cjoy_x());
  Serial.print("   Y = ");
  Serial.println(nunchuk_cjoy_y());



  // Stabilize Wii output and 
  // set Max values for Wii X to counter the esc 50% reduction in reverse
  if (nunchuk_cjoy_x() <= 75) 
    escnine.write(7);

  else if (nunchuk_cjoy_x() >= 150)
    escnine.write(150);

  else {
    escnine.write(nunchuk_cjoy_x()); 
  }

  // Stabilize Wii output and 
  // set Max values for Wii Y to counter the esc 50% reduction in reverse
  if (nunchuk_cjoy_y() <= 75) 
    escfive.write(7);

  else if (nunchuk_cjoy_y() >= 150)
    escfive.write(150);

  else {
    escfive.write(nunchuk_cjoy_y()); 
  }

  delay(20); // ESCs will only change every 20ms
}