CPU speed, Wiichuk and Teensy 4.0

Status
Not open for further replies.

Redanac

New member
Hey I'm very new to teensy with little indepth knowledge on how they work. I have been trying to connect a Wii nunchuk to my teensy 4.0 and intend to use it to control a strip of Neopixels. To read the wiichuk inputs I am using this library https://github.com/GabrielBianconi/arduino-nunchuk and as a test I am printing the outputs to the serial (the example script in the link). Initially I had no luck and the inputs to the controller were not being read (random numbers were being printed for inputs). I then changed the CPU speed from 600 MHz to 24 MHz which is closer to the CPU speed of the Arduino UNO (18MHz I think) which is the board I've seen most examples of the wiichuk being connected and this worked fine. My problem is that the Neopixels that I am using don't work at 24MHz but work at 600 MHz and I've read somewhere that messing with the timing of led strips is notoriously annoying and difficult. My question is then is there any way of getting the nunchuk controller to work at 600 MHz? I've attached a photo of my circuit set up (I've read that you need pull up resistors to make readings more reliable so I've added them in, but it works without them too at 24MHz) . I would be grateful for any help. Thank you!!
106103789_268518297900381_7806929311790770692_n.jpgcpuspeed.png
 
Just a glance at the library it seems all its doing is sending bytes through I2C using Wire which is pins 18/19.

Would suggest that you leave the CPU clock at 600Mhz and edit the .cpp file to put a Wire.setClock(100000); after Wire.begin and see if that helps.
 
Are you using the latest IDE/TD (1.83 and 1.53beta2)? At one point there was alot of work done to prove i2c comm?

One of the things i did to debug I2C as a test was to put some delays after Wire.send etc, something like this:
Code:
/*
 * ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
 *
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following resources:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 *
 */

#include <Arduino.h>
#include <Wire.h>
#include "ArduinoNunchuk.h"

#define ADDRESS 0x52

void ArduinoNunchuk::init()
{
  Wire.begin();

  ArduinoNunchuk::_sendByte(0x55, 0xF0);
  ArduinoNunchuk::_sendByte(0x00, 0xFB);

  ArduinoNunchuk::update();
}

void ArduinoNunchuk::update()
{
  int count = 0;
  int values[6];

  Wire.requestFrom(ADDRESS, 6);

  while(Wire.available())
  {
    values[count] = Wire.read();
[COLOR="#FF0000"][COLOR="#FF0000"]   delayMircoseconds(100);
[/COLOR][/COLOR]    count++;
  }

  ArduinoNunchuk::analogX = values[0];
  ArduinoNunchuk::analogY = values[1];
  ArduinoNunchuk::accelX = (values[2] << 2) | ((values[5] >> 2) & 3);
  ArduinoNunchuk::accelY = (values[3] << 2) | ((values[5] >> 4) & 3);
  ArduinoNunchuk::accelZ = (values[4] << 2) | ((values[5] >> 6) & 3);
  ArduinoNunchuk::zButton = !((values[5] >> 0) & 1);
  ArduinoNunchuk::cButton = !((values[5] >> 1) & 1);

  ArduinoNunchuk::_sendByte(0x00, 0x00);
}

void ArduinoNunchuk::_sendByte(byte data, byte location)
{
  Wire.beginTransmission(ADDRESS);

  Wire.write(location);
[COLOR="#FF0000"][COLOR="#FF0000"]   delayMircoseconds(100);
[/COLOR][/COLOR]
  Wire.write(data);
[COLOR="#FF0000"]   delayMircoseconds(100);
[/COLOR]
  Wire.endTransmission();

  delay(10);
}
Then delete them where the problem is - i dont have one of those controllers so there is no way to test it.
 
That's done the job, seems the
Code:
Wire.write(data)
was the problem although I'm not sure why. Thank you very much for your help :)
 
Glad that worked but not sure why still the problem with i2c. Guess i will be buying for testing.
 
Status
Not open for further replies.
Back
Top