 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
sumon
Joined: 30 Mar 2008 Posts: 6 Location: Sweden
Digg It |
Posted: Tue Apr 01, 2008 6:53 pm Post subject: WiiRemoteJ and Arduino |
|
|
Hi,
Is there any one tried to interface the wii remote with the Arduino or any other Microcontroller devices by using the WiiRemoteJ API?
I am trying to connect the wii with the Arduino Diecimila, but its showing “Extension partially inserted” error! I setup the Arduino as a Slave device (0x52) for the I2C bus of wii extension, so that wii can detect it as a Nunchuk, but it is not! My cabling and coding are same as the project “Wiimote controlled firefighting robot” (plz Google it for details, Im not allowed post link, as I am new to forum!).
I want to use the Arduino to get some custom data to and from wii.
Is there any supporting issue with the WiiRemoteJ API or something else? Little help/advice will be appreciable in this regards.
Thanks in advance.
/Sumon |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 466
Digg It |
Posted: Tue Apr 01, 2008 11:24 pm Post subject: |
|
|
Did you create a custom extension class for the Arduino and register it with the extension factory? If you have no idea what I'm talking about, please see the API, esp. WiiRemoteExtensionFactory and WiiRemoteExtension. _________________ Cha0s |
|
| Back to top |
|
 |
sumon
Joined: 30 Mar 2008 Posts: 6 Location: Sweden
Digg It |
Posted: Wed Apr 02, 2008 2:22 pm Post subject: |
|
|
Hi Cha0s,
Thanks for your advice. I have tried to do so but it’s unable to register the extension (Arduino) and showing following errors:
Apr 2, 2008 3:25:22 PM wiiremotej.WiiRemoteExtensionFactory registerWiiRemoteExtension
WARNING: Error registering extension.
java.lang.UnsupportedOperationException: Not supported yet.
at wii.wii_Arduino$2.getCode(wii_Arduino.java:68 )
at wiiremotej.WiiRemoteExtensionFactory.registerWiiRemoteExtension(WiiRemoteExtensionFactory.java:67)
at wii.wii_Arduino.<init>(wii_Arduino.java:86)
at wii.wii_Arduino.main(wii_Arduino.java:26)
I have created the WiiRemoteExtension with the payload 8 and than register it by registerWiiRemoteExtension method.
May be there are the problem with my codes. Would you please kind enough to post some code for me?
Thanks,
/Sumon |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 466
Digg It |
Posted: Wed Apr 02, 2008 2:42 pm Post subject: |
|
|
Something in your code is throwing that Exception. I'd have to see it to help with debugging. By the way, are you sure the Arduino is compatible with the Wii Remote? The fact that it's showing up as "partially inserted" does not bode well. _________________ Cha0s |
|
| Back to top |
|
 |
sumon
Joined: 30 Mar 2008 Posts: 6 Location: Sweden
Digg It |
Posted: Wed Apr 02, 2008 8:43 pm Post subject: |
|
|
HI Cha0s,
I am really not good in JAVA. Follows are the simple code given in the example API, which I tried for testing.
| Code: | public class wii_Arduino {
public static void main (String args[]){
new wii_Arduino();
}
public wii_Arduino(){
try{
//WiiRemoteJ.setConsoleLoggingAll();
WiiRemoteDiscoveryListener wrdlistener = new WiiRemoteDiscoveryListener()
{
public void wiiRemoteDiscovered(WiiRemoteDiscoveredEvent evt)
{
evt.getWiiRemote().addWiiRemoteListener(new wii(evt.getWiiRemote()));
}
public void findFinished(int numberFound)
{
System.out.println("Found " + numberFound + " remotes!");
}
};
//Find and connect to a Wii Remote
WiiRemote remote = WiiRemoteJ.findRemote();
remote.addWiiRemoteListener(new wii(remote));
remote.setAccelerometerEnabled(true);
//remote.setInterleaved(false);
//Extension with 6 payload
WiiRemoteExtension wrx= new WiiRemoteExtension(6) {
public boolean isPayloadValid(int arg0) {
throw new UnsupportedOperationException("Not supported yet.1");
}
public void decryptExtensionInput(byte[] arg0, int arg1, int arg2) {
throw new UnsupportedOperationException("Not supported yet.2");
}
public short getCode() {
throw new UnsupportedOperationException("Not supported yet.3");
}
public WRExtensionEvent createWRExtensionEvent(WiiRemote remote, byte[] arg1, int arg2) {
try {
System.out.println(remote.getBluetoothAddress());
} catch (IOException ex) {}
throw new UnsupportedOperationException("Not supported yet.4");
}
};
WiiRemoteExtensionFactory wrxf = WiiRemoteExtensionFactory.getDefault();
//short s = (short)123;
//wrxf.createWiiRemoteExtension(s);
wrxf.registerWiiRemoteExtension(wrx);
}
catch(Exception e){}
}
public void disconnected(){
System.out.println("Remote disconnected... Please Wii again.");
System.exit(0);
}
} |
The error in coming from “public short getCode()” method and its quit obvious because I am not sure about the code for the extension types. The createWiiRemoteExtension(short code) takes code for different extension types, but I don’t know what it will be for NunChuk or even its necessary!
Arduino can communicate with the I2C bus, and its address can be set to any thing for the bus. In this case the address is 0x52, which is a Nunchuk address and wii suppose to detect it as a Nunchuk. Inside the Arduino there is a method which sends chunk of data if requested by master (wii), here 6 byte for wii (Extension status report ).
The same thing is done by Chad on windmeadowDOTcom/node/45. He used the libcwiimote API (written in C) for the wii in Linux environment. But I am doing my project on JAVA and in windows environment.
I just want to receive some data from the Arduino via wii as an Acceleration or Button input data.
Please help me with the code.
/Sumon |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 466
Digg It |
Posted: Wed Apr 02, 2008 11:08 pm Post subject: |
|
|
Ah, ok. Well, in that case, you'll need to remove the Nunchuck extension:
| Code: | WiiRemote remote = WiiRemoteJ.findRemote();
WiiRemoteExtensionFactory factory = remote.getExtensionFactory();
factory.removeExtension(0x52);
factory.registerWiiRemoteExtension(wrx); |
Now, you need to implement all those methods that you're saying are unsupported.
| Code: | WiiRemoteExtension wrx= new WiiRemoteExtension(6) {
public boolean isPayloadValid(int payload) {
return payload == getPayload();
}
public void decryptExtensionInput(byte[] arg0, int arg1, int arg2) {
//this may or may not be necessary, depending on
//how Arduino works
}
public short getCode() {
return (short)0x52;
}
public WRExtensionEvent createWRExtensionEvent(WiiRemote remote, byte[] arg1, int arg2) {
try {
System.out.println(remote.getBluetoothAddress());
} catch (IOException ex) {}
throw new UnsupportedOperationException("Not supported yet.4");
//this needs to parse the data and return an event.
return null; //for now I'll have it return null
}
}; |
That should work, though it won't do anything until you implement createWRExtensionEvent. _________________ Cha0s |
|
| Back to top |
|
 |
sumon
Joined: 30 Mar 2008 Posts: 6 Location: Sweden
Digg It |
Posted: Sat Apr 12, 2008 7:27 pm Post subject: |
|
|
Hi Cha0s,
Sorry for the delayed reply.
Thanks for your code on last post. It works fine and I can receive the data from wii to Arduino by writing manually to the register. But I am having problem to receive the data from wii as a Nunchuk or something else’s data.
The abstract methods “createWRExtensionEvent(,,)” is seems to be never executing, as like the “getCode()” method. I have tried manually to fire the “extensionInputReceived” event by executing the “createWRExtensionEvent(,,)” by returning current remote object with 0x00 and 0 values! Than caste the “WRExtensionEvent” to “WRNunchukExtensionEven”, but its failed
Would you please tell me what to do or how can I manually (or continuous as Nunchuk) receive the data from extension port (as like sending, by writing to port a400xx)
| Code: | public class wii_Arduino extends WiiRemoteAdapter{
static WiiRemote remote;
static byte[] extData;
static int extFirstByte;
public int x, y, z;
static WiiRemoteExtension ABC;
public static void main (String args[]){
try{
WiiRemoteJ.setConsoleLoggingAll();
WiiRemoteDiscoveryListener wrdlistener = new WiiRemoteDiscoveryListener()
{
public void wiiRemoteDiscovered(WiiRemoteDiscoveredEvent evt)
{
evt.getWiiRemote().addWiiRemoteListener(new wii(evt.getWiiRemote()));
}
public void findFinished(int numberFound)
{
System.out.println("Found " + numberFound + " remotes!");
}
};
//Find and connect to a Wii Remote
remote = WiiRemoteJ.findRemote();
remote.addWiiRemoteListener(new wii_Arduino(remote));
remote.setAccelerometerEnabled(true);
remote.getButtonMaps().add(new ButtonMap(WRButtonEvent.HOME, ButtonMap.NUNCHUK, WRNunchukExtensionEvent.C, new int[]{java.awt.event.KeyEvent.VK_CONTROL},
java.awt.event.InputEvent.BUTTON1_MASK, 0, -1));
WiiRemoteExtensionFactory factory = remote.getExtensionFactory();
factory.removeExtension((short)0x52);
factory.registerWiiRemoteExtension(ABC=new WiiRemoteExtension(6){
public boolean isPayloadValid(int payload){
System.out.println("Inside Payload..............1");
return payload == getPayload();
}
public void decryptExtensionInput(byte[] arg0, int arg1, int arg2){
System.out.println("Inside DecryptExtension........2");
}
public short getCode(){
System.out.print("Inside getCode...................3");
//It works with any address !!!
return (short)0x52;
}
// This method never execute!
public WRExtensionEvent createWRExtensionEvent(WiiRemote remote1, byte[] arg1, int arg2){
remote1= remote;
System.out.println("createWRExtensionEvent..........4");
byte [] b = {0x00};
arg1=b;
arg2=0;
return new WRExtensionEvent(remote){};
}
});
//This throws following exception
//java.lang.IllegalStateException: Extension not connected!
//at wiiremotej.WiiRemote.setExtensionEnabled(WiiRemote.java:1610)
//remote.setExtensionEnabled(true);
}
catch(Exception e){e.printStackTrace();}
}
// Used this method, because this event fire after connecting Arduino (I added the listener for wii)
public void extensionUnknown()
{
System.out.println("Extension unknown............................");
//Sending all zeros, just to check what happen (maybe its wrong)
byte []b = {0x00};
// calling and Returning a WRExtensionEvent
extensionInputReceived(ABC.createWRExtensionEvent(remote, b, 0));
}
public void extensionInputReceived(WRExtensionEvent evt){
WRNunchukExtensionEvent NEvt = (WRNunchukExtensionEvent)evt;
WRAccelerationEvent AEvt = NEvt.getAcceleration();;
x = (int)(AEvt.getXAcceleration()/5*300)+300;
y = (int)(AEvt.getYAcceleration()/5*300)+300;
z = (int)(AEvt.getZAcceleration()/5*300)+300;
System.out.println("Valur of x: "+ x + "Y: "+y + "Z: "+z);
if (NEvt.wasPressed(WRNunchukExtensionEvent.C))System.out.println("C button input receive!!!");
if (NEvt.wasPressed(WRNunchukExtensionEvent.Z))System.out.println("And crouch.");
} |
I receive following output, when connect Arduino:
Apr 12, 2008 9:11:58 PM wiiremotej.WiiRemote connectToExtension
FINER: Extension code: 0x7d7e
Inside getCode...................3Extension unknown............................
createWRExtensionEvent..........4
Apr 12, 2008 9:11:58 PM wiiremotej.WiiRemote connectToExtension
WARNING: Unable to connect to extension!
java.lang.ClassCastException: wii.wii_Arduino$2$1 cannot be cast to wiiremotej.event.WRNunchukExtensionEvent
at wii.wii_Arduino.extensionInputReceived(wii_Arduino.java:127)
at wii.wii_Arduino.extensionUnknown(wii_Arduino.java:121)
at wiiremotej.WiiRemote.connectToExtension(WiiRemote.java:1355)
at wiiremotej.WiiRemote.access$600(WiiRemote.java:63)
at wiiremotej.WiiRemote$1$1.run(WiiRemote.java:339)
at java.lang.Thread.run(Thread.java:619)
Please write some code for me, how can I get data from the extension.
/Sumon |
|
| Back to top |
|
 |
|
|
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
|