One of the staples of CircuitPython (and programming in general!) is something called a "print statement". This is a line you include in your code that causes your code to output text. A print statement in CircuitPython (and Python) looks like this:
This line in your code.py would result in:
However, these print statements need somewhere to display. That's where the serial console comes in!
The serial console receives output from your CircuitPython board sent over USB and displays it so you can see it. This is necessary when you've included a print statement in your code and you'd like to see what you printed. It is also helpful for troubleshooting errors, because your board will send errors and the serial console will display those too.
The serial console requires an editor that has a built in terminal, or a separate terminal program. A terminal is a program that gives you a text-based interface to perform various tasks.
If so, good news! The serial console is built into Mu and will autodetect your board making using the serial console really really easy.
First, make sure your CircuitPython board is plugged in.
If you open Mu without a board plugged in, you may encounter the error seen here, letting you know no CircuitPython board was found and indicating where your code will be stored until you plug in a board.
Once you've opened Mu with your board plugged in, look for the Serial button in the button bar and click it.
The Mu window will split in two, horizontally, and display the serial console at the bottom.
If you're on Linux, and are seeing multi-second delays connecting to the serial console, or are seeing "AT" and other gibberish when you connect, then the
modemmanager service might be interfering. Just remove it; it doesn't have much use unless you're still using dial-up modems.
modemmanager, type the following command at a shell:
sudo apt purge modemmanager
On Linux, if you see an error box something like the one below when you press the Serial button, you need to add yourself to a user group to have permission to connect to the serial console.
On Ubuntu and Debian, add yourself to the dialout group by doing:
sudo adduser $USER dialout
After running the command above, reboot your machine to gain access to the group. On other Linux distributions, the group you need may be different. See the Advanced Serial Console on Linux for details on how to add yourself to the right group.
If you're not using Mu to edit, are using or if for some reason you are not a fan of its built in serial console, you can run the serial console from a separate program.
Windows requires you to download a terminal program. Check out the Advanced Serial Console on Windows page for more details.
MacOS has Terminal built in, though there are other options available for download. Check the Advanced Serial Console on Mac page for more details.
Linux has a terminal program built in, though other options are available for download. Check the Advanced Serial Console on Linux page for more details.
Once connected, you'll see something like the following.