I'm using visual studio 2012 and implementing a test code to try to figure out why my Arduino isn't receiving any of the data I send. I am using an Arduino zero. I also have tried an Arduino uno, Arduino pro mini and Arduino micro and can try with any of them instead of the Arduino zero if it helps.
I am using a code format from online. When I run the code my led always remains on, indicating that serial.available = 0. I can't open serial monitor while my program is running either as the serial port is busy, which agrees with the lack of available ports.
int incomingByte = 0; // for incoming serial data
int ledPin = 13;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
digitalWrite(ledPin, LOW);
}
else digitalWrite(ledPin, HIGH);
}
I don't have my computer with the c++ code on me right now, but will post it tomorrow morning.
The basic format was
Serial * s = new Serial(COM port);
if(s->isConnected){
s->writeData(char_variable, 1);
//print out test code to see data being transmitted
}
Could someone offer some ideas for why this isn't working? Do I need to send a start bit or something to start serial port communications? Is there a proper SerialClass.h and serial.cpp I should be using?