Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Wii Nunchuck I2C to Analog teensy 2.0 Plausibility

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    8

    Wii Nunchuck I2C to Analog teensy 2.0 Plausibility

    Hello all,

    I have an application where I want to use a wii nunchuck to control a 2-axis robot. Everything on the robot side I have completely under control and just need to send it digital and analog inputs which I will derive from the I2C nunchuck data.

    So basically the C and Z buttons will map to 2 digital inputs on the robot, and the joystick X/Y positions will map to analog inputs on the robot, and I would like to use a Teensy 2.0 board to do so.

    I've read up on quite a bit of reading the I2C data from a nunchuck and know how to code it on a teensy, as well as using the analog outputs (PWM/Filtering) on the teensy. I was just curious if anyone has done something similar or if anyone can confirm/deny that this concept should be possible.

    One thing I am unsure of is on the sheet I got from pjrc has 2 sides with a pinout for using C and a different pinout for using Arduino. Using arduino software I see the PWM pins but not the SCL and SDA pins needed for I2C. The C pinout has SCL and SDA pins but no PWM that I can see. Is it not possible to use both I2C and PWM outputs simultaneously?


    Any advice/info would be appreciated,
    Thanks

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,220
    Several people have used Wii Nunchucks with Teensy.

    Yes, I2C and PWM work simultaneously.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks for confirming, I'm going to start prototyping later this week and update if anyone is interested.

    I'm still somewhat confused on the 2 different sets of pinouts for Arduino/C. For example, if I'm going to be using I2C which utilizes D0/D1 pins, this means I am forced to write in C correct? And if so, I don't see where PWM is available in the C pinout diagram. Sorry if this is a stupid question but I guess I am looking for a more detailed description of some of the pins in the C layout and how to configure them. I know I'll be using the Wire library but still looking for info on PWM, all I could find was this

    Click image for larger version. 

Name:	pinout2a.png 
Views:	958 
Size:	208.2 KB 
ID:	1098

    Click image for larger version. 

Name:	pinout2b.png 
Views:	1413 
Size:	187.5 KB 
ID:	1099
    Last edited by z0nghits; 11-10-2013 at 04:06 AM.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,220
    The Wire library works great on Teensy 2.0.

    Arduino's analogWrite() function works with all the pins labeled "PWM" on the Arduino side of the card. This page as specific documentation on PWM. All the supported pins are listed.

    http://www.pjrc.com/teensy/td_pulse.html

    It's good to plan in advance, but really, this stuff does work quite well. Just use it.

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks Paul, my second teensy 2 with pins is on it's way now so I can actually get this thing on a breadboard soon. In the mean time I've tried to gather as much info as possible to accomplish my goal for this prototype and have my code ready to go.

    Like I mentioned I will be reading nunchuck data over I2C then sending out that modified data as digital outs and analog outs (pwm) to a robotic system. The nunchucks natively operate on 3.3v and I've seen a good amount of discussion about how running them on 5v may shorten their lifespan or give bogus/high data from the device. No one has actually proven the impact of running nunchucks on 5v that I can tell but I'd like to err on the side of caution and run it on 3.3 volts. I know you provide the ability to do this on a teensy 2 board but doing so will bring my entire board voltage down form 5v to 3.3v. The drawback for me is that I planned on writing 0v - 5v PWM outputs to the robotic system and I would lose some resolution with the drop in voltage.

    So my plan is to keep the board operating at 5v but use some resistors to drop the voltage powering the nunchuck to 3.3v like this. This would allow me to keep the nunchuck happy but still have 5 volts of resolution to work with for PWM.

    Does this seem like a sane approach to my issue? Do the SDA/SCL lines get effected by this at all? If I had my chip and breadboard in hand I would be trying it out instead of bothering people on the forums but until then I'm just trying to get ahead as much as I can. Thanks

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,220
    Quote Originally Posted by z0nghits View Post
    So my plan is to keep the board operating at 5v but use some resistors to drop the voltage powering the nunchuck to 3.3v like this.
    The proper way is to use a voltage regulator chip.

    The resistor divider only works if you don't draw any current from the center. As soon as you do, more current flows through one resistor, so the voltage changes. If the current is perfectly constant, you can change the resistors to compensate. But if the current ever changes, so does the voltage.

    A voltage regulator chip solves all those problems.

  7. #7
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    A voltage regulator chip would drop my entire board down to 3.3v like outlined here correct? This would then drop my maximum output for PWM to 3.3 instead of 5 like I was hoping to utilize. I guess I can live with it for now and see how the robot on the receiving end handles the lower input range.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,220
    If you solder the chip onto Teensy 2.0, then yes.

    But you can use it externally, so it powers only the nunchuck.

    One tiny gotcha: some voltage regulators require a capacitor. The MCP1825 is one, but the needed capacitor is already on Teensy 2.0. If you use it separately, you'll also have to connect a capacitor to the output and ground.

  9. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Gotcha, thanks Paul I really appreciate it

  10. #10
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    I successfully got what I was looking for after prototyping. I'm able to output the I2C data from the nunchuck via USB-Serial, Digital Outs w/PWM, and as HID mouse buttons/movements. I've decided to go with using Digital Outs and PWM since it requires no extra software on the receiving side in my scenario.

    My next step is to minimize price as much as possible and source a PIC that has the following capabilities:
    -I2C input
    -Atleast 2 Digital Outputs
    -Atleast 2 PWM outputs
    -3.3 to 5.v power

    If anyone has recommendations or links to sites that make narrowing down PICs based off my requirements easier I'd appreciate it.

    *Edit: I found this site which is really helpful but if anyone else has suggestions I'm still open, thanks
    Last edited by z0nghits; 11-14-2013 at 04:16 PM.

  11. #11
    Senior Member
    Join Date
    Jan 2013
    Posts
    964
    Quote Originally Posted by z0nghits View Post
    If anyone has recommendations or links to sites that make narrowing down PICs based off my requirements easier I'd appreciate it.
    You do realize what Forum you are posting this question on ?

  12. #12
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Quote Originally Posted by Headroom View Post
    You do realize what Forum you are posting this question on ?
    I do. A forum for boards made for prototyping of which I've purchased a handful already and plan on purchasing more in the future. My next experiment was to minimize my application and since I haven't personally worked with PICs I figured I'd ask. That okay with you?

  13. #13
    Member
    Join Date
    Nov 2012
    Location
    Olympia, WA
    Posts
    43
    I'm not dissing PICs because that's what I started on, but there's a bit of a learning curve. I am sure you have your reasons. Back in the day it seemed you did get more for your buck in peripherals and power with PICs.

    If they are mostly related to price, the ATtiny85 has 6 I/O pins, including 2 pwms. There is an I2C library. There is a lot of development and forum activity out there right now for maxing out this chip due to the digispark and Adafruit trinket boards--both based on the chip and use the arduino IDE and most of the code you already have.

    Initially I thought they were mildly expensive compared to 8 pin PICs ($2.25 at sparkfun), but they are a buck less in quantity one and 75 cents in q25. That's cheap, and the 4K ATTiny45 is a dime less.

    http://www.digikey.com/product-detai...20SU-ND/735470

    This was my own personal revelation; you probably have a good reason for wanting to change platforms, but I'm throwing this out as a former PIC guy.

  14. #14
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thank you for your honest input drjohn. I'm not abandoning teensy development by any means but rather also exploring PICs because they are something I've always been curious about. The amount of things I was able to accomplish with the teensy in only a couple days was really great and has given me motivation to try a lot of other projects I've put off in the past. Thanks again
    Last edited by z0nghits; 11-14-2013 at 09:14 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •