What is Serial.begin(9600)?

Описание к видео What is Serial.begin(9600)?

🤩 FREE Arduino Crash Course 👇👇
https://bit.ly/get_Arduino_skills

Want to learn more? Check out our courses!
https://bit.ly/2QcIL2u

**Get the code, transcript, challenges, etc for this lesson on our website**
https://bit.ly/3uTMjFK

We designed this circuit board for beginners!
Kit-On-A-Shield: https://amzn.to/3lfWClU

SHOP OUR FAVORITE STUFF! (affiliate links)
---------------------------------------------------

We use Rev Captions for our subtitles
https://bit.ly/39trLeB


Arduino UNO R3:
Amazon: https://amzn.to/37eP4ra
Newegg: https://bit.ly/3fahas8

Budget Arduino Kits:
Amazon:https://amzn.to/3C0VqsH
Newegg:https://bit.ly/3j4tISX

Multimeter Options:
Amazon: https://amzn.to/3rRo3E0
Newegg: https://bit.ly/3rJoekA

Helping Hands:
Amazon: https://amzn.to/3C8IYXZ
Newegg: https://bit.ly/3fb03X1

Soldering Stations:
Amazon: https://amzn.to/2VawmP4
Newegg: https://bit.ly/3BZ6oio

AFFILIATES & REFERRALS
---------------------------------------------------
►Audible Plus Free trial: https://amzn.to/3j5IGrV

►Join Honey- Save Money https://bit.ly/3xmj7rH
►Download Glasswire for Free:https://bit.ly/3iv1fql

FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook:   / programmingelectronicsacademy  
Twitter:   / progelecacademy  
Website: https://www.programmingelectronics.com/

WHAT IS SERIAL.BEGIN(9600)?
Are you wondering what Serial.begin(9600) does?

You’ve probably seen it in most of the Arduino programs you’ve looked at – but what’s it there for?! Do you even need to use Serial.begin()?

What if you change the number 9600? I mean, what’s 9600 even mean?!

In this lesson you will learn exactly what Serial.begin does, when you NEED to use it, and what the heck the 9600 means.

WHAT DOES SERIAL.BEGIN(9600) DO?
Let’s get straight to this…

Serial.begin() establishes serial communication between your Arduino board and another device. The most common use of serial communication you will establish is between your Arduino and your computer via a USB cable – or should I say a Universal Serial Bus cable.

When you have established serial communication between two devices, it allows the two devices to communicate using a serial protocol.

So let’s answer a couple practical questions…

WHEN DO I NEED TO USE SERIAL.BEGIN()?
The most common reason to use serial.begin() is when you want to output some information from your Arduino to your computer screen.

That is, you want to print some text out.

The function used to display text on your computer screen from your Arduino board is the serial.print() function.

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.print("Look Ma, I’m in the phone book!");
}
The text that gets printed out shows up on the Serial Monitor window – which can be opened from the menu bar under Tools / Serial Monitor. Or with the shortcut key CTRL + SHIFT + M (on PC) or Command + Shift + M (MacOs).

There are other times you’ll use serial.begin(), for example, maybe you have an application running on your computer that will be expecting data from your Arduino over a serial port. In these cases, you’ll also need Serial.begin().

WHERE DOES SERIAL.BEGIN() GO IN THE ARDUINO SKETCH?
99% of the time, you’ll be putting the Serial.begin() function inside of the setup() function. As you may know, setup() only runs once, and since you’ll only need to establish the Serial Communication one time – it makes sense to have it there.

WHAT’S WITH THE NUMBER 9600?
That number is called the baud rate. Probably the most important practical thing you need to know, is that for serial communication to work the baud rate in Serial.begin() and the baud rate set on the receiving device need to match.

If you are using the Arduino IDE Serial Monitor window to read the information from your Arduino, then you can use the baud rate drop down to set the baud rate.

Remember! If these two values don’t match – then anything you try to send over serial will not work right.

It’s like, as a kid, did you and a friend ever come up with a long distance communication protocol?

Like, 2 hoots meant, “Is anyone at the fort?”, and the appropriate response was two hoots back?

But if you both didn’t agree on that protocol beforehand, and your friend was cawing, instead of hooting, then you were like, what is he trying to say? Same thing with the baud rate – remember these have to match!

Комментарии

Информация по комментариям в разработке