|
|
View previous topic :: View next topic |
Author |
Message |
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
(SOLVED) How to use driver Wii_Nunchuck.c ? |
Posted: Sat Mar 19, 2011 9:01 pm |
|
|
I'm using ver 4.114 on windows XP pro, all upgrades; 18F46K22 w/ internal osc & PLL at 64 MHz...
I'm trying to read the sensors & switches in some cheap Chinese knockoff Wii Nunchucks.... I have searched the forum and read several threads, as well as on the Internet at large. I have modified the init routine in the driver as follows, based on the posting here:
http://www.musclera.com/wii-nunchuk-demonstration
Code: |
void wii_nunchuck_init(void)
{
i2c_start();
i2c_write(WII_NUNCHUCK_WRITE);
i2c_write(0xF0);
i2c_write(0x55);
i2c_stop();
i2c_start(); // this section from web site: http://www.musclera.com/wii-nunchuk-demonstration/
i2c_write(WII_NUNCHUCK_WRITE);
i2c_write(0xFB); //0xA4, 0xF0, 0x55. - then 0xA4, 0xFB, 0x00
i2c_write(0x00); //0x40, 0x00
i2c_stop();
}
|
Here is my code; very basic, just trying to read the data:
Code: |
#include <18F46K22.h>
#fuses INTRC, NOWDT, NOPROTECT, NOXINST
#fuses NOLPT1OSC, MCLR, NOPBADEN, NOWDT
#fuses NOPUT, NOFCMEN, NOIESO, NOBROWNOUT
#fuses NOXINST, NOSTVREN, NODEBUG
#use delay ( clock=64M )
#use rs232 ( baud=115200, uart1 )
#include <Wii_Nunchuck.c>
void main()
{
wii_nunchuck_init(); // Calls wii driver
int8 i = 0;
volatile int8 buffer[6] = {0};
while (true)
{
wii_nunchuck_data(buffer);
buffer = data_buffer;
printf( "Wii Data: %x \n\r", buffer[] ); //wii_data wii_struct data_buffer wii_nunchuck_data()
printf("\n\r");
delay_ms(500);
}
}
|
What I really have not been able to get is how to receive the data back from the functions in the driver code.
Thanks,
Brad
Last edited by Sergeant82d on Wed Mar 23, 2011 10:54 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 19, 2011 11:27 pm |
|
|
The problem is that you didn't provide any information about the
driver code that you need help on.
For example, if I do Google search on this function name, I don't get
any hits:
If I go to the link in your post, they have some code there, but it doesn't
have that function listed. Same thing with this:
Also, the definition of this symbol is missing:
Quote: | WII_NUNCHUCK_WRITE |
To help you, we need some more information. If the information is
contained in Wii_Nunchuck.c, then post the file or post a link to it. |
|
|
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
Wii Nunchuck Driver |
Posted: Mon Mar 21, 2011 5:26 pm |
|
|
My apologies - the driver is in my "Drivers" folder of my 4.014 install... I thought it was included w/ CCS... It has CCS's copyright in it... not supposed to post it here... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2011 9:33 pm |
|
|
I didn't know they had that driver. I looked at it, and here is a test
program that should work. It calls the routine that reads the nunchuck
and loads the results into the global data structure. You then use printf
to display the contents of the structure. This is shown below:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <wii_nunchuck.c>
//==========================================
void main()
{
wii_nunchuck_init();
while(1)
{
wii_nunchuck_data();
printf("x_analog: %u \n\r", wii_data.x_analog);
printf("y_analog: %u \n\r", wii_data.y_analog);
printf("x_axis: %lu \n\r", wii_data.x_axis);
printf("y_axis: %lu \n\r", wii_data.y_axis);
printf("z_axis: %lu \n\r", wii_data.z_axis);
printf("c_button: %u \n\r", wii_data.c_button);
printf("z_button: %u \n\r", wii_data.z_button);
delay_ms(500);
}
} |
|
|
|
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
|
Posted: Tue Mar 22, 2011 7:15 am |
|
|
Thank you - I will try it out this afternoon when I get home. |
|
|
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
|
Posted: Tue Mar 22, 2011 4:27 pm |
|
|
Thanks again, PCM, for a wonderful, brief and correct answer to my questions - it works! |
|
|
david_upn
Joined: 30 Jun 2011 Posts: 1
|
|
Posted: Thu Jun 30, 2011 12:09 am |
|
|
can you post the full code i try connect the nunchuk but no have any response , thacks.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|