analogRead and Serial in Visual Studio

Hello, could you please help me with this question:

I have a program that does the following in arduino:

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(13, HIGH);
  delay(1000); // Approximately 10% duty cycle @ 1KHz
  // read the input on analog pin 0:
  float sensorValue = analogRead(A0);
  Serial.println("Detected ");
}

The purpose is to make this simple progarm in Visual Studio, because I connect also another interface with serial port.

I have developed an application in Visual Studio

According to this tutorial : manash.me
windows-d08710186498 that

connects to the Arduino Com Port. I can already write something and print it. However when i read content

back it is corrupted, so for sure I am doing something wrong.

while (arduino.isConnected()){
				int read_result = arduino.readSerialPort(incomingData, MAX_DATA_LENGTH);
				cout << read_result << " " << &incomingData << " " << incomingData <<   endl;
				puts(incomingData); 
				Sleep(1000);

The above returns corruputed chars and I am afraid there is something I haven't understood well.

Could you please advise how to implement the Serial.print and the analogRead, as well as the pinMode functions?

Could you please advise how to implement the Serial.print and the analogRead, as well as the pinMode functions?

First, the analogRead() function returns an int, not a float. Second, you never print() the value that you read. Third, you have not described what you mean by, or shown any evidence of, "corrupted characters". Fourth, you have not posted the complete VB application code. So, no, we can't really help you.

Hello, thank you for your reply. Please find the code attached.

I will correct the analogread float to int. You see the characters I receive at the screen.

My question is how can I implement the same way with analogRead, pinMode etc. in windows app if there is a built in library that I can use instead of an ino file. Thank you

arduino.cpp (2.08 KB)

Manager.cpp (2.01 KB)

arduino.h (586 Bytes)

My question is how can I implement the same way with analogRead, pinMode etc. in windows app if there is a built in library that I can use instead of an ino file.

Suppose that you call a friend, on the phone. Your friend can bark like a dog, sing like a bird, and piss like a race horse. How do you get him/her to do any of those things? It is NOT by calling his/her bark(), sing(), or piss() methods. It is be asking him/her to invoke the appropriate method.

There is nothing you can put on the Arduino that will expose the analogRead(), pinMode(), etc. functions in such as way that an app on the PC can execute them.

Personally, I'd dump that code you have, and create a C# app to talk to the Arduino. I know THAT works, because I have a functioning C# app that sends data to, and gets data from, my Arduino.