Hi,
I am using TX2 and RX2 in serial communication.
But after setting pin 16 to LOW , I can't reuse it in serial communication.
Here is my code for arduino due:
if (inputString1.equalsIgnoreCase("BREAK")) {
Serial2.end();
pinMode(16,OUTPUT);
digitalWrite(16,LOW);
delay(350);
Serial2.begin(baudeADP);
}
void setup() {
Serial.begin(9600);
Serial2.begin(4800);
}
void loop() {
// read from port 0, send to port 2:
if (Serial.available()) {
int inByte = Serial.read();
if(inByte == 'B')
{
pinMode(16,OUTPUT); // using pin 16 as an output
digitalWrite(16,HIGH);
delay(350);
Serial2.begin(4800); // using pin 16 again on serial communication
}
Serial2.write(inByte);
}
// read from port 2, send to port 0:
if (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
}
RX2 (pin 17) is wired with TX2 (pin16).
This code allow the arduino to recieve bytes on port 0 and send it to port 2.
Recieving 'B', pin 16 is switched to pinmode and returning again to Serial mode.
Its works perfectly on mega board:
With Serial Monitor:
hi -> hi
B -> B
hi -> hi
But problems come with the Due board:
With Serial Monitor:
hi -> hi
B ->
hi ->