Writing to Console with Arduino

3 Просмотры
Размещено
Buy access to all our courses now - For a limited time just 19USD per month with a 30 day satisfaction or your money back "No Hassle" guarantee! https://bit.ly/2OUUmCI

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

WRITING TO CONSOLE WITH ARDUINO | SOLVED
How the heck do you write and print text to the Arduino console, you know, that black output section at the bottom of the Arduino IDE? Is it even possible?! Have you been reading about Serial.print(), but it just isn’t making any sense at all?

You just want to be able to view the state of some variables, I mean what gives! This should be easy!

Arduino console with how do I print here bubble pointing to black area

LESSON OUTLINE:
In this lesson…

You will learn exactly how to print and write text to the Arduino console
Spoiler Alert – you may have been looking for love in all the wrong places – it’s not actually the console! You’ll write to the Serial Monitor.

You will learn the two REQUIRED functions to write text on the Arduino console Serial Monitor
As a bonus, you’ll also learn how to avoid two of the most common printing gotchas that always trip people up when they are getting started with Arduino.
ARDUINO CONSOLE SERIAL MONITOR
When you open up the Arduino IDE, and you see the black section at the bottom that takes up 20% of the window, you might have assumed (very appropriately) that this was a console where you can print out text and values.

Similar to what you’ll find in other IDEs like Visual Studio, Eclipse, or whatever you’re familiar with. Trust me – just about everybody new to Arduino IDE thinks the exact same thing – so you are not alone!

But in fact, this IS NOT one of the functions of the Arduino console. Its only purpose is to display error messages and status information about your Arduino.

If you want to see text output like you think of on a console, you need to use the Serial Monitor Window. The Serial Monitor window can be found under Tools - Serial Monitor.

Arduino tools menu showing Serial Monitor shortcut for printing to console

The shortcut key to open the serial monitor window is CTRL + SHIFT + M (Or CMD + SHIFT + M on a macOS). This Serial Monitor window is where you see the text that you are writing and printing – not a console.

But how do you actually print, display, and write text this Arduino Console (which we now know is called the Serial Monitor)?

WRITING TO CONSOLE SERIAL MONITOR
It’s really easy! There are TWO functions you must invoke from the Arduino Serial library (which happens to be built into the Arduino IDE)

The first function is Serial.begin(baud rate). This function will go inside the curly braces of void setup. That’s because this function only needs to run once.

Serial.begin() is what establishes serial communication between your Arduino board and your computer.

The value that goes inside the parentheses is called the baud rate, and a very common baud rate to use is 9600 – it’s simply the speed at which your Arduino board and you Computer are agreeing to communicate at.

The second function you’ll need is Serial.print(). Serial print is what will actually send the value to the serial monitor window. You can print text strings, like “Hello World”, or values like integers, floats, or whatever. So the 2 functions you must have are Serial.begin() and Serial.print().

Sometimes you can get a little tripped up writing to the Arduino Console Serial Monitor though, so make sure to observe check out the following common gotchas…

ARDUINO SERIAL MONITOR GOTCHAS
But there are a couple gotchas that might really trip you up when writing text the console Serial Monitor.

GOTCHA 1: BAUD RATE DOES NOT MATCH
Sometimes you see what looks like Egyptian hieroglyphics printed on the Arduino Console Serial Monitor. This happens when the number you put into the Serial.begin() function does not match the baud rate set in the serial monitor window drop down.

arrow showing Baud rate in Serial.print and baud rate in Serial monitor window, must match to print to console correctly

If these two baud rates don’t match, you get a bunch of garbled stuff printed to the Arduino console Serial Monitor window. A common baud rate is 9600, as is 115200. For most applications, it doesn’t matter that much, as long as the value matches in the code and the Serial Monitor window setting.

CONTINUED...
https://bit.ly/3cfduEF

***About Us:***
This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.

***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***
Категория
Ардуино
Комментариев нет.