Now that UDP is supported in AIR, communication with a Nintendo DS is no big deal. Let’s start with the requirements:
- NDS (with WFC already configured)
- A Flashcard (I have an R4, but Ezflash or M3 would be ok too)
- DS2Key (for sendig data from DS to your computer)
- Know your DS and computer’s IP.
- Of course a computer, a router, Flex (or FDT, FlashDevelop, whatever) and AIR sdk 2 beta (and runtime).
The code is very simple actually for this example, it just reads the coordinates where the stylus is pressing the touchscreen, I’m just showing the important parts:
//IP & port for this computer
private var localIP:String = “xxx.xxx.xxx.xxx”;
private var localPort:int = 55555;
//IP & port for NDS
private var targetIP:String = “yyy.yyy.yyy.yyy”;
private var targetPort:int = 55555;
private function init():void
{
datagramSocket = new DatagramSocket();
datagramSocket.addEventListener(DatagramSocketDataEvent.DATA, dataReceived);
datagramSocket.bind(localPort, localIP);
datagramSocket.receive();
//Need to actually send comething to receive data… don’t know why, sorry
var data:ByteArray = new ByteArray();
data.writeUTFBytes(“Some data”);
datagramSocket.send( data,0,0, targetIP, targetPort);
}
private function dataReceived(event:DatagramSocketDataEvent):void
{
//get the data, X and Y position of the DS stylus
var pos:String = event.data.readUTFBytes(event.data.bytesAvailable);
// we receive for example “/m120.90.3″
// 120 is the value in the X axis, and 90.3 the value for Y
var separate:String = StringUtils.beforeFirst(pos, “.”);
var firstPart:String = StringUtils.remove(separate,”/m”);
var secondPart:String = StringUtils.afterFirst(pos, “.”);
//Your stuff
}
(As you can see I used Grant Skinner’s StringUtils which is here).
That’s all we need to receive and handle data from the NDS.
Now, to send data from the NDS, the DS2Key is needed (grab it here), to install it we just copy the DS2key.nds to the flashcard. Insert the flashcard into the NDS, run DS2Key to set the target computer’s IP and the port (55555 in this case).
And that’s it! Very easy. Of course, this is not limited to just reading the X and Y values of a point in the touchscreen being pressed with the stylus, button (x, y, b, a, etc. ) states can also be read. At first I had problems getting the data from the DS, so make sure the port you are using is open, that solved it for me.
I did a simple drawing application:
You can download the source here.







[...] This post was mentioned on Twitter by Joseph Burchett, katopz and Abraham Vázquez , Joseph Burchett. Joseph Burchett said: RT @bioRex21: Communicating Nintendo DS with Adobe Air http://bit.ly/72whpl [...]
just don’t stop doing this! i love it!
I won’t, I have another experiment in mind
unfortunately, it has to wait till next week
[...] developer, nicknamed bioRex21, highlights another ingenious use for AIR. bioRex21 managed to use a Nintendo DS and Adobe AIR to create a simple drawing application (video [...]
Wow, awesome — got any more like this?
Check this fun remote I am working on:
http://sjevsejev.blogspot.com/2010/06/progress-on-remote4android-part-2.html