Communication between Arduino and Visual C++ Prog.

Hello!

I have written a program in Visual C++ 2005, in which I now need to set a value whether the LED on the Arduino is lighting or not. The Arduino is connected with the PC over USB.
The code for the Arduino is the following:

int ledPin = 13;
int inPin = 9;

int val = 0;     // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(inPin, INPUT);
}

void loop(){
  val = digitalRead(inPin);
  if (val == HIGH) {
    digitalWrite(ledPin, HIGH); // turn LED off
    // Serial communication that LED is off
  } else {
    digitalWrite(ledPin, LOW);  // turn LED ON
    // Serial communication that LED is on
  }
}

So every time the circuit is closed, the LED is on.

My questions are now:

What do I need on the PC-Side (libraries etc.), to find out in my program whether the LED is on or off?
Which messages do I have to send from the Arduino?

Thanks for all answers!

Best regards,
Bimbo

Use your Arduino to send a serial message and write a C++ program that opens the proper serial port and waits for incoming serial messages from your Arduino. It's up to you to come up with a protocol that suits your needs. Everything you need for handling serial communication is included in .NET.

  • Ben