Society of Robots - Robot Forum

General Misc => Robot Videos => Topic started by: frank26080115 on December 15, 2007, 02:47:56 PM

Title: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 15, 2007, 02:47:56 PM
My robot Charlie with a Wii Nunchuck R/C system

[youtube=425,350]rFN0P7389O8[/youtube]

I sound weird on a mic.

EDIT: I posted code and such a few posts after this one

Other videos on my Youtube account
http://youtube.com/frank26080115

More better neater photos on my flickr
http://www.flickr.com/photos/frank26080115/2125780153/
Title: Re: Wii Nunchuck Controlled Robot
Post by: Mega on December 15, 2007, 02:54:34 PM
Very cool!
Where can I find more info on Charlie?
Title: Re: Wii Nunchuck Controlled Robot
Post by: Admin on December 15, 2007, 04:24:40 PM
Nice!!!

post some code!
Title: Re: Wii Nunchuck Controlled Robot
Post by: ed1380 on December 15, 2007, 05:24:53 PM
awesome
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 15, 2007, 05:44:01 PM
The Nunchuck reading code is an improvement upon the code from http://www.windmeadow.com/node/42

This is all done with the Arduino environment

You need one of my custom library (some weird functions i find handy), and you need to modify the existing Wire library with the steps in http://www.windmeadow.com/node/42

my library file is named basic.h, place it in /arduino-0010/hardware/libraries/basic/
i've attached this file to this post

the controller side uses the file inside my "charlie_wii_nunchuck.zip" attached to this post
I found that instructions here http://www.windmeadow.com/node/42 for the connection is not so reliable, I really think you should use a 3.3V regulator, PLUS 10K pull up resistors
Read this http://www.sparkfun.com/commerce/present.php?p=Sensor-Interfacing

The radio transmitter is one of those cheap RF modules Spark Fun sells, except mine only costs $5 each, not $15,
it is connected to the TX pin on the MCU
Don't bother with 4800 baud even though it's the speed the modules are advertised at, use 2400
http://www.robotshop.ca/home/products/robot-parts/communication-control/data-telemetry/on-shine-low-cost-tx-rx.html

the robot has pins defined to the various servos, the pin definitions can be changed in the code (file is servo.pde), the radio receiver is connected to the RX pin, the file is "charlie_advanced_rc.zip"
(I got lazy and used a bunch of switch cases instead of simply calculating out the servo pulse widths, floating point wasn't working right)

OH, and I made a connector to avoid cutting the nunchuck's cables, it's a stick of double sided copper clad board etched with 3 lines to match the inside of the connector, and i made a plastic housing so everything stays nicely together, it's great! The screws I used even lets the connector to "click in"

The pinouts of the connector is here:
http://www.hardwarebook.info/Wiimote_Expansion_Port
Title: Re: Wii Nunchuck Controlled Robot
Post by: airman00 on December 15, 2007, 07:24:17 PM
Very cool    ;D
 
i gotta build me one of those...
Title: Re: Wii Nunchuck Controlled Robot
Post by: Mega on December 16, 2007, 02:21:22 AM
Very nice indeed!
If I spotted it correctly, your Charlie bot uses the AVRcam?
Do you have some more info on how you use the cam and how you connected it to the Arduino?
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 16, 2007, 11:40:09 AM
It wasn't hard, but it's a pain in the ass to use.

I'll try and fish up some code, maybe even a library someday. But it's basically send your track command, then wait for a few packets, then end the tracking, and process the packets.

I'm also hoping to make my own image processor, but with a atmega128 instead of the atmega8
But the camera's datasheet is very very difficult to understand.
Title: Re: Wii Nunchuck Controlled Robot
Post by: HDL_CinC_Dragon on December 16, 2007, 12:01:13 PM
that is genius dude. Good freaking job! Seriously, that is cool as hell lol. That little bot has some serious application potential! :D
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 16, 2007, 09:42:31 PM
This is weird, you guys see the wire antenna i used on the breadboarded transmitter? removing the antenna gives me a huge boost in signal quality... I need to make a project boxed version of the transmitter, and now i'm wondering about an antenna, what should I do? use an antenna or stick with what works?
Title: Re: Wii Nunchuck Controlled Robot
Post by: Admin on December 17, 2007, 05:53:35 AM
hmmm odd about the antenna . . .

is the antenna on your robot also vertical? antennas must be parallel for optimal transmission
Title: Re: Wii Nunchuck Controlled Robot
Post by: Ro-Bot-X on December 17, 2007, 11:59:16 AM
Nice job, Frank!
Small request, can you post the code for the AVRcam processing sequence? I am struggling making mine work with a Arduino custom board...
Title: Re: Wii Nunchuck Controlled Robot
Post by: Mega on December 17, 2007, 12:02:54 PM
Quote
Small request, can you post the code for the AVRcam processing sequence?

Same request from me. Thanks in advance!
Title: Re: Wii Nunchuck Controlled Robot
Post by: Admin on December 17, 2007, 12:25:10 PM
Quote
Quote
Small request, can you post the code for the AVRcam processing sequence?

Same request from me. Thanks in advance!
and me . . . I tried to do it yesterday actually with the CMUcam on my ATmega168 and so far no luck. The code is basically the same for both cams . . .
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 17, 2007, 02:53:36 PM
Code: [Select]
// Cam Related Variables
// These needs to be written while reading buffer
byte objNum;
byte objColour[8]; // Refer to sensordef.h
// These are used by the robotic functions
boolean noObj;
byte objXCenter[8];
byte objYCenter[8];
byte objWidth[8];
byte objHeight[8];
byte objSize[8]; // Average between width and height used for ranging purposes
byte objShape[8]; // 0 for null, 1 for square, 2 for tall, 3 for wide
boolean objFound;
byte objAtt; // in view and right shape and colour
boolean objInterestFound;
byte objInterested; // not the right shape, but right colour on the edge of view
byte wantedColour = 1; // What colour you are looking for

boolean waitACK()
{
  boolean incomeValid = true;
  while(Serial.available() < 4);
  if(Serial.read() != 65)
  {
    incomeValid = false;
  }
  if(Serial.read() != 67)
  {
    incomeValid = false;
  }
  if(Serial.read() != 75)
  {
    incomeValid = false;
  }
  if(Serial.read() != 13)
  {
    incomeValid = false;
  }
  return incomeValid;
}

void getObj()
{
  byte objXMin[8];
  byte objXMax[8];
  byte objYMin[8];
  byte objYMax[8];
  byte waittimeout = 0; 
  byte temp;

  Serial.println("ET");

  while(waitAck() == false)
  {
    Serial.println("ET");
  }

  while((Serial.available() == 0) && (waittimeout != 10))
  {
    delay(1);
    waittimeout++;
  }
 
  if(Serial.available() == 0)
  {
    noObj = true;
    objNum = 0;
    Serial.println("DT");
    while(waitAck() == false)
    {
      Serial.flush();
      Serial.println("DT");
    }
  } else {
    temp = Serial.read(); // useless byte
    while(Serial.available() == 0);
    objNum = Serial.read();
    noObj = false;
  }

  waittimeout = 0;

  if(noObj == false)
  {
    for(temp = 0; temp < objNum; temp++)
    {
      while(Serial.available() == 0);
      objColour[temp] = Serial.read();
      while(Serial.available() == 0);
      objXMin[temp] = Serial.read();
      while(Serial.available() == 0);
      objYMin[temp] = Serial.read();
      while(Serial.available() == 0);
      objXMax[temp] = Serial.read();
      while(Serial.available() == 0);
      objYMax[temp] = Serial.read();
    }
  }
 
  Serial.println("DT");
  delay(100); // there might be some junk left over, wait for finish
  // for robots who need constant servo pulses, replace delay with
  // for loops that sends the pulses for a similar amount of time
  // 100 is only an estimate
  Serial.flush(); // clear buffer
 
  objFound = false;
  objInterestFound = false;
 
  if(noObj == false)
  {
    for(temp = 0; temp < objNum + 1; temp++)
    {
      objWidth[temp] = objXMax[temp] - objXMin[temp];
      objHeight[temp] = objYMax[temp] - objYMin[temp];
      objXCenter[temp] = objXMin[temp] + (objWidth[temp] / 2);
      objYCenter[temp] = objYMin[temp] + (objWidth[temp] / 2);
      objShape[temp] = 0;
      if(similarTo(objWidth[temp], objHeight[temp]))
      {
        objShape[temp] = 1;
      }
      if(objShape[temp] != 1)
      {
        objShape[temp] = 2;
        if(objWidth[temp] > objHeight[temp])
          objShape[temp] = 3;
      }
      objSize[temp] = averageWH(objWidth[temp], objHeight[temp]);
      if(objShape[temp] == 1)
      {
        if(objColour[temp] == wantedColour)
        {
          objAtt = temp;
          objFound = true;
        }
      }
      else {
        if(objColour[temp] == wantedColour)
        {
          objInterested = temp;
          objInterestFound = true;
        }
      }
    }
  }
}

I think that should do it, it doesn't configure the camera for you though
I am making various changes to the code, the current one might not work
I think you need these functions in another small library of mine

Code: [Select]
boolean similarTo(byte varAa, byte varBb) // used to compare length and width of objects to find shape
{
  float varA = varAa;
  float varB = varBb;
  boolean isSimilar = 0;
  if((varA < varB + (varA / 3)) && (varA > varB - (varA / 3)))
  {
    isSimilar = 1;
  }
  if((varB < varA + (varB / 3)) && (varB > varA - (varB / 3)))
  {
    isSimilar = 1;
  }
  return isSimilar;
}

boolean similarTo(int varAa, int varBb) // used to compare length and width of objects to find shape
{
  float varA = varAa;
  float varB = varBb;
  byte divider = 10;
  boolean isSimilar = 0;
  if((varA < varB + (varA / divider)) && (varA > varB - (varA / divider)))
  {
    isSimilar = 1;
  }
  if((varB < varA + (varB / divider)) && (varB > varA - (varB / divider)))
  {
    isSimilar = 1;
  }
  return isSimilar;
}

byte averageWH(byte varAa, byte varBb)
{
  float varA = varAa;
  float varB = varBb;
  byte avgSize;
  varA = (varA + varB) / 2;
  avgSize = varA;
  return avgSize;
}

A Processing program I made for the computer is attached to this post, it can only do frame dumps, nothing else
Title: Re: Wii Nunchuck Controlled Robot
Post by: Admin on December 17, 2007, 03:40:53 PM
are the Serial.whatever() commands for Wiring? or perhaps require some other header?
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 17, 2007, 03:55:38 PM
Serial.whatever works in Arduino without doing anything extra
But you have to initialize it with Serial.begin(115200); in initialization process.
Title: Re: Wii Nunchuck Controlled Robot
Post by: reSpawn on December 18, 2007, 09:59:13 AM
Hi Frank! The Radio Module works "out of the box", I mean you don't need to configure anything? It works just like there would be a cable?
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 18, 2007, 10:08:01 AM
it acts as an invisible wire, but only for digital signals (so only binary 0 and 1s, nothing in between), but it can't handle more than 2400 changes per second.

ALSO you must change the input to the transmitter every second or else the receiver starts to output junk, apparently this is not needed if you run the transmitter at 12V, but I didn't try that yet.

To use it for a serial connection, just connect the transmitter to the TX pin on your microcontroller, and the receiver to the RX pin on another microcontroller, and set the baud rate on both microcontrollers to 2400 baud.

The black and white answer is Yes, but with the above limitations you must look out for.
Dirt cheap compared to SparkFun, eh? Costs less than plain wire for that distance.
Title: Re: Wii Nunchuck Controlled Robot
Post by: reSpawn on December 30, 2007, 11:29:31 AM
it acts as an invisible wire, but only for digital signals (so only binary 0 and 1s, nothing in between), but it can't handle more than 2400 changes per second.

ALSO you must change the input to the transmitter every second or else the receiver starts to output junk, apparently this is not needed if you run the transmitter at 12V, but I didn't try that yet.

To use it for a serial connection, just connect the transmitter to the TX pin on your microcontroller, and the receiver to the RX pin on another microcontroller, and set the baud rate on both microcontrollers to 2400 baud.

The black and white answer is Yes, but with the above limitations you must look out for.
Dirt cheap compared to SparkFun, eh? Costs less than plain wire for that distance.
What do you mean by "change the input to the transmitter every second" ?
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on December 30, 2007, 11:33:00 AM
oops i meant change the bit inputted to the transmitter, otherwise, the receiver goes nuts
Title: Re: Wii Nunchuck Controlled Robot
Post by: roschler on January 02, 2008, 02:09:54 PM
Great job Frank!  Nunchaku control and no host PC required!
Title: Re: Wii Nunchuck Controlled Robot
Post by: SmAsH on January 10, 2008, 06:10:24 PM
lol i told my friend and now he hates you for dishonouring the wii  ;D oh well freakin wiked tho
Title: Re: Wii Nunchuck Controlled Robot
Post by: vidam on January 17, 2008, 02:56:01 PM
I just read this post. Awesome!!! If you can only control the robot with WII to go to the fridge and get a beer.

Title: Re: Wii Nunchuck Controlled Robot
Post by: Nyuli on January 20, 2008, 02:11:44 AM
So if you are using the Arduino, you need to include "Wire.h" (i'm assuming that "stdio.h" and "string.h" are standard c libraries). say i wanted to do something similar, i.e: control servos and whatnot remotely using the Wii nunchuck and some cheap RF receivers/transmiters, but instead i have a homemade microcontroller similar to the $50 robot one (which will use the Atmega168). where would i find the required libraries, like "Wire.h" and any others that it may also include so that i can use the functions in your code? I could always just buy an Arduino, but im going to school for all this neato robotics jazz (Mechanical Engineering/Mechatronics) so i'd rather do EVERYTHING the hard way and make my own stuff. You learn more that way anyhow. thanks for any help.
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on January 20, 2008, 04:02:14 PM
Wiring.h should be compatible with both ATMEGA8 and ATMEGA168
Title: Re: Wii Nunchuck Controlled Robot
Post by: Nyuli on January 20, 2008, 07:53:54 PM
No, basically what I'm saying is that i wanna do this without the Arduino. Where can I get "Wire.h"? doesnt that header file come with Arduino?
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on January 20, 2008, 10:00:49 PM
the "wire" library will work with AVR-GCC and with any AVR chips that has I2C
Title: Re: Wii Nunchuck Controlled Robot
Post by: Nyuli on January 21, 2008, 11:29:52 AM
Cool man. So any tips you can give me for the cheapo RF Receiver/Transmitter set, like hoe to make them talk to each other? got any code snippets for that part?
Title: Re: Wii Nunchuck Controlled Robot
Post by: E.Man.Lava on January 21, 2008, 05:38:31 PM
dude that video is awesome.  i didnt know you could do that with the nunchuck!  ;D
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on January 21, 2008, 07:27:14 PM
Cool man. So any tips you can give me for the cheapo RF Receiver/Transmitter set, like hoe to make them talk to each other? got any code snippets for that part?

they behave like a wire, but only for digital signals, all you need to know is how to use USART on a microcontroller
Title: Re: Wii Nunchuck Controlled Robot
Post by: korforfan on March 07, 2009, 06:55:10 AM
nice one! good work  :D
Title: Re: Wii Nunchuck Controlled Robot
Post by: andd64 on April 16, 2009, 03:20:48 PM
Hi Frank,

Question - can you please explain how you made the connector for the nunchuck? Im looking to use my nunchuck but i really don't want to cut the cable. 

Thanks
Title: Re: Wii Nunchuck Controlled Robot
Post by: frank26080115 on April 17, 2009, 05:57:47 PM
I suggest you buy http://www.dealextreme.com/details.dx/sku.4115 (http://www.dealextreme.com/details.dx/sku.4115) , there's no point in making a connector my original way now
Title: Re: Wii Nunchuck Controlled Robot
Post by: AdvsNoob on May 08, 2009, 10:11:58 PM
how you get the wireless stuff going and how much?
Title: Re: Wii Nunchuck Controlled Robot
Post by: BANE on May 10, 2009, 06:19:37 AM
Has any one done something similar but with the axon?   
Title: Re: Wii Nunchuck Controlled Robot
Post by: dellagd on May 10, 2009, 09:10:37 AM
if the same pins are connected, will this code work for a $50 board?

I mean, they both use c, or i there something special about the arduino
Title: Re: Wii Nunchuck Controlled Robot
Post by: BANE on May 10, 2009, 11:48:16 AM
I was looking on youtube for wii hacks and the majority used the ardunio.  Is there anything special about the ardunio? Is it just serial communication with the wii receiver?
Title: Re: Wii Nunchuck Controlled Robot
Post by: Razor Concepts on May 10, 2009, 11:50:36 AM
Arduino has easy ways to communicate with I2C, which seems like why it is the most common board to be used with the wii stuff.
Title: Re: Wii Nunchuck Controlled Robot
Post by: SmAsH on May 10, 2009, 02:14:42 PM
the arduino is just a mega168 with extras like usb and i2c... same *could* be achieved with the $50 board.
Title: Re: Wii Nunchuck Controlled Robot
Post by: Sankeerth on May 23, 2009, 10:57:15 PM
Can you guide me with the construction of charlie? i mean does it use Arduino as well? how did you interface so many servos there? I'm really sorry for my ignorance but i'm new to Arduino..... please help
Title: Re: Wii Nunchuck Controlled Robot
Post by: Sankeerth on May 23, 2009, 11:00:18 PM
And also that i never used RF modules before, can you guide me with the connections? rx and tx is fine, but the other connections....sorry again for my ignorance  :(
Title: Re: Wii Nunchuck Controlled Robot
Post by: awally88 on May 31, 2009, 02:27:02 AM
Quote
I suggest you buy http://www.dealextreme.com/details.dx/sku.4115 (http://www.dealextreme.com/details.dx/sku.4115) , there's no point in making a connector my original way now

I <3 Deal Extreme, free shipping worldwide on cheap Hong Kong electronics!

I just bought a couple of these wii nunchucks, if you do cut them the wires inside aren't the same colours as those of the original parts. If you pull apart the connector you can see what colour on goes to which pin on the connector and check it against the original part. Its only a five minute job to do but don't get freaked out if you open it and the colours are different!
Title: Re: Wii Nunchuck Controlled Robot
Post by: dellagd on June 01, 2009, 03:39:20 PM
looks like you need to make a tutorial
Title: Re: Wii Nunchuck Controlled Robot
Post by: xCyclone on June 01, 2009, 04:20:35 PM
lol i told my friend and now he hates you for dishonouring the wii  ;D oh well freakin wiked tho
Thats not dishonoring the Wii. Actually, Nintendo may want to copy his idea likewith the little RC Mario Cart things. BTW Great Idea!
Title: Re: Wii Nunchuck Controlled Robot
Post by: calfred on November 03, 2009, 03:22:43 AM
very good job.
although it'll be even more interesting if BLUETOOTH was used, instead of rc.
Title: Re: Wii Nunchuck Controlled Robot
Post by: tagulandito on June 21, 2013, 11:13:54 AM
So i have a few questions on the arduino pwm. i want to control to ESC for my motors and they use a pwm input. how will this hook up to the arduino and  still use the wii? i know this is a simple question but i havent see it explained, I.E. which pin to use and the code for it.
Title: Re: Wii Nunchuck Controlled Robot
Post by: jiudiany3 on September 25, 2018, 04:10:28 AM
oops i meant change the bit inputted to the transmitter, otherwise, the receiver goes nuts







__________________________________________
Robots stepper motor:oyostepper.com (https://www.oyostepper.com/)