Questions tagged [serial]

Serial communication is the standard USB connection between the Arduino and a computer with a standard USB A to B cable or through the TX/RX pins using a USB to serial converter. It can also refer to the serial library.

Serial communication is the standard USB connection between the Arduino and a computer with a standard USB A to B cable or through the TX/RX pins using a USB to serial converter. It can also refer to the serial library.

[Serial is] used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output. You can use the Arduino environment's built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().

Excerpt from the Arduino Page about Serial.

Most boards have only one serial port. Exceptions:

  • Leonardo has two: one connected to USB and the other connected to pins 0 and 1 for connection to UART items.
  • The Mega/Mega2560 has 4 serial ports, one connected to a UART to USB converter.
  • The DUE also has 4 serial ports, one connected to a UART to USB converter.

The serial is outputted through UART. Then, for the primary serial connection on pins 0 and 1*, the data goes to a UART to serial chip** and then transferred to/from the computer.

*On some boards, such as the Leonardo, it doesn't use the pins 0 and 1.

**On some boards, such as the Leonardo, there is no USB chip because it is built into the chip itself, or it has no USB connection.


The serial library:

Arduino includes a library for inferencing with the serial ports. Here is some example code:

void setup() {
  // open the serial port at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hello World!");
  delay(1000);
}
2147 questions
48
votes
21 answers

Serial data plotting programs

I need to plot serial data from Arduino. I require support for: Various data formats (e.g. signed, unsigned, 8 bits, 16 bits); Plots several data on the same axes; Exports / Imports file data. As plotting serial data from Arduino is a common need,…
akellyirl
  • 2,146
  • 1
  • 15
  • 19
45
votes
5 answers

What is the difference between Serial.write and Serial.print? And when are they used?

What is the difference between Serial.write and Serial.print? And when are they used? Both have been used to print on serial monitor, what are their actual differences?
shadab
  • 569
  • 1
  • 5
  • 7
43
votes
5 answers

Serial.begin(): Why not always use 28800?

In a lot of the sample code online people add the line Serial.begin(9600) in the setup block. When I look up what Serial.begin() is on the official documentation, it says that it controls the bit per second data transfer. So the obvious question is,…
Fraïssé
  • 895
  • 5
  • 13
  • 16
32
votes
2 answers

How does the Arduino handle serial buffer overflow?

How does the Arduino handle serial buffer overflow? Does it throw away the newest incoming data or the oldest? How many bytes can the buffer hold?
HighLife
23
votes
4 answers

Communication Protocol Best Practices and Patterns

Every time I design a serial protocol to be used between two arduinos, I feel a bit like I'm reinventing a wheel. I wonder if there are any best practices or patterns people follow. This question is less about the actual code, but more about the…
Jeremy Gillick
  • 481
  • 1
  • 3
  • 8
14
votes
3 answers

Serial data showing up weird

I have a simple sketch that prints out "Hello World" to the serial, but I'm getting a bunch of gibberish instead. void setup() { Serial.begin(9600); } void loop() { Serial.println("Hello World"); delay(1000); } Why isn't it printing…
sachleen
  • 7,525
  • 4
  • 39
  • 57
14
votes
6 answers

Sending Large Amounts of Serial Data

So in the fields of robotics sometimes you need multiple boards and or computers linked together to share information or save statistical data. Currently I need to send a few different variables over a serial connection and was wondering what was…
Steven10172
  • 511
  • 2
  • 4
  • 11
11
votes
1 answer

Use Unix terminal instead of the Monitor on Arduino IDE

I want to make a shell or C script that interprets the Arduino serial input to run commands. For that, I will need to make that script be the Serial monitor for my arduino. Another reason I want to use scripts or the command line as a Serial I/O is…
John K
  • 225
  • 1
  • 2
  • 9
10
votes
1 answer

What does the line "while (! Serial);" do in an Arduino program?

I'm new to Arduino, and I am trying a couple of tutorials. What does this line do in a program? while (! Serial);
Brendan
9
votes
3 answers

Can I make the Arduino ignore serial print

I like having serial communication for debugging and testing purposes but after a while it takes away too much speed from the sketch. Is it possible to have the Arduino ignore serial.print and serial.println throughout my code, without turning it…
Kevin Kroon
  • 93
  • 1
  • 1
  • 4
8
votes
4 answers

For which type of serial communication is Arduino Severino designed?

Arduino has become quite costly where I come from (2/3 of the price of Raspberry PI) so I have created an Arduino Severino clone. I had used the device with the RS-232 Usb-Serial converter. But after a (long) while, the device stopped working. My…
Tomáš Zato
  • 282
  • 5
  • 14
7
votes
4 answers

Is it possible to connect many arduino uno in one pc?

We have many Arduinos and we will be putting each of them in a cubicle. All of them are connected to only one PC. The PC will stand as a server were you can control your Arduino there.
Ashley Templado
7
votes
5 answers

Clear existing array when getting new serial command

I'm starting to build my first Arduino project but I'm running into some problems with serial communication. I get serial data from the console and store it in a char array called "data". Then, when I send a new console message to the Arduino, I…
squeck
  • 73
  • 1
  • 1
  • 3
6
votes
5 answers

Can I have two separated serial monitor for the same arduino board connected to PC?

I'd like to split serial communication into the two channels: 1) debug info, 2) application data. There's only one Serial object to use. However, maybe, there is an alternative way to print data separately, is there? P.S. I use Nano and UNO.
zhekaus
  • 439
  • 2
  • 6
  • 16
6
votes
1 answer

ATMega32u4 (Leonardo) Serial Baud Rate

Does anyone know what the actual baud rate that the CDC Based virtual serial port on the Leonardo runs at is? Serial::being() for the CDC version is just empty, so it's not setting a baud rate anywhere. Basically, I'm debating between using the 32u4…
Adam Haile
  • 599
  • 2
  • 7
  • 14
1
2 3
13 14