Trying to connect the controller but not getting any response.
- I'm Using an Arduino Uno.
- The momentary switch is connected to digital pin 2 and ground per the schematic found on this page: https://www.arduino.cc/en/Tutorial/Button
- The wiring of the Wii controller cable to the Arduino is as follows: Ground to ground, 3.3v to 3.3v, SCL to SCL pin A5, SDL to SDL pin A4. Have tried the 3.3v on the controller to AREF as well.
- Have tried using the SDA & SCL pins on the other side of the board, too.
- All wires in the the controller cable have been verified with continuity tester as the correct pins.
- I have verified numerous times there are no loose connections.
- The Arduino is being powered by USB from my laptop.
Only result so far is the LED is blinking and the serial terminal outputs 0 or outputs 1 when the momentary switch is pressed.
Not sure if this is normal or pertinent but on the serial terminal output there are always at least two 1's in a row no matter how fast the momentary is pressed.
The sketch code is as follows (omitted wiimote.h and wm_crypto.h etc for brevity. Available here if necessary: arduino-wiimote/classic at master · denizkoekden/arduino-wiimote · GitHub).
The code already existed, just added serial/LED output for making sure the switch was working properly and also excessive comments (learning still).
/*
* Sample sketch which makes the Arduino to impersonate a Classic Controller.
* Copyright (c) 2011 Peter Brinkmann (peter.brinkmann@gmail.com)
*
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*
*/
/*
* Use a momentary switch connected to the digital pin 2 and GND.
* It will simulate the D-Pad RIGHT button press.
*
* Here's how to connect the Arduino to the Wiimote:
* Arduino Wiimote
* GND GND (white cable)
* AREF 3.3V (red cable)
* A4 SDA (green cable)
* A5 SCL (yellow cable)
*/
#include "Wire.h"
#include "wiimote.h"
// Current controller data.
// Classic Controller Buttons. 0 = initial state
int bdl = 0; // D-Pad Left state
int bdr = 0; // D-Pad Right state
int bdu = 0; // D-Pad Up state
int bdd = 0; // D-Pad Down state
int ba = 0; // A button state
int bb = 0; // B button state
int bx = 0; // X button state
int by = 0; // Y button state
int bl = 0; // L button state
int br = 0; // R button state
int bm = 0; // MINUS button state
int bp = 0; // PLUS button state
int bhome = 0; // HOME button state
int bzl = 0; // ZL button state
int bzr = 0; // ZR button state
// Analog buttons
// They are initialized with center values from the calibration buffer.
byte lx = calbuf[2]>>2;
byte ly = calbuf[5]>>2;
byte rx = calbuf[8]>>3;
byte ry = calbuf[11]>>3;
int pinRight = 2; // set digital pin 2 as input, assign variable "pinRight"
int ledPin = 13; // LED on pin 13
int val = 0; // variable for counting the state of the button
// Wiimote button data stream
byte *stream_callback(byte *buffer) {
wiimote_write_buffer(buffer, bdl, bdr, bdu, bdd, ba, bb, bx, by, bl, br, bm, bp, bhome, lx, ly, rx, ry, bzl, bzr);
return buffer;
}
// Setup the controller and serial output
void setup() {
Serial.begin(9600); // begin serial communication - used to see if switch is working
pinMode(ledPin, OUTPUT); // set LED pin (13) for output - used for determining if momentary switch is working.
pinMode(pinRight, INPUT); // initialize digital pin 2 as an INPUT - should I use pinMode(pinRight, INPUT_PULLUP); instead?
digitalWrite(pinRight, HIGH); // configured as an INPUT, so digitalWrite(pinRight, HIGH) enables the internal pullup on the input pin.
// Prepare wiimote communications
wiimote_stream = stream_callback;
wiimote_init();
}
// Main program
void loop() {
/*
* If momentary switch is pressed, pinRight will be LOW.
* This value is then inverted and given to variable "bdr", that represents
* D-Pad RIGHT button.
*/
val = digitalRead(pinRight); // if button was pressed or not then...
digitalWrite(ledPin, val); // turn on LED. If released then turn off.
Serial.print(bdr); // Print "1" to serial if button is pressed or "0" otherwise.
Serial.println(); // Create new line in serial terminal so text doesn't scroll laterally
bdr = digitalRead(pinRight);
delay(50);
}
I have been working on this for a week nonstop including hours of Googling and reading tens of other examples and cannot figure it out, at my wits end. Would love if someone could point out what is going wrong here and I'll gladly donate 1 or 20 or 50 beers. ![]()
Thank you for your time