Difference between hardware and software serial

Hello.

I have a question: I connected to my arduino board an external device by using the built-in softwareserial library. Everything works fine.

Now, I'd like to move this and get rid of software serial and use the built in USB/serial connector to connect this device. By using this, I'm not able to establish the the connection with the device. By debugging it looks I'm sending out data, but the device does not reply to the arduino.

Now, my question is: which are the difference between the software and hardware serial in terms of settings? Do you have any suggestion in how to handle this?

Thanks a lot for your help.

Cips

ceci0: using the built-in softwareserial library. Everything works fine.

Now, I'd like to move this and get rid of software serial and use the built in USB/serial connector to connect this device.

Since it used to work fine, I assume you connected to the external device by wires from the declared software serial pins. You should therefore get a result by using the same wires from the declared hardware serial pins D0,D1.

Needless to say, the code will need to be modified by replacing all the software serial commands with Serial commands.

Usually they are interchangeable - what works on SoftwareSerial should work on HardwareSerial.

Without seeing your program it is impossible to say more.

...R

Thanks for your replies

@Nick_Pyner: Yes, I changed the softwareserial command with Serial

I'm not using D0,D1, but the usb connector itself, with a USB cable. I also tried to connect this USB to a PC and monitor the USB port: I see the command I send from arduino coming in. Now, by typing a doubt came in my mind....should I care about the TX/RX wires, may be I should switch them? I don't think so, since on the PC it works...

@Robin2 the code is quite simple, just sending some bytes and expecting a reply, but I don't do anything special

Thanks to both

ceci0: I'm not using D0,D1,

Possibly why it doesn't work. I assume you did not use the USB cable with software serial.

Yes, I was using a direct wiring. But with the cable, shouldn't be the same?

(for uno/mega) The TX and RX lines of the hardware serial are connected to pins 0 and 1 (for most Arduino boards, at least). These are connected (through a resistor) to the TX and RX lines of an on-board USB-serial adapter. The USB D+ and D- lines from that are connected to the USB port.

(for leo/micro) The USB is connected to different pins on the microcontroller than the serial pins. The hardware serial is called Serial1 ("Serial" is a virtual USB serial port, it can only be used to act like USB-serial adapter to a USB host)

The only things that can be plugged into the USB port and be expected to work are a USB host device like a computer (which will see a serial port), or +5v power (ex, from USB phone charger or something).

ceci0: Yes, I was using a direct wiring. But with the cable, shouldn't be the same?

USB is not the same as serial port.

ceci0:
@Robin2
the code is quite simple,

I can’t see it.

…R

You spoke of debugging printing. You do know you can't do that at the same time as talking to your device using the same data stream?

Hello.

In order to debug, I attached a device to the other end of the USB cable coming from the arduino, and I was able to see the bytes I was writing coming in.

USB is not the same as serial port.

Do you think that there's a way to convert this signals as the "software serial" ones?

Thanks,

ceci0: Do you think that there's a way to convert this signals as the "software serial" ones?

Thanks,

Yep, connect the wires that initially went to your SW serial pins to the HW serial pins on the Arduino (D0 (RX) and D1 (TX)).

Be aware that whatever you transmit from the Arduino goes to both the USB and the device. Also be aware that reception from USB and device might interfere with each other if they occur at the same time.

Thanks sterretje

Yep, connect the wires that initially went to your SW serial pins to the HW serial pins on the Arduino (D0 (RX) and D1 (TX)).

OK, this is clear. My question was more if I can use the USB cable and port (because this is a must in waht I’m trying to do) and convert in some way the signal to get it working.

Thanks again

The signals are incompatible. There is no rx an tx in USB.

Only if your device can act as a USB host (meaning it has the same connectors as e.g. a PC) and has the driver, it will work directly.

Else you need something that can act as a host at the one side and TTL serial at the other side.

Thanks sterretje