1

Is it possible to create an application with Mono for Android and control Arduino without using Eclipse but using Visual Studio and C#?

I checked some examples but everyone uses Java and Eclipse.

1 Answer 1

2

Simply put, the answer is yes, it is possible. The real question is: How? I'm going to assume you've already written you first Android app with Mono.

Next, you need to decide how you will connect your Android device to the Arduino. Bluetooth? Wi-Fi? Web?

Next, it's simply a matter of using the appropriate Android API. Check out the Xamarin documentation for Android.

Update

Much more than what I present below is available with the ported MonoDroid sample applications. Specifically, you would be interested in the BluetoothChat example.

Make sure you also take a look at adding permissions to the manifest file, and of course, the Android Developer Guide for Bluetooth.

That said, here's a tiny something to get you started, based on Android Quick Look: BluetoothAdapter:

txtStatus.Text = "Getting Bluetooth adapter...";
BluetoothAdapter bluetooth = BluetoothAdapter.DefaultAdapter;
if( bluetooth == null )
{
    txtStatus.Text = "No Bluetooth adapter found.";
    return;
}

txtStatus.Text = "Checking Bluetooth status...";
if (!bluetooth.IsEnabled )
{
    Toast.MakeText(this, "Bluetooth not enabled. Enabling...", 
        ToastLength.Short).Show();
    bluetooth.Enable();
}

if (bluetooth.State == State.On)
{
    txtStatus.Text = 
        "State: " + bluetooth.State + System.Environment.NewLine +
        "Address: " + bluetooth.Address + System.Environment.NewLine + 
        "Name: " + bluetooth.Name + System.Environment.NewLine; 
} 
else
{
    txtStatus.Text = "State: " + bluetooth.State;
}
Sign up to request clarification or add additional context in comments.

4 Comments

thank you fro the answer. Yeah i already working an application in mono with data transfer with a server. i prefer to connect with bluetooth...i checked the classes and i noticed Android.Bluetooth class(i dont know if i need another classes for my connection yet . but my "fear" is created because i cant find any example in google. thats why i am asking if you ever tried and worked a project with mono +arduino
I know this isn't what you're looking for, but perhaps you might want to look into how to use the Android APIs (Java), and what the equivalent code would be in C#. I can post example code in a few hours, if you'd like. Have you used Bluetooth with Arduino yet?
didnt try it yet. i already control it as .exe(windows form application) and manually with LCD screen on it , and my next step is to control it with bluetooth honestly. but because i am using C# already to create the connection , i wonder if i can do the same as android application with mono droid..(so any example it would be really usefull). thank you in advance
It depends on how well you separated the control and connection code in your previous C# application. Once you have the Bluetooth connection set up, it boils down to sending and receiving bytes, just like a serial connection from PC to Arduino. What bytes you send and what you do with those that you receive should be transparent of you medium of communication (i.e. Bluetooth or RS-232). In most cases, on the Arduino side of things you won't change much at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.