The example code I found on the internet that works when I use Serial but not when using Serial1 , Serial2 or Serial3.
int ledPin = 13; // use the built in LED on pin 13 of the Uno
int state = 0;
int flag = 0; // make sure that you return the state only once
void setup() {
// sets the pins as outputs:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); // Default connection rate for my BT module
Serial1.begin(9600); // Default connection rate for my BT module
}
void loop() {
//if some data is sent, read it and save it in the state variable
if (Serial1.available() > 0) {
state = Serial1.read();
flag = 0;
}
// if the state is 0 the led will turn off
if (state == '0') {
digitalWrite(ledPin, LOW);
if (flag == 0) {
Serial1.println("LED: off");
flag = 1;
}
}
// if the state is 1 the led will turn on
else if (state == '1') {
digitalWrite(ledPin, HIGH);
if (flag == 0) {
Serial1.println("LED: on");
flag = 1;
}
}
}
Do you guys have any idea how come this program isn't working while I'm using serial 1, 2 or 3 but it does when using the default?
The default port is used for the Touch Screen which I'm also going to be using (but not in this example)
I just came to the conclusion that my (clone) board has TX1 on 19 and RX1 on 18
An official board has TX1 on 18 and RX1 on 19. That might be the reason why connecting my RXD from bluetooth to pin 18 might work (since this is acutally TX1 instead of RX1 printed on the board)
Am I correct that my board might have misprinted these values? Is it always 18 for TX and 19 for RX?
Ah, I got a clone from "DCcEle" with these marking problems... Also Rx and Tx LEDs are swapped, and some other stupid label mistakes, no "reset-en" track... Might explain why they sell it for less than 10€
I believe the mix up is on the HC-06 module. I have an HC-06 and I have to do the same thing: tx to tx and rx to rx and it has worked fine for me no problem. I also have read this a number of other places but I have never seen an actual explanation. I think you should be fine.