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:

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:

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 

More than one thousands words: