Best way to connect wirelessly to Windows app

Hello,

I am starting a new project and I would like to hear some advice. My goal is to connect 4-8 distance sensors and few leds on arduino and then make windows application with GUI to control leds and see sensor data on screen. Later i will add accelerometer and display graph. My question is: which is best solution to make this? Should I use processing, LabView or Visual Studio to manage this? Programming language or environment is not an issue. Thanks in advance

Hello,

I think that there are many good solutions to do your project.

Personnaly I did some similar applications using Arduino UNO, WI-FI ESP8266 modules and

Visual Basic 2010 environnement. Although not very sophisticated, those projects work decently.

I am sure you will find a good way.

Hi, thank you for reply. What is your opinion about flexibility of visual studio with arduino, what i mean by that is are the libraries and documentation good for making gui in visual studio and connecting it to arduino over xbee or it is easier to go with processing.

What is your opinion about flexibility of visual studio with arduino

There is NO connection between Visual Studio, an application that makes it somewhat easier to develop Windows applications, and the Arduino. Visual Studio does NOT have any capability to open a serial port or to read data from, or write data to, that serial port.

What it does have is the ability to let you write a program, using Basic, C, C++, C#, and/of F#, that can open the serial port and read from/write to it. So, lets stop talking about Visual Studio and the Arduino as if they could somehow communicate. They can't.

I HAVE used Visual Studio to build an application, in C#, with a user interface and the ability to open a serial port (hopefully the one that the Arduino is connected to), and send data to, and get data from, that serial port.

The handling of the serial port happens on one thread and the user interface stuff happens on another thread, so you need to understand how to get one thread to communicate with another.

Processing handles all that for you. But, it is terrible for defining useful GUIs.

Hi PaulS,

that is great, that was the answer I was looking for. Can you maybe provide me in the right direction with understanding how to get one thread communicate with another? Is maybe Firmata the solution?

Can you maybe provide me in the right direction with understanding how to get one thread communicate with another?

Starting the serial port is done using a method like this:

		private void connect_Click(object sender, EventArgs e)
		{
			System.ComponentModel.IContainer components =
				new System.ComponentModel.Container();
			port = new System.IO.Ports.SerialPort(components);
			port.PortName = comPort.SelectedItem.ToString();
			port.BaudRate = Int32.Parse(baudRate.SelectedItem.ToString());
			port.DtrEnable = true;
			port.ReadTimeout = 5000;
			port.WriteTimeout = 500;
			port.Open();

			readThread = new Thread(new ThreadStart(this.Read));
			readThread.Start();
			this.hardWorker.RunWorkerAsync();

			connect.Text = "<Connected>";

			connect.Enabled = false;
			comPort.Enabled = false;
		}

Where hardWorker and readThread are declared as:

		private BackgroundWorker hardWorker;

		private Thread readThread = null;

and hardworker is initialized as:

			hardWorker = new BackgroundWorker();

(in the form’s constructor).

The Read() method that the serial thread uses looks like:

		public void Read()
		{
			while (port.IsOpen)
			{
				try
				{
					if (port.BytesToRead > 0)
					{
						string message = port.ReadLine();
						Console.WriteLine("Read from serial port [{0}]", message);
						this.SetText(message);
					}
				}
				catch (TimeoutException) { }
			}
		}

where the SetText() method is declared as a delegate:

		delegate void SetTextCallback(string text);

and is implemented as:

		private void SetText(string text)
		{
			// InvokeRequired required compares the thread ID of the
			// calling thread to the thread ID of the creating thread.
			// If these threads are different, it returns true.
			if (this.receiveText.InvokeRequired)
			{
				SetTextCallback d = new SetTextCallback(SetText);
				this.Invoke(d, new object[] { text });
			}
			else
			{
				this.receiveText.Text += "Text: ";
				this.receiveText.Text += text;
				this.receiveText.Text += Environment.NewLine;
			}
		}

Basically, this allows the UI thread and the serial thread to call the same function. If the caller is the UI thread, the text is handled directly. If it is the serial thread, a delegate is created, and Invoke used to pass the data to the UI thread.

This help a lot! Thank You very much :)