Go Down

Topic: Visual Basic and Arduino Uno Communication (Read 938 times) previous topic - next topic

andre220

Hello,

I am trying to setup a connection between VB Studio and my arduino so that I can eventually make an HMI, however, things are not going well. I am quite new to arduinos and have been looking around the forums to find an explanation or a tutorial for how to connect the two.

I have a VB form open, and my arduino connected via USB and a serial port is placed on the form (configured to COM6, same as the arduino). Basically all I am trying to do is just get some type of feedback in the way of VB output so I know that it is working.

Any help is appreciated.

MikMo


MilanV

I can show you the Arduino code. I don't know VB but I know C#.
Code: [Select]
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the data from the serial port

void setup() {
  pinMode(ledPin,OUTPUT);    // declare the LED's pin as output
  Serial.begin(9600);        // connect to the serial port
}

void loop (){
  if( Serial.available()>0){
    val = Serial.read();      // read the serial port
    if(val==1)          //checks the value
      digitalWrite(ledPin, HIGH); //if the value from serial port is 1 then turn LED on
    if(val==0)
      digitalWrite(ledPin, LOW);  //if the value from serial port is 0 then turn LED off
    else
      Serial.println("Error");
  }
}


The code is simplest. You read the string value from serial port and if it's 1 it turns LED on pin 13 on, or if it's 0 it turns LED off. In VB you need two buttons (On button and Off button) and each of them sends strings 1 or 0 with serial write.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy