Hello,
I've been trying to get my Arduino Mega to communicate with a simple C++ program through the serial port.
Currently, the Arduino seems to communicate fine with the serial interface and I've made a small program allowing me to use the Arduino IDE serial monitor to send and receive data to and from it: it receives the string from the serial monitor and echoes back the result once it has received the string.
Now the problem lies in the following: I'm trying to make a C++ application to allow me to do pretty much the same thing as serial monitor currently does (ie. send a series of bytes to the serial port on which the Arduino is plugged and received the echoed info).
I've found a couple of C++ Serial libraries (currently trying out this one: http://hdrlab.org.nz/a-c-class-for-controlling-a-comm-port-in-windows/ ), made my application, compiles fine but I don't get any result.
For some reason the Arduino is neither receiveing, nor sending data from and to the C++ Application.
The C++ application is the one currently provided by the site I named above.
Any help with this would be greatly appreciated!
Thanks
PS: functional Aduino Mega serial echoing code below
Also, I am running on a W7 64bit OS, not sure whether it matters.
// include the library code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(46, 53, 28, 26, 24, 22);
int bytes=0;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Comp 2 Serial");
Serial.begin(38400);
}
void loop()
{
if(millis()%1000 == 0)
Serial.println("Ping");
if(Serial.available())
{
delay(10);
bytes = Serial.available()+1;
lcd.setCursor(0,0);
lcd.print("Comp 2 Serial");
//bytes++;
char str[bytes];
for(int i=0;i<bytes;i++)
{
str[i] = Serial.read();
delay(10);
}
str[bytes-1] = '\0';
lcd.setCursor(0,1);
lcd.print(str);
//lcd.setCursor(bytes-1,1);
lcd.print(" ");
Serial.print("Received: ");
Serial.println(str);
bytes=0;
}
}