UART serial between defined ports

Hi, I would like to use the UART serial communication features first just to try it out between pins 0 and 1 (defauñt rx and tx). I would like to put some data manually to the tx pin and send it immadiately to the rx anddicho process the received data. I hace found serial examples for mobitoring and writing, thede data for the serial monir but not for my question. How can I define to make it between the ports I want and after print out the sent data with the start,stop and parity bits? Thank you very much.

How can I define to make it between the ports I want and after print out the sent data with the start,stop and parity bits?

Which Arduino are you using? Where the data comes from, or goes to, does not matter to the Arduino. If you have a Mega, you can use Serial to send data, and connect pins 0 and 1 to 18 and 19 and use Serial1 to read the data. Or use Serial1 to send and Serial3 to read, and Serial to debug.

It is best to avoid pins 0 and 1 because these hardware serial pins are handy for debugging using the serial monitor.

You have not told us what Arduino you are using, but it might be best to use one of the software serial solutions (there are a few) so that you may use other pins. Alternatively, if you have a Mega, you may want to use Serial1, Serial2, or Serial3.

It is hardly worthwhile to print out the start and stop bits because they never change. If you want to see start and stop bits, a logic analyzer may be the way to go.

Parity bits have me stumped. They can be seen on a logic analyzer, or they may be computed, but if there is a way to see them in the hardware I do not know what it is.

I suppose you could hack the software serial library for start bits, stop bits, and parity bits if you REALLY need it.

Sorry, I am using Arduino Leonardo.

sylarhero: I would like to put some data manually to the tx pin and send it immadiately to the rx anddicho process the received data.

I don't understand that.

You say you have a Leonardo. On the Leonardo the pins 0 and 1 are for Serial1. And Serial is used for communication with the PC over the USB cable.

Do you mean that you want the Leonardo to receive data using Serial1 and then send the data to the Arduino Serial Monitor using Serial? That is perfectly possible.

But if you are doing that you need to tell us what you are connecting to Serial1 (pins 0 and 1) to send data to the Leonardo.

...R Serial Input Basics

sylarhero: How can I define to make it between the ports I want and after print out the sent data with the start,stop and parity bits? Thank you very much.

Wires. You use wires to connect pins together.

If you want to print parity bits, calculate the parity for yourself and print that.

It sounds more like you need to buy a logic analyzer. USB-based ones are very cheap.

At the and I will need to send data with an LED and I want to use the serial communication functions because arduino makes the data framing by itself so I won't have to worry about it. The idea is: TX is an LED, RX is a photodiode, between these elements I want UART serial communication, but for now I just wired together the 0 and 1 pins (as transmitter and receiver) in order to play a little bit with the functions and see how it works but I couldn't make it work, that's why I am asking.

sylarhero: The idea is: TX is an LED, RX is a photodiode, between these elements I want UART serial communication,

Have a look at the Serial IR Thread

Then answer my questions in Reply #4

...R

Sorry I misunderstood a little bit my task.

So what I want is the following: I have the Leonardo connected to the PC via USB and later I would like to send data from Matlab to the Arduino, if I am not wrong between the Arduino and the PC there is serial communication on the pins 0 and 1.

The data I send from the PC I would like to send it with an LED connected to one of the pins and I want to receive it with a photodiode which will be connected to the same Arduino on a different pin. Between the LED and photodiode I would like to have the same serial communication.

For now I just wired together 2 pins to see if it is possible to use or define somehow another serial channel apart of the 0/1 pins between the Arduino and the PC.

So my question is: is it possible somehow to define one pin as receiver and another as transmitter and have UART between them? For now I'd just like to send one char or something just to see how it works.

You do realize that you will probably need more than just an LED and a photodiode? Possibly transistors, resistors, and amplifiers?

I think that you have misunderstood the connections and the purpose of a UART.

Hardware UARTs on the Leonardo and the Mega have predefined pins whose numbers you cannot change. Software UARTs allow you to choose almost any pin numbers but often cannot handle transmitting and receiving simultaneously.

Good Luck with your changing specifications.

sylarhero: if I am not wrong between the Arduino and the PC there is serial communication on the pins 0 and 1.

You are not not wrong. The USB communication between the PC and Leonardo doesn't appear on any Arduino pin. Serial1 is the hardware serial for pins 0 and 1 and it's totally separate. It means you don't need to mess around with SoftwareSerial for this application.

Just flashing an LED on and off is difficult to detect with a photodiode. You will not get much more than 1-2 metres range, even with good analog processing at each end. You should use a scheme like an IR remote where the on/off signal is imposed on a 38KHz carrier frequency. You can get simple modules which do all of this for you so they can be connected directly to the Arduino pins. Then you can get many metres range, even in daylight.

Okay thank you it is good to know. I already have the LED circuit with resistors and transistor and the receiver circuit with the photodiode and amplifier as well, I know it is working only in short distances but this is what I have to do (it is a university project).

So that means I can connect the LED circuit to the 1 pin (which is tx) and the photodiode to the 0 pin (which is rx) ?

sylarhero:
So that means I can connect the LED circuit to the 1 pin (which is tx) and the photodiode to the 0 pin (which is rx) ?

That will not interfere with the communication between the Leonardo and the PC.

However I do not believe it will be a useful test of anything. I assume you longer term plan is to use light to send data from the Leonardo to something else. The normal way that IR LEDs are used for data transmission is to modulate a 38kHz carrier wave - as in the link I gave you. By using a carrier frequency it is much easier for the system to ignore noise.

…R

sylarhero: So that means I can connect the LED circuit to the 1 pin (which is tx) and the photodiode to the 0 pin (which is rx) ?

Is there a current limiting resistor on the LED circuit?

What about data polarity? Does a mark turn on the LED or does a space turn it on?