Pages: [1]   Go Down
Author Topic: Hello? Who's out there? I2C address unknown, how to obtain it?  (Read 3904 times)
0 Members and 1 Guest are viewing this topic.
Canton, Connecticut, United States, Planet Earth, SOL Galaxy, 3rd star on the left.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
To Infinity, And BEYOND!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just picked-up a simple joystick pad which is supposed to plug onto the Nintendo Wii remote, in place of the nunchuck.. It had a joystick, which appears to only have buttons (on/off only, no analog) and 6 buttons.   using the nunchuck info, the values that come back are all 255, but none change when I press any of the buttons. (this is polling for JoyX, JoyY, AccelX, AccelY, AccelZ, Button C & Button Z, all 7 values remain 255)

The thing I'm wondering, is the controller using the same I2C address as the nunchuck? or some other device address, and is there a way to send a 'Who's Out There?" request from the arduino?  I can't seem to find an answer for this, and several references to needing an occilloscope, but no reference on how to connect it.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is an arduino sketch that will scan a I2C buss for all possible I2C addresses 1-127 and report on the serial monitor those addresses that had responses.


Code:
/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr,
                void(*callback)(byte address, byte result) )
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 1;
byte end_address = 127;

// standard Arduino setup()
void setup()
{
    delay(2000);
    Wire.begin();
    Serial.begin(38400);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,HEX);
    Serial.print(" to ");
    Serial.print(end_address,HEX);
    Serial.println("...Hex");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}


Lefty
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is, though, if you know the address, are you going to know the protocol used to communicate with it??  Usually the communication protocol and address are documented together.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It'll be the nunchuk protocol, and the nunchuk address. What else could it be?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't seem to find an answer for this, and several references to needing an occilloscope, but no reference on how to connect it.

An oscilloscope won't help, unless you are very very patient. A logical analyser might.
Logged

Canton, Connecticut, United States, Planet Earth, SOL Galaxy, 3rd star on the left.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
To Infinity, And BEYOND!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Retrolefty, Thanks!  I'll give the sketch a try.

RE:Nick G:, using the demo sketch someone made for the nunchuck, and expanding it to read more than just the accelerometer, (also get the joystick X & Y, as well as buttons C & Z), as I mentioned in the original post, it responds back with all 7 values = 255.. (and none chance with any of the buttons pressed.)

This is a link to the device,  http://www.airaccent.com/arcade-fighter-joystick-controller-for-nintendo-wii-white-p-35437.html
Although, I bought mine from a local Ocean State Job-Lot ("Inventory close-out" store for those unfamiliar with the place.)

I'm not using the turbo or macro functions (yet, once I am sure I can talk to it, maybe.....)  but the arduino (either a UNO or a Duemilinova, programmer 0.23, as it seems even more than just Ethernet or charlieplexing libraries are changed under 1.0  smiley-zipper) reports back 255, 255, 255, 255, 255, 255, 255.....

wanting to use this in a remote control to another arduino, on a robot..

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh well, run the I2C scanner suggested above. At least that confirms the address, and confirms you have it wired up right.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it responds back with all 7 values = 255.. (and none chance with any of the buttons pressed.)

That's a typical default value when something is not even responding due to the pull-up resistors used on a I2C bus. I have a DS1307 I2C real time clock that works fine, and if I start the sketch but don't have the RTC attached to the arduino the sketch does not stall or hang-up it just returns 0xff for all transactions.

Lefty


Logged

Germany
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
just sun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey comunity,

i found this by searching for an I2C / TWI  Scanner.
in the sketch posted here is a smal error with the Arduino IDE 1.0.3 (others not tested.)

Corrected Sketch:
Code:
/**
 * TWI_I2C_Scanner.ino
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 * http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/comment-page-1/
 * http://arduino.cc/forum/index.php/topic,95067.msg714094.html#msg714094
 * https://getsatisfaction.com/thingm/topics/cant_get_blinkm_communicator_to_compile_and_upload
 *
 */

#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr,
                void(*callback)(byte address, byte result) )
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, 0);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 1;
byte end_address = 127;

// standard Arduino setup()
void setup()
{
    delay(2000);
    Wire.begin();
    Serial.begin(115200);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,HEX);
    Serial.print(" to ");
    Serial.print(end_address,HEX);
    Serial.println("...Hex");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

the correction is in line 27:
twi_writeTo needs one additional parameter: 0 for a normal stop command.
i found this info here: https://getsatisfaction.com/thingm/topics/cant_get_blinkm_communicator_to_compile_and_upload

Have fun with I2C / TWI
sunny greetings
stefan
Logged

Canton, Connecticut, United States, Planet Earth, SOL Galaxy, 3rd star on the left.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
To Infinity, And BEYOND!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, after 3/4 of a year since this thread was active, I pulled the controller out, and hooked it up, changing slightly, running +3.3V & GND externally. (Using the THINGS.Com nunchuck plug, external from the Arduino.)  and tried the original code someone posted here..  confirmed, it's the same address as the actual nunchuck controller (52), but when I tried various ways of talking to it to send data, nothing came back...    just sat there..  So, apparently, it's something the master controller of the Wii sends, that it understands..  Also, internally, this controller is nothing but switches under the joystick, 8 external switches to the right, but no ideas how the turbo and macro control keys work..  I'll check that new URL someone just posted..  just downloaded the PDF.. So, hopefully, I'll learn something from it.  Thanks.


Update: the URL was for another of Tod Kurt's devices, but I couldn't make heads or tails of it..

I understand, the sketch he wrote long ago for the Nunchuck looks for data from memory address 0x40 (decimal 64) of device 0x34 ( decimal 52), But, how do I (a) figure what memory address is this thing using, if not 0x40? and (b) how many bytes will it send?
« Last Edit: October 14, 2013, 08:43:02 pm by gelfling6 » Logged

Pages: [1]   Go Up
Jump to: