I wrote a very simple library to make the ESP32 talk via I2C to Wii controllers like the Wii Nunchuk and the Wii Classic Controller.
There are a few libraries around that do this for the Arduino using
the Wire
library, but
for some reason that doesn't work consistently with the ESP32 and the
Wii controllers. So I wrote the I2C communication using the ESP-IDF
API,
and it works really well, except that for some reason I wasn't able to
make it work at 400KHz (which is supposedly what the Wii controllers
accept), only at 100KHz. That's a little disappointing, but good
enough for my purposes, which is using the controllers in the ESP32
port of Loser Corps.
While playing with it, I wrote a little test program to display the
state of the connected controller on a small OLED screen (SSD1306),
which is controlled using the Adafruit SSD1306
library also via I2C,
but using the Wire
library:
When using the Wii Classic Controller, the screen shows two triangles that point on the direction where you move the sticks, growing in size as you move the stick farther along. Pressing each button lights a corresponding character on the screen, and pulling the analog triggers increases the size of two bars that appear on the left side.
When using the Wii Nunchuk, the screen shows a single triangle with the status of the nunchuk stick and three bars to the left that show the status of the X, Y and Z accelerometer readings. Pressing C or Z displays the corresponding letter on the screen.
I wrote this small test program mostly for fun, but it tests something
important: that my library, which uses I2C via ESP-IDF, can coexist
with Wire
library. When using them together, you just have to be
careful not to use the same ESP32 I2C port with the two libraries at
the same time. In this program, my library uses I2C port 0 and the
Wire
library uses I2C port 1 (by using the Wire1
object).
The source code for the library is here: https://github.com/moefh/esp32-wii-nunchuk