Hi. I'm having trouble connecting to an Arduino Leonardo via a serial COM port, from a program I've written in PureBasic.
My PureBasic program opens a serial port with the following parameters: 9600 baud, 8 bits, no parity, 1 stop bit, no handshaking, 32 byte buffer. These are the same settings I've used successfully countless times in other Arduino projects.
Straight after programming the Leonardo, the connection works exactly as expected. I can connect and disconnect at will, both from my PureBasic program, and the Arduino IDE serial monitor. However, if I unplug and reconnect the Leonardo (and wait for the bootloader to pass), it behaves differently: Connecting from my PureBasic program no longer works. The PC says the connection is open, but the Leonardo doesn't report it. If, after this, I open a serial connection using the Arduino IDE, it works fine. And if I try my basic program again after that, it works again.
My conclusion is that the Arduino IDE is connecting to the Leonardo in a slightly different way to my basic prog, which is critical to the Leonardo, but not to other Arduinos. I wonder if is using the RTS/DTR lines in some way?
I'm using the following code for testing:
// Flash rapidly 20x on reset
// Flash in short pulses to indicate a serial connection
// Flash slowly when serial connection is not present
const byte LED = 13;
void setup()
{
pinMode(LED, OUTPUT);
// Flash quickly to indicate a reset
for (byte a = 20; a > 0; a--)
{
digitalWrite(LED, HIGH); delay(50);
digitalWrite(LED, LOW); delay(50);
}
Serial.begin(9600);
}
void loop()
{
//Serial.println("Blink1");
if (Serial)
{
// Short pulses indicate serial connection present:
digitalWrite(LED, HIGH); delay(50);
digitalWrite(LED, LOW); delay(450);
}
else
{
// Slow flash indicates no serial connection:
digitalWrite(LED, HIGH); delay(1000);
digitalWrite(LED, LOW); delay(1000);
}
}
Any help appreciated.