-1

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?

  • 1
    Please post your code. Please define "not working". What device have you connected? – Nick Gammon Nov 6 '15 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. – Dodo Nov 6 '15 at 6:27
  • What if you try SoftwareSerial serial(0,1);? – frarugi87 Nov 6 '15 at 9:48
  • 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. – James Waldby - jwpat7 Nov 6 '15 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?). – Dodo Nov 6 '15 at 18:34
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.