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);
}
2167 questions
71
votes
12 answers

How do I split an incoming string?

I am sending a list of servo positions via the serial connection to the arduino in the following format 1:90&2:80&3:180 Which would be parsed as: servoId : Position & servoId : Position & servoId : Position How would I split these values up, and…
ValrikRobot
  • 843
  • 2
  • 8
  • 6
55
votes
12 answers

How do I print multiple variables in a string?

Say I have some variables that I want to print out to the terminal, what's the easiest way to print them in a string? Currently I do something like this: Serial.print("Var 1:");Serial.println(var1); Serial.print(" Var…
sachleen
  • 7,565
  • 5
  • 40
  • 57
50
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
  • 619
  • 1
  • 6
  • 7
49
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,156
  • 1
  • 15
  • 19
44
votes
4 answers

Why does starting the serial monitor restart the sketch?

If I upload any sketch that sends serial data, I immediately see the TX/RX LEDs flash once the sketch is uploaded. If I then start the serial monitor, the sketch appears to restart. A bare minimum sketch that shows this behaviour: void setup() …
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
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é
  • 905
  • 5
  • 13
  • 16
41
votes
10 answers

Arduino Nano uploading gives error: avrdude: stk500_recv(): programmer is not responding

I have a Arduino Nano (Sainsmart) that I'm trying to upload a sketch to. Under the Arduino IDE, the device selected was Arduino Nano w/ ATmega328. However uploading the sketch gives me the error avrdude: stk500_recv(): programmer is not…
Nyxynyx
  • 1,419
  • 4
  • 23
  • 25
33
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
30
votes
2 answers

Arduino as USB HID

Is it possible to build a HID device (like a keyboard) using an Arduino uno? At the time being, I have button inputs on the Arduino giving outputs on the serial line. So, how can I transform my current firmware into something that can behave like a…
Stuyvenstein
  • 435
  • 1
  • 5
  • 6
30
votes
3 answers

What is Serial.begin(9600)?

I know that this is to initialize something: Serial.begin(9600); But I want to know what it really means?
shajib0o
  • 551
  • 2
  • 6
  • 9
23
votes
2 answers

Why can't I upload a sketch while other components/devices are connected to my Uno?

I wanted to make a fairly simple circuit which would flash a series of LEDs in sequence, using my Arduino Uno (more specifically, a SainSmart clone). I wrote my sketch and it compiled fine. After that, I connected 8 LEDS+resistors to pins 0 through…
Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
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
21
votes
1 answer

How does serial communications work on the Arduino?

With reference to the Arduino Uno, Mega2560, Leonardo and similar boards: How does serial communications work? How fast is serial? How do I connect between a sender and receiver? Please note: This is intended as a reference question.
Nick Gammon
  • 38,901
  • 13
  • 69
  • 125
18
votes
7 answers

How do I know the sampling frequency?

I am beginning to get a bit confused about sampling rates and baudrates etc. I have this Arduino code: #include extern volatile unsigned long timer0_overflow_count; float fanalog0; int analog0; unsigned long time; byte…
hawkar
  • 553
  • 2
  • 6
  • 12
18
votes
4 answers

How to get weight data from glass electronic bathroom scale sensors?

I am doing a small project with a bathroom scale but I run into some problems. I am using an Arduino Uno V3, HX711 module amp and a scale. Scale: HX711 amplifier: I disassembled the scale to get to sensor wires and I am a bit confused. These…
silent_bob
  • 193
  • 1
  • 2
  • 7
1
2 3
99 100