On my Uno-equivalent Arduino, a SoftwareSerial connection (on RX, TX = 8, 9) is working*, while a hardware serial connection to the same device, set up in the same way (but on pins RX, TX = 0, 1) is not working. Why is the hardware serial setup not working?
*By working I mean receiving a byte from the external device
Edit: as a simple example:
void setup() {
Serial.begin(38000);
pinMode(7, OUTPUT);
}
void draw() {
if (Serial.available() > 0) {
Serial.read();
tone(7, 440, 1000);
}
}
The above, using Serial
, doesn't work, whereas
#include <SoftwareSerial.h>
SoftwareSerial serial(8, 9);
void setup() {
serial.begin(38000);
pinMode(7, OUTPUT);
}
void draw() {
if (serial.available() > 0) {
serial.read();
tone(7, 440, 1000);
}
}
does work.
I don't know if this helps, but connecting RX/TX through an LED to ground gave me the following, using Serial on (0, 1) and SoftwareSerial on (8, 9):
Serial
RX: bright
TX: bright
SoftwareSerial
RX: dim (but still lit)
TX: bright
Is the fact that RX is dim using SoftwareSerial significant?
2 Answers 2
There may be several reasons
- Be sure uC pin connect pin header
- In setup part, you write Serial.begin(xxxx);
- After serial begin, don't change this pins IO features(Input, output)
Please check that after if not solve, please share code
-
Can you explain what you mean in 1?Dodo– Dodo2015年11月06日 06:03:02 +00:00Commented Nov 6, 2015 at 6:03
-
Also explain what you mean by (3).2015年11月06日 06:19:12 +00:00Commented Nov 6, 2015 at 6:19
-
I think that means don't use pinMode on pins 0 or 1.Dodo– Dodo2015年11月06日 06:28:03 +00:00Commented Nov 6, 2015 at 6:28
-
2I think a translation might be: 1. Make sure you connect to the right pins. 2. Be sure to use Serial.begin(baud). 3. Never use pinMode() on pins 0 and 1 when you are using Serial.Majenko– Majenko2015年11月06日 11:00:18 +00:00Commented Nov 6, 2015 at 11:00
-
1In that case: check, check and check... I think.Dodo– Dodo2015年11月06日 18:37:22 +00:00Commented Nov 6, 2015 at 18:37
I would check if the arduino you are using supports your selected baudrate.
38000 is not a standard rate and it could be, that the hardware is not able to work at it with the needed precision. The software serial (and most USB serial dongles) could use any baudrate, but not the limited hardware within most arduinos.
SoftwareSerial serial(0,1);
?