0

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?

asked Nov 6, 2015 at 4:45
12
  • 2
    Please post your code. Please define "not working". What device have you connected? Commented Nov 6, 2015 at 6:18
  • @NickGammon This is interfacing with a CASIO fx-9750GII. I can receive the request byte from the calculator using SoftwareSerial but not with Serial. If the Arduino receives any data it makes a sound. Commented Nov 6, 2015 at 6:27
  • What if you try SoftwareSerial serial(0,1);? Commented Nov 6, 2015 at 9:48
  • 1
    38000 bps is not a standard rate and hardware at one end or the other might not support it, while software might not care. You still haven't said what "doesn't work" means, but if it means garbled characters, use a standard rate, eg 38400 bps. Commented Nov 6, 2015 at 15:18
  • @jwpat7 'Doesn't work' means no byte is received. The external device supports 38000 bps only, and the Arduino can use it on the hardware serial port (as tested connected to a computer with a Processing sketch). The fact that it is simultaneously connected to a computer through the USB port doesn't seem to be an issue, because it exhibits the same behaviour powered by a phone charger (unless the charger also interferes with something?). Commented Nov 6, 2015 at 18:34

2 Answers 2

1

There may be several reasons

  1. Be sure uC pin connect pin header
  2. In setup part, you write Serial.begin(xxxx);
  3. After serial begin, don't change this pins IO features(Input, output)

Please check that after if not solve, please share code

answered Nov 6, 2015 at 5:40
5
  • Can you explain what you mean in 1? Commented Nov 6, 2015 at 6:03
  • Also explain what you mean by (3). Commented Nov 6, 2015 at 6:19
  • I think that means don't use pinMode on pins 0 or 1. Commented Nov 6, 2015 at 6:28
  • 2
    I 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. Commented Nov 6, 2015 at 11:00
  • 1
    In that case: check, check and check... I think. Commented Nov 6, 2015 at 18:37
1

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.

answered Jan 10, 2020 at 6:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.