Go Down

Topic: 2 inputs from visual studio to arduino (Read 1 time) previous topic - next topic

kkimlee4

Hi,

I am trying to use visual studio to control my arduino.

what i would like to do is...

 - have on/off button to control LED on visual studio
 - have a textbox to display on arduino


My questions is:

- how do you differ those two different inputs from arduino... if i am just using data = Serial.read()


kkimlee4

I posted this before but I thought I should post this again properly.

Someone please help me.



what I am trying to do:

 - have two outputs through Arduino (LCD, LED)

What I have:

 - using Visual Studio 2015, using C# right now

from visual studio, i have two buttons, and 1 text box (please see attachment for an image)

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Arduino_Connection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            serialPort1.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.Write("A");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.Write("j");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}



I have not wrote down anything for the text box portion yet. Because i do not know if i can use same serialPort to send a data to Arduino when Arduino is reading from the same Serial


Code: [Select]
int data;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}



void loop()
{
  if (Serial.available())
  {
    data = Serial.read();

    if (data == 'A')
    {
      digitalWrite(13,HIGH);
    }
    else
    {
      digitalWrite(13,LOW);
    }
  }
 
}




so, basically i have the LED worked out. but if i were to have a text msg box work out using the visual studio with Arduino... how do i do that...? 
Is there any way i can distinguish the data that i am trying to use from visual studio to arduino?

PLEASE HELP!!!

Thank you so much in advance!!


nickgammon

Please don't cross-post. Your thread title of "PLEASE HELP ME QUICK!!!" is appallingly bad. Most people will just move on. Post what you are trying to do, not "help me quick".

Threads merged.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

kkimlee4

6v6gt.
Thank u for ur reply, but your link does not solve any of my problems here.

I understand how to control lcd or led using VS and arduino but not led and lcd.


I am sorry about posting it twice.  I could not edit the first thread within 5 mins, so i decided to write again after reading the sticky.

kkimlee4

What i am trying to do is having 2 seperate user inputs (message box & on/off switch) from user interface (VS) and output it to arduino lcd screen and led.

For example, user can type "potato fries" and indicate if the cooking machine is on or off.

Thank you...

6v6gt

You have successfully demonstrated that from C# running on your PC, you can activate a button and transmit the results through the serial port right through to the Arduino where you can interpret the data stream and activate a LED. Is that correct ?

Why not simply code the message box and attempt to send a value to the Arduino using the same construct ie serialPort1.Write("xxxxxxxxxxxxxxxxx");
On the Arduino, then start by simply printing out what you have read on the serial port. Once you see what you get, work out how you can parse it (and distinguish it from the data for the 'button press')

Robin2

Have a look at Serial Input Basics - in particular the parse example.

Make your PC program send data in the format used by that example.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Andrija24

Hi, I have one question.
How I can get action from button on arduino in my visual studio C# windows form app?
I used StandardFirmata for communicate with arduino, but I can not get action when I press button on arduino.

Robin2

You are asking a new question in an old Thread. Your question has been moved to it own Thread here.

Please don't double post.

...E
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up