Go Down

Topic: Visual Basic and Arduino Uno Communication (Read 1 time) previous topic - next topic



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.



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
      digitalWrite(ledPin, LOW);  //if the value from serial port is 0 then turn LED off

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!

via Egeo 16
Torino, 10131