Hobby project – Lego NXT, XBox 360 controller, PC and C#. Part 3

By | 7. August 2015

Back to Part 2

Now time is ready to start actual programming. We will use classical desktop Windows Forms Application. For target framework we choose .NET 4.5

project01

As MonoBrick defualt library  is compiled to target x86 then we have to do same

project02

 

First task is to add libraries mentioned in Part 2 – J2i.Net.XInputWrapper.dll fro Xbox Ciontroller and MonoBrick.dll for Lego NXT.

We made separate Libraries directory, but you are free to hold them where you like, just add them to References.

Setting Up Project

Setting Up Project – reference files

Two other files –  LibUsbDotNet.dll and hidapi.dll are part of MonoBrick library download. The are used in case NXT communication is done via USB. We don not need them for now , but will keep them just in case we want try USB connection later.

Now we will two buttons on screen and code behind them to test if we can connect to our devices.

Main Screen

Main Screen

First we will test connection to Lego NXT:

NXT Connection test

NXT Connectivity Test

 

using MonoBrick.NXT;   –  We need MonoBrick library

We will create new Brick called nxt. In our case Bluetooth connection uses virtual port com3.

Next we open connection, switch on one motor to speed 40 for 2 seconds and switch it off again.

If error occurs we report it to message box and in any case nxt connection is closed in finally section.

Pay attention to what port your motors are connected, we had B and C. For initial test we used nxt.MotorA and were for a moment surprised that there was no movement but no error either.

Now we can run the program and if all is correct then pushing button [NXT Connection Test] will result little spin by Lego NXT robot.

 

Next task is test Xbox controller connectivity.

 

XBox Controller Connectivity Test

XBox Controller Connectivity Test

using J2i.Net.XInputWrapper; – again the library to access XBox 360 controller

XboxController.RetrieveController(0); – this  access to first connected controller, if you have more than one XBox controller connected then you should use corresponding number from 0 to 3.

For test we will vibrate both motors. There is no connection to open and close in case of  XBox Controller.

Run the program and press button [Controller Connection Test] , both motors in controller should vibrate shortly.

Both tasks completed we are ready to program logic.

 

 

One thought on “Hobby project – Lego NXT, XBox 360 controller, PC and C#. Part 3

  1. Pingback: Hobby project – Lego NXT, XBox 360 controller, PC and C#. Part 2 - Software Blog

Leave a Reply