Serial Console (REPL)

CircuitPython sends the output of the .py files it runs to the connected computer over USB serial. So, to view the output of your code from print statements and any errors that occur you'll need to connect to the serial console.

Also, because CircuitPython is a variant of Python, it too has a read-evaluate-print-loop or  'REPL' for short. The REPL lets you run individual commands and load up code interactively and is therefore great for testing a new idea. However, the code typed into the REPL isn't saved anywhere so make sure and save it elsewhere (like for example.)


Serial Drivers (for Windows 7)

If you are using Windows 7 you will need to install drivers. Click below to download the driver package and install it! This is not necessary for Mac, Linux or Windows 10+.

Determine Your Serial Port

Next you must determine the name of the serial port for your board.  It's easiest to look at the serial ports with the board disconnected (on Windows check Device Manager under the Ports (COM/LPT) node

It will be named something like Adafruit Circuit Playground, Adafruit Gemma M0, Adafruit Trinket M0 or Adafruit Feather M0

Install Serial Port Terminal Software

On Windows you'll want to use a tool like PuTTY to connect to the serial port.  Download and run PuTTY, then configure it to use a serial connection to the board's COM port at 115200 baud similar to as shown below:

After clicking Open you should see a new window pop up with the current output from the running code. If no code is running, it may be blank so hit Ctrl - C to get to the REPL prompt.

Mac OSX and Linux

Connecting to the serial terminal on is more straightforward than on Windows. Neither OS requires additional drivers.

First open a terminal program. On Mac OSX, Terminal comes installed and iTerm2 can be downloaded. On Linux there are a variety available such as gnome-terminal (called Terminal) and Konsole on KDE.

Now before plugging in the board, type ls /dev/tty.* to view existing serial connections.

Next, plug in the board. There should be one new serial connection that is for your board. Typically on Mac OSX its something like /dev/tty.usbmodem* and on Linux its /dev/ttyACM*.

Now that we know the device name, the screen command can be used to connect to the serial port. Its installed on Mac OSX by default but Linux users may need to install it using their package manager. Run the following command to connect at 115200 baud:

screen /dev/tty.board_name 115200

Where /dev/tty.board_name is the name of the board's serial port.

When you're done using screen most versions of it allow you to exit by pressing Ctrl-a then k then y or pressing Ctrl-a then typing :quit and pressing enter.

Using the REPL

After you're connected to the serial REPL try pressing enter to confirm you see the >>> prompt.  You can also type help() and press enter on most boards to see basic usage information.

If you can't get a >>> prompt to appear try pressing Ctrl-c a couple times to interrupt any running program on the board.

You might get a Traceback and KeyboardInterrupt that lets you know the current Python program has stopped, and you'll get a prompt:

That's all there is to connecting to the board's serial REPL, you're ready to start typing in and running CircuitPython code!

Last updated on 2017-12-01 at 04.59.09 PM Published on 2017-07-26 at 06.08.30 PM