Author Topic: Axon and Nunchuck by i2c  (Read 2810 times)

0 Members and 1 Guest are viewing this topic.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Axon and Nunchuck by i2c
« on: September 24, 2009, 05:34:10 AM »
hi,
I've a heavy problem with the communication over the I2C-Bus.
My plan was to use the wii-nunchuck for a manual control of my robot.
I've used http://www.societyofrobots.com/member_tutorials/node/35 to get inforations of the I2C,
For pluging I used this http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/ (I didn't want cut any wires), so I had this description http://todbot.com/arduino/sketches/WiichuckDemo.zip for geting startet and translate the code into somthing running with i2c.h (the standart for axon), but I had no success.
Can anyone help me solving this issue, I've tried so much and nothing runs.

A lil 2nd question:"Do I need any resistor for terminate the SCl and SDa data?" I read about this, bit I'm not shure because there isn't any on this tobot.com-tutorial

Even at this many places, thanks for the help.
WfG Patrick
I just started with robitic.

PS.: you have to sorry my bad english.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Axon and Nunchuck by i2c
« Reply #1 on: September 24, 2009, 07:55:31 PM »
Quote
A lil 2nd question:"Do I need any resistor for terminate the SCl and SDa data?" I read about this, bit I'm not shure because there isn't any on this tobot.com-tutorial
You can turn on internal pull-up resistors using software for the Axon.

To do so, open up SoR_Utils.h

change this:
Code: [Select]
DDRD = 0b11110011;  //configure ports for output
to this:
Code: [Select]
sbi(PORTD, PD0); // SCL pull-up
sbi(PORTD, PD1); // SDA pull-up
DDRD = 0b11110011;  //configure ports for output

I'll make that a default when I release v1.11.

Give that a try, and if still no luck, describe in more detail where you think you are stuck.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: Axon and Nunchuck by i2c
« Reply #2 on: September 25, 2009, 06:47:32 AM »
Thanks for this Answer, but I'm still not shure how to read the data from the Nunchuck.
I'll try a few things, but help by translating the nunchuck_func.h into somthing that can run with i2c.h from the Axon would be nice.
I'll put some code up when I have something locking god.
I just started with robitic.

PS.: you have to sorry my bad english.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Axon and Nunchuck by i2c
« Reply #3 on: September 25, 2009, 07:02:11 AM »
Here is an example of using I2C with the Axon for a digital compass:
http://www.societyofrobots.com/robotforum/index.php?topic=8393.0

It'll help you reverse engineer the code you found.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: Axon and Nunchuck by i2c
« Reply #4 on: September 25, 2009, 07:34:33 AM »
I know, that looks so easy, but nothing is working...
...here the code I tried last (still nit working)

Code: [Select]
#define Wii_ADDR 0x52
#define BUFFSIZE 0x06

void nunchunk_data(void){
volatile u08 databuffer;
volatile u08 readbuffer[BUFFSIZE];
databuffer=0;

i2cMasterSend(Wii_ADDR, 0x01, &databuffer);
delay_ms(10);
i2cMasterReceive(Wii_ADDR, BUFFSIZE, &readbuffer);

rprintf("\n Data: ");
for (i = 0; i < BUFFSIZE; i++)
{
rprintfu08(readbuffer[i]);
rprintfChar('.');
}
rprintf("\n");

accx  = readbuffer[2]; // ranges from approx 70 - 182
    accy  = readbuffer[3]; // ranges from approx 65 - 173
accz  = readbuffer[4];
    zbut  =((readbuffer[5] >> 0) & 1) ? 0 : 1;
    cbut  =((readbuffer[5] >> 1) & 1) ? 0 : 1;
xjoy  =readbuffer[0];
yjoy  =readbuffer[1];
}


void nunchuck_init(void){
i2cMasterSend(0x52, 0x02, 0x4000);
}


I get the nice line 00.00.00.00.00.00, but i don't know why.
I just started with robitic.

PS.: you have to sorry my bad english.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: Axon and Nunchuck by i2c
« Reply #5 on: September 25, 2009, 08:54:43 AM »
Still not working, but on a god way. Have receaved some date (but still not the right interpratation or some small  mistake).
Here some code, I'm open for help, loding up thecorrect code if it runs correctly.

Code: [Select]
#define Wii_ADDR 0x52
#define BUFFSIZE 0x06

void nunchunk_data(void){
volatile u08 databuffer;
volatile u08 readbuffer[BUFFSIZE];
databuffer=0;

int i;

rprintfInit(uart1SendByte);  // Set up rprintf to be USB

i2cSetBitrate(100);  //set I2C transaction bit rate to 100 kHz

i2cSendStart(); //Send I2C start condition in Master mode
i2cSendByte(Wii_ADDR | 0x40 | 0x00);    //Send (address| memory address |R/W) combination or a data byte over I2C

i2cSendStart(); //Send I2C start condition in Master mode
i2cSendByte(Wii_ADDR | 0x00);    //Send (address|R/W) combination or a data byte over I2C

for (i=0;i<BUFFSIZE;i++) {
i2cReceiveByte(1);
readbuffer[i] = nunchuk_decode_byte (i2cGetReceivedByte());

}

i2cSendStop();      //Send I2C stop condition in Master mode


rprintf("\n Data: ");
for (i = 0; i < BUFFSIZE; i++)
{
rprintfu08(readbuffer[i]);
rprintfChar('.');
}
rprintf("\n");

accx  = readbuffer[2]; // ranges from approx 70 - 182
    accy  = readbuffer[3]; // ranges from approx 65 - 173
accz  = readbuffer[4];
    zbut  =((readbuffer[5] >> 0) & 1) ? 0 : 1;
    cbut  =((readbuffer[5] >> 1) & 1) ? 0 : 1;
xjoy  =readbuffer[0];
yjoy  =readbuffer[1];
}

static u08 nunchuk_decode_byte (u08 x)
{
    x = (x ^ 0x17) + 0x17;
    return x;
}
I just started with robitic.

PS.: you have to sorry my bad english.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Axon and Nunchuck by i2c
« Reply #6 on: September 27, 2009, 12:11:48 PM »
Quote
Still not working, but on a god way. Have receaved some date (but still not the right interpratation or some small  mistake).
Here some code, I'm open for help, loding up thecorrect code if it runs correctly.
Could you re-explain? I don't quite understand what you mean . . .

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Re: Axon and Nunchuck by i2c
« Reply #7 on: September 27, 2009, 03:40:25 PM »
my problem is I get some data locking randomized. There're all bytes the same (most time FF.FF.FF.FF.FF.FF, but I had some tries with 2D.2D.2D.2D.2D.2D or somthing else), locking like that it isn't changing if I do something, there is this Print all the time (unchanged).
I just started with robitic.

PS.: you have to sorry my bad english.

 


Get Your Ad Here

data_list