Using the Nintendo Wii Nunchuk Joystick in the STM32F4Discovery running NuttX

I created a simple NuttX sensor driver (I will implement a joystick driver and send to NuttX mainline) to use Nunchuk Joystick with STM32F4Discovery running NuttX.

We have two options to see the NuttX serial console on STM32F4Discovery board: 1) Connect a USB/Serial dongle to UART pins or 2) Use the “usbnsh” configuration to get the serial console in the MicroUSB port (CN5).

I opted to use the UART pins because I have many USB/Serial dongle here.

The NuttX serial console for STM32F4Discovery board is on UART2:

PIN   |   FUNCTION
------------------
PA2   |    TX
PA3   |    RX

Then all I need to do is to connect the dongle GND signal to board GND, RX signal to PA2 pin (TX) and TX signal to PA3 pin (RX).

After getting the NuttX running in the board I connected a Nunchuk receptacle connector (I cut it from a Wii Mote damaged board) to STM32F4Discovery.

I’m using I2C 1 in the pins PB7 and PB8:

/* I2C config to use with Nunchuk PB7 (SDA) and PB8 (SCL) */

#define GPIO_I2C1_SCL  GPIO_I2C1_SCL_2
#define GPIO_I2C1_SDA  GPIO_I2C1_SDA_1

This is the Nunchuk to STM32F4Discovery wiring connection:

---------------------------------
  Nunchuk  |   STM32F4Discovery
-----------|---------------------
     1     |       PB7
     2     |       NC
     3     |       3V
     4     |       PB8
     5     |       NC
     6     |       GND

This is the Nunchuk pinout:
nunchuk_pinout

The Nunchuk can be detected at I2C address 0x52. And to initialize it you need to write “0x40 0x00” (write 0x00 in the register 0x40).

This is the command used to debug the reading of data:

nsh> dd if=/dev/nunchuk0 of=/dev/null bs=6 count=1 
 X: 114 | Y: 126 | Buttons: 3 
nsh> 

More than one thousands words:
nunchuk_connection

3 thoughts on “Using the Nintendo Wii Nunchuk Joystick in the STM32F4Discovery running NuttX

  1. Hi, I’ve got the F4discovery working with USB and trying to use UART2 as the console. I’ve done the wiring, and opened a terminal to UART2 (and its worked on other connections) but what do I have to do in Nuttx to connect the console to UART2. Many thanks

  2. I suppose your issue happens because of “CONFIG_NO_SERIAL_CONSOLE=y”, this is default behavior when using USB console shell. []’s, Alan

  3. Yes it seems to be some configuration and trying to dig into it and understand Nuttx – so was just a shot in the dark when I saw you using UART2 that you might have a pointer 🙂
    The CONFIG_NO_SERIAL_CONSOLE seems to be old as it only appears in one place (nuttix 7.12+) nuttx\arch\arm\src\sam34\sam_serial.c

Leave a comment