Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: CPU speed, Wiichuk and Teensy 4.0

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    4

    CPU speed, Wiichuk and Teensy 4.0

    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!!
    Click image for larger version. 

Name:	106103789_268518297900381_7806929311790770692_n.jpg 
Views:	3 
Size:	192.3 KB 
ID:	20748Click image for larger version. 

Name:	cpuspeed.png 
Views:	1 
Size:	59.1 KB 
ID:	20749

  2. #2
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,325
    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.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    Hi thanks for the reply, sorry I should have said, but I had already tried this with no luck

  4. #4
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,325
    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();
       delayMircoseconds(100);
        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);
       delayMircoseconds(100);
    
      Wire.write(data);
       delayMircoseconds(100);
    
      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.

  5. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    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

  6. #6
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,325
    Glad that worked but not sure why still the problem with i2c. Guess i will be buying for testing.

  7. #7
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    Possibly just a problem with the controller, I imagine it couldn't keep up with the teensy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •