Creating interface using Visual Basics to read value from the Arduino Mega 2560

I'm trying to create an interface using VB to display the value from the Arduino Mega 2560 board. But, how can we read the values from the arduino continuously to VB once we run the VB application without using any sort of buttons in VB application?

My project involves creating an interface for Arduino in the monitor and display the analog voltage values in terms of percentages in VB application. Since we are giving analog inputs to the board, the values should be read continuously to the interface window.

I tried to write and read the values using buttons like "Send to Arduino" and "Read from Arduino". But I was asked to remove the buttons in Windows form application and read the values sent from the Arduino board.

VB Code:

if (port.IsOpen)
{
in1textBox.Text = port.ReadLine();
in2textBox.Text = port.ReadLine();

Here I'm using the Serial.println command in Arduino to write the values to the serial port and used read line command VB to display the percentage value of analog voltage given by the user.

All I'm in need of are suggestions to make this project possible. If I can use your help to write the code in Visual Basics that would help me in completing the project. Thank You.

Since we are giving analog inputs to the board, the values should be read continuously to the interface window.

Now, this is a silly notion. There is nothing "continuously" about reading an analog value, converting the value to a string, and sending the string over the serial port. Each read/convert/send is a discrete event. The interval between events might be small, but there IS an interval.

Here I'm using the Serial.println command in Arduino to write the values to the serial port and used read line command VB to display the percentage value of analog voltage given by the user.

And the problem is?

You should set the serial instance to buffer data until some delimiter arrives. You should also have a delegate deal with the arrival of serial data. That delegate will deal with each packet as it arrives.

Yes Mate I get what your trying to say. I have used a buffer to read the value into Arduino and I'm able to send multiple data using the buffer from Visual C#.

Mate, I'm using Visual C# to send my data to Arduino Mega 2560 board. For this operation I'm using a send button to write the value to serial port. Is it possible to send data without the use of any button in Visual C# ?

Is it possible to send data without the use of any button in Visual C# ?

Of course. The only question is what is going to trigger sending the data? If you have a Windows Forms app, the whole application is event driven. Some event needs to trigger sending the data.

That event could be a timer firing.

However, your original post talked about the PC app receiving data. Since that happens in a thread of it's own, the function that deals with incoming serial data is called whenever there is serial data to read. If that function calls ReadLine(), the function blocks for the read timeout period or until a carriage return/line feed arrives.

So, the function actually does something useful only when a complete packet arrives, and it does that as soon as the end of packet marker (CR/LF) arrives.

Mate! my project actually involves monitor interface for Arduino.
For example, if a user is giving 1V and 2V to A0 and A1 pins respectively using AnalogRead() in arduino I'm trying to display the percentage values of these two voltages in Visual C#. And based on the input that we give, the output voltages has to displayed in Visual C# as well. So 1st I tried using SEND and READ buttons in Visual C# to display the value and its working fine. But I was asked to implement this project without the use of any buttons in Visual C#.

Can you please suggest me a way to make this project work. Cause the user may give different voltages at different times, so the windows form application should be able to display what ever the input and output percentage values.

The problem I'm facing at the moment is, if we give 2-Input in Arduino I'm able to receive those values in windows form application, but what if the user gives another values in the input ?
And if we give values from VB to arduino, I have used a buffer to read the values for which I used SEND button click in VB and my professor has asked me not to use any button either to read or write, how can this case be possible ?

I'm using 2- text boxes to send the inputs to Arduino serial port and I'm performing some logic in Arduino, now I'm writing the value to serial port. How to receive output in Windows form application without any button click.

Can you please help me coding in Visual C# to receive the values from Arduino to VB even though the user change the inputs and replace the functionality of SEND button without actually using it.

Thank You.

So 1st I tried using SEND and READ buttons in Visual C# to display the value and its working fine.

What did you send to the Arduino? What did you do with the serial data that it returned?

The C# application creates a thread that listens for serial data to arrive, and does something with the data when it arrives. THAT part has NOTHING to do with buttons or forms or timers.

Can you please help me coding in Visual C# to receive the values from Arduino to VB even though the user change the inputs and replace the functionality of SEND button without actually using it.

No. I can't imagine why you'd want to read the data using C# and then send that data to VB.

C# is able to do the whole job.

I'm using C# just to display numbers like 40.32 or 30.00 etc. These numbers are percentage values of voltages given to the Arduino analog input pins. For example,

A0 pin - 2V -- 40% (in 0-5V range) .... Hence 40.00 should be sent to and displayed in the Windows form application create by C#. I agree with you regarding reading the values from the Arduino using threads.

And also, to implement ON-OFF controller experiment we are using SET-POINT (0-255 range) and HYSTERESIS (0-100) both of these values should be sent to Arduino board. So that depending on the logic written in Arduino ON-OFF controller action should be implemented.

Pls find the attachment below. Thank You.

Sample Output.pdf (219 KB)

Hi,

We've created a library that does exactly this: It can send and receive messages between .NET and Arduino: CmdMessenger. It comes with samples for both Visual Basic and C#, see this forum post:
http://forum.arduino.cc/index.php?topic=186928.0