Jimmy Engström

NAVIGATION

Building your own Lego Mindstorms EV3 Windows Phone app

I just love gadgets, especially those I can develop for.

I recently got the Lego Mindstorms EV3-kit and of course I wanted to make a Windows Phone app to control it =D.
Here is a tutorial on how to make your own.

The basics

The EV3 has 2 different types of ports, motors and sensors.
Motor ports are A, B, C and D, Sensor ports are 1, 2, 3 and 4.

Check the firmware

To be able to use the API you need to have a firmware version >= 1.03, You can check the version on the brick from the Settings tab-> Brick Info –> Brick FW
To update the firmware run “LEGO MINDSTORMS EV3 Home Edition” and choose Tools –> Firmware Update

image

Enable Bluetooth

To be able to connect to the brick you need to enable Bluetooth you can do that on the brick from the Settings tab-> Bluetooth.
Enable Visibility and Bluetooth.

Pair with the brick

Pair your phone with the brick by going to Settings –> Bluetooth tap on “EV3”, the brick will now ask Ii f its ok to pair and then show a pin code.
Accept the default pin “1234” and enter it on the phone.

We are now all set up to start coding.

I have a Nokia Lumia 920 that I got from //Build, I can’t connect to the brick using that one, it might be a problem with all Lumia 920 developer phone (please let me know).
Luckily I also have a retail Lumia 920 and I have tested this code on a Lumia 1020, 720, 920 and HTC 8X and it works great (just not the //Build one).

Start a new project

image

 

Right click on references and click Manage Nuget packages

Search for "EV3”

image

Click install on “Lego Mindstorms EV3 API”


Enable Bluetooth by opening Properties/WMAppManifest.xml
Enable the capability ID_CAP_PROXIMITY

image

 

The API has the ability to connect to the EV3 by Wi-Fi, Bluetooth and USB for this project I will focus on Bluetooth only.

In MainPage.xaml
Create a button named “ConnectButton” and give it the text “Connect”
Create a button named “MotorAForwardButton” and give it the text “Motor A forward”
Create a button named “MotorStopButton” and give it the text “Stop”

Double click on each button to create the event handler in the code behind.

In MailPage.Xaml.cs att the following code:

private Brick brick;
private async void ConnectButton_Click(object sender, RoutedEventArgs e)
{
    brick = new Brick(new BluetoothCommunication(), true);
    await brick.ConnectAsync();
}

private void MotorAForwardButton_Click(object sender, RoutedEventArgs e)
{
    brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 50);
}
        
private void StopStopButton_Click(object sender, RoutedEventArgs e)
{
    brick.DirectCommand.StopMotorAsync(OutputPort.All, false);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    brick.Disconnect();
    base.OnNavigatedFrom(e);
}

 

I have kept this sample really simple so you can get a quick start.
You should always add error handling and you should disable the buttons unless you already connected and so on.
This is just to get you started.
I realize that this sample isn’t that exciting, but now we know how to control motors, time to kick things into gear and build some fun stuff =D

Related links

https://legoev3.codeplex.com/
The site for the EV3 API, with video instructions

http://www.lego.com/en-us/mindstorms/downloads/software/ddsoftwaredownload/download-software/
Download for LEGO MINDSTORMS EV3 Home Edition

Posted in Gadgets, Windows Phone