# Circuit Playground Express Serial Communications

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/059/134/medium800/makecode_putty.png?1534292438)

This guide explains serial connections between the Circuit Playground Express and other devices. This is very useful for making connections to other microcontrollers or single board computers like the Raspberry Pi. And some sensors require serial communications instead of other protocols like I2C or SPI.

An outbound serial connection can be used for applications like CNC, data logging, debugging code, and many other things.

You can program serial communications with Microsoft MakeCode and CircuitPython - examples will be shown in each.

## Parts List
### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
![A Black woman's manicured hand holds a round microcontroller with lit up LEDs.](https://cdn-shop.adafruit.com/640x480/3333-05.jpg)

### USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi

[USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi](https://www.adafruit.com/product/954)
The cable is easiest way ever to connect to your microcontroller/Raspberry Pi/WiFi router serial console port. Inside the big USB plug is a USB\<-\>Serial conversion chip and at the end of the 36" cable are four wire - red power, black ground, white RX into USB port, and green TX out...

In Stock
[Buy Now](https://www.adafruit.com/product/954)
[Related Guides to the Product](https://learn.adafruit.com/products/954/guides)
![USB to TTL Serial Cable With Type A plug and 4 wire sockets](https://cdn-shop.adafruit.com/640x480/954-02.jpg)

# Circuit Playground Express Serial Communications

## What is Serial Communications?

![](https://cdn-learn.adafruit.com/assets/assets/000/059/129/medium800/makecode_Capture.png?1534292290)

In simple terms, serial data is sending data over few wires in a timed sequence. This is the opposite of parallel in which data may simultaneously be transmitted over many wires.

To take advantage of the benefits of serial communications, standards have been devised:

First was RS-232, a standard that has evolved over time and used as a basis for the TTL Serial interface, lower level connectivity between two electronics boards.

Later was the Universal Serial Bus (USB), devised to be better than RS-232. With refinements and operating system innovations like "Plug and Play", USB has dominated modern electronics device connectivity.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/130/medium800/makecode_Serial_vs_parallel_transmission.jpg?1534292335)

# Circuit Playground Express Serial Communications

## Serial Hardware

![](https://cdn-learn.adafruit.com/assets/assets/000/058/713/medium800/makecode_cpx-serial.png?1533664573)

The Circuit Playground Express has two serial interfaces baked in:

- The USB connector for high level serial
- Pads RX/A6 and TX/A7 (along with an electrical ground GND) provide a 3.3 volt TTL serial interface

There also is the capability to work with TTL serial over any two set of data pins. This is called software serial as there is no dedicated hardware on the Circuit Playground Express' microcontroller chip to assist in providing a serial interface, the data serialization is done in software instead of hardware. See the [CircuitPython Essentials Guide](https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial) for more in-depth information on selecting serial pins.

## USB to TTL Serial Adapters

It is very useful to have devices that can convert from a low level TTL serial interface to USB. Likewise it can be useful to have a USB capable computer talk low level TTL serial.&nbsp;

Adafruit and other companies sell USB to serial adapters with various capabilities for providing this type of conversion and interface.

&nbsp;

The [USB to TTL Serial Cable](https://www.adafruit.com/product/954) provides serial conversion both ways: TTL to USB and USB to TTL serial. It makes connections very easy.

&nbsp;

The&nbsp;[Adafruit CP2104 Friend - USB to Serial Converter](https://www.adafruit.com/product/3309)&nbsp;Board adds additional serial connection signals needed by some projects. It is very reasonable price-wise and comes with transmit and receive LED indicators. Some soldering might be needed for connections.

![makecode_954-02.jpg](https://cdn-learn.adafruit.com/assets/assets/000/058/687/medium640/makecode_954-02.jpg?1533646902)

![makecode_3309-00.jpg](https://cdn-learn.adafruit.com/assets/assets/000/058/688/medium640/makecode_3309-00.jpg?1533647160)

## Serial Ports on Computers

Our computers (be they a PC, Mac, Linux box or a mobile device) all have serial communications baked-in. How this is usually done is via a number of USB ports.&nbsp;

USB ports show up on your computer in operating system-dependent ways:

- **Windows** : Serial ports are called COM ports and are typically numbered. For example COM1, COM2,.., COM23, .. COM33, etc. Use the Device Manager to find your COM port name
- **Mac** : Serial ports follow a Linux/Unix like convention, with device names like /dev/tty.usbmodem and a suffix like a number. In Terminal, type `ls /dev/tty*` to list all serial ports.
- **Linux:** Serial ports are also in /dev and start with tty but may vary in their naming conventions, an example may be /dev/ttyUSB0. In the command line type `ls /dev/tty*` to list all serial ports

# Circuit Playground Express Serial Communications

## Serial Communications Software

![](https://cdn-learn.adafruit.com/assets/assets/000/058/747/medium800/makecode_Blinka-promo.png?1533755948)

## Serial Terminal Emulation Use

Going back to the serial RS-232 standard, there are a number of configurations for how many serial bits are sent at once. But with TTL serial, it is pretty standard that software is set for 8 bits, no parity bit, one stop bit, abbreviated 8,N,1 or 8, 1, N.

A key parameter for setting up serial communications is setting a baud rate. Best to think of it as how many bits a second are transmitted. Typical speeds follow old-time modem rates such as 1200, 9600, 19200, 57600, 115200. 256000, and 1 megabit. While setting non-standard rates may be possible with software serial, hardware may only accept fixed rates. For microcontrollers, 9600 is a typical slow rate and 115200 often a fast rate. Check your hardware specifications (spec) sheet for the baud rates the board supports.

When you run your terminal emulator, you'll need at least the baud rate, possibly the bit configuration also. Below is the configuration you might set up for Windows PuTTY:

![](https://cdn-learn.adafruit.com/assets/assets/000/058/740/medium800/makecode_circuitpython_PUTTY.png?1533748846)

Note the Serial line box has the **COM port** name, and **Speed** has the baud rate. We also have to click the **Serial** radio button to make sure we have a Serial connection

## Software

While your final project may have two devices communicating without any visualization on what is being exchanged, viewing serial communications is very common. It was the primary way to interface with minicomputers before PCs came along.

Serial communications software has many names but they all basically do the same thing: display the outgoing data as characters and possibly allow the user to send characters back.

### Mac and Linux

Linux and the Mac command line have the terminal capability to initiate serial communications. See our guide [Advanced Serial Console for Mac and Linux](https://learn.adafruit.com/welcome-to-circuitpython/advanced-serial-console-on-mac-and-linux) for more information

### Windows

Windows does not have a serial terminal standard but there are many third party terminal emulators including [PuTTY](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) and Tera Term among others. See our guide [Advanced Serial Console on Windows](https://learn.adafruit.com/welcome-to-circuitpython/advanced-serial-console-on-windows) for more information.

Your Windows COM port will be shown in the **Control Panel -\> Devices and Printers** section, under Unspecified Devices and names Silicon Labs CP210x USB to UART Bridge.

![](https://cdn-learn.adafruit.com/assets/assets/000/058/741/medium800/makecode_windows-dev.png?1533748853)

Use that COM port and the baud rate in your code for your terminal software

# Circuit Playground Express Serial Communications

## External TTL Serial Connections

![](https://cdn-learn.adafruit.com/assets/assets/000/058/720/medium800/makecode_Serial-to-camera_bb2.png?1533673758 The TTL camera operates on 5V DC but performs 3.3 volt TTL serial so it is Circuit Playground Express safe run via USB power.)

## Device Types

You will find a variety of devices that use TTL serial connections. This includes:

- JPEG still camera boards - examples: [Adafruit 397](https://www.adafruit.com/product/397)&nbsp;(shown above), [Adafruit 1386](https://www.adafruit.com/product/1386) (miniature) and [Adafruit 613](https://www.adafruit.com/product/613) (waterproof)
- GPS boards - examples: [Adafruit Ultimate GPS 746](https://www.adafruit.com/product/746), [Adafruit Flora GPS 1059](https://www.adafruit.com/product/1059)
- Thermal printers - examples: [Adafruit Tiny Printer 2751](https://www.adafruit.com/product/1059) and [Adafruit nano printer 2752](https://www.adafruit.com/product/2752)
- Fingerprint Sensor - example: [Adafruit 751](https://www.adafruit.com/product/751)
- Serial LCD Displays - example: [Adafruit 784](https://www.adafruit.com/product/784)
- Serial to PS/2 Keyboard - example: [Adafruit 1136](https://www.adafruit.com/product/1136)
- XBee modules - example: [Adafruit 128](https://www.adafruit.com/product/128) and many others at Adafruit
- Ultrasonic Sensors - example: [Adafruit 984](https://www.adafruit.com/product/984) and many others at Adafruit

## Connections
Danger: 

Check the data sheet for your device. If it is a 5 volt device, you may need a level shifting chip to interface between the TTL device and the Circuit Playground Express.

If your device is 3.3 volts safe, here are the connections you will want to make:

- Connect the Circuit Playground Express&nbsp; **TX/A7** pad to the device **RX/Receive** pin
- Connect the Circuit Playground Express **RX/A6** pad to the device **TX/Transmit** pin
- Connect the Circuit Playground Express **GND/Ground** pad to the device **GND/Ground**

If the device will be powered by the Circuit Playground Express, you can connect the 3.3V pad to the 3.3 Volt input of the device. But be sure the device will not draw more than about 300 milliamps. You can draw up to 450 milliamps if you do not use the NeoPixels on the Circuit Playground Express. See [this page](https://learn.adafruit.com/adafruit-circuit-playground-express/pinouts "Circuit Playground Express guide") for details.

Warning: 

The [Adafruit TTL serial camera](https://www.adafruit.com/product/397) is a good example board (see the Fritzing diagram at the top of the page). The TTL serial connections run at 3.3 volts so hooking TX to RX, RX to TX and ground to ground makes the communications work. The camera board must be powered by 5 volts. This is taken from the Vout pad which does have 5 volts when the Circuit Playground Express board is powered from a USB connection.

# Circuit Playground Express Serial Communications

## USB Converter Connections

## Using the Adafruit USB Serial to USB Cable
![](https://cdn-learn.adafruit.com/assets/assets/000/058/738/medium800/makecode_Serial-to-cable-w-pwr.png?1533748171 The red wire is not required and should not be used if you power the board from a battery or the native USB port.)

Info: 

Warning: 

If you are looking to establish a serial connection via the [Adafruit&nbsp;USB console cable #954](https://www.adafruit.com/product/954), the connections are shown above. This diagram shows using the USB cable power for the Circuit Playground Express (the red wire). If the console cable is plugged into a computer, the red wire has +5 volts and can power the Circuit Playground Express if connected to the Vout pad. If you plan to power the Circuit Playground Express via battery or USB power via the onboard USB connection, do not connect the USB serial converter cable red wire.

The signal wires RX and TX are 3.3 volt "TTL" levels so they are safe for Circuit Playground Express.

For computer drivers for using the USB port from the USB converter cable:

- If you are running Windows 7/8/10 etc,&nbsp;[check this tutorial page with links to drivers for both PL2303 and CP2102](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/software-installation-windows)
- If you are running Mac OS X,&nbsp;[check this tutorial page with links to drivers for both PL2303 and CP2012](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/software-installation-mac)
- If you are running Linux, drivers are already included in the kernel, no need to install anything!

In Windows, you will see the following icon appear in the Control Panel -\> Devices and Printers view:

![](https://cdn-learn.adafruit.com/assets/assets/000/058/734/medium800/makecode_windows-dev.png?1533746592)

## Using the Adafruit CP2104 Serial Communications Board
![](https://cdn-learn.adafruit.com/assets/assets/000/058/725/medium800/makecode_cpx-serial-cp2104.png?1533676729)

Above shows the connections for the [Adafruit CP2104 Serial board #3309](https://www.adafruit.com/product/3309). The headers are not soldered in to get a better view of the board markings.&nbsp;This diagram assumes you are using USB or battery power for the Circuit Playground Express. The signal wires RX and TX are 3.3 volt "TTL" levels so they are safe for Circuit Playground Express. The ground wire provides an electrical return path so is necessary.

For Windows, the USB driver is in Windows Update, [Mac OS drivers are here](http://www.silabs.com/products/mcu/pages/usbtouartbridgevcpdrivers.aspx), Linux does not need a driver.

## What do these connections do?

These connections turn a serial connection between the Circuit Playground Express (via the hardware serial TX and RX pads) to the cable and board which have chips which convert the TTL serial into USB serial communications.

**Why not just use the Circuit Playground Express USB port?**

1) The software support for USB on the Circuit Playground Express was discussed earlier - there are some limitations on its use in various languages that may not be present with an external board.

2) Sometimes you need more than one serial connection.

**Can I program the Circuit Playground Express via an external USB connection like the ones shown?**

Nope! This is only for debugging output from MakeCode or CircuitPython

# Circuit Playground Express Serial Communications

## Serial Communications Code

The following pages have the explanation of how to use serial communications for MakeCode and CircuitPython.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/127/medium800/makecode_Serial-to-cable-w-pwr.png?1534291058)

For both of these examples, you'll need to have the wiring to your USB Serial cable or adapter as seen above!

# Circuit Playground Express Serial Communications

## MakeCode

![](https://cdn-learn.adafruit.com/assets/assets/000/059/126/medium800/makecode_Serial-to-cable-w-pwr.png?1534291047)

MakeCode has a beta set of blocks for serial communications. You will need to use the web address [https://makecode.adafruit.com/beta](https://makecode.adafruit.com/beta). Click **New Project**. Then Click the **ADVANCED** block group then the **EXTENSIONS** button under that. One of the experimental extensions is Serial. Click that and you should see back on the main block editing page a new block group **SERIAL**.

![](https://cdn-learn.adafruit.com/assets/assets/000/058/730/medium800/makecode-serial.png?1533741801)

These are the blocks you can use to connect to external serial peripherals and serial to USB devices.&nbsp;

Warning: 

Here is a simple program to write the light level and temperature read by the Circuit Playground Express to a serial interface. The `serial redirect` block sets up the communication pads and the baud rate. The program below uses the pads marked **TX** and **RX** for transmit and receive. If you use other pads, they will work but you are not using the hardware serial on the board but a software serial code function which is fine for the low transmission rates allowed by the block (no greater than 115,200 baud).

The hardware setup is shown on the page [USB Converter Connections](https://learn.adafruit.com/circuit-playground-express-serial-communications/usb-converter-connections).

![](https://cdn-learn.adafruit.com/assets/assets/000/058/736/medium800/makecode-serial-code.png?1533747721)

[Click to Load the Example in MakeCode](https://makecode.com/_isvJ5f0j6Uxy)
If you open up a terminal program and set it for your communications port at 115,200 baud, you'll get the output similar to that below:

![](https://cdn-learn.adafruit.com/assets/assets/000/058/737/medium800/makecode_putty.png?1533747814)

If you get garbled text, you don't have the right baud rate, close the terminal and rerun the terminal program with the correct baud rate (for the code shown, that is 115,200).

If you get nothing, check the following:

1. Is the Power On green LED on Circuit Playground Express? If not, add the correct power supply.
2. Did you load the MakeCode onto the Circuit Playground Express?
3. Are your connections such that the Circuit Playground Express TX pad connects to the converter RX (white wire) and that the RX pad connects to the TX (green wire) on the converter? They must be crossed for serial connections between devices).
4. Ensure your terminal emulator is set for **115200 baud**. For PuTTY, this is in the opening screen, with the COM port number the one from the Control Panel -\> Devices and Printers for the Silicon Labs CP210x USB to UART Bridge device.

![](https://cdn-learn.adafruit.com/assets/assets/000/058/739/medium800/makecode_putty.png?1533748806)

# Circuit Playground Express Serial Communications

## CircuitPython

![](https://cdn-learn.adafruit.com/assets/assets/000/058/744/medium800/makecode_Serial-to-cable-w-pwr.png?1533754681)

CircuitPython has support for serial communications through the `busio` library. The [CircuitPython Essentials guide](https://learn.adafruit.com/circuitpython-essentials) has a page on [UART Serial](https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial) for CircuitPython which is a good reference.

The following code opens serial communications via `busio.UART` on the Circuit Playground Express TX and RX pads defined in the `board` library.&nbsp;

The code then goes into a loop, waiting for a character to be received (any character), sending back the time (relative), the light intensity (relative) and the temperature in Celsius. The `sleep` time between reads can be adjusted.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPX_Serial/code.py

The output is shown below. The data will not be displayed until you type in a character (any one character), then the program returns the time, the light value, and the temperature in Celsius. The read is not required, you can remove that if you like and have the data be written on every pass of the loop delayed by the `sleep` time.

![](https://cdn-learn.adafruit.com/assets/assets/000/058/745/medium800/makecode_CP-serial.png?1533755380)

The documentation for `busio.UART` is on [Read The Docs](https://circuitpython.readthedocs.io/en/latest/shared-bindings/busio/UART.html).

Also see the [CircuitPython Essentials guide UART Communications page](https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial).


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi

[USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi](https://www.adafruit.com/product/954)
The cable is easiest way ever to connect to your microcontroller/Raspberry Pi/WiFi router serial console port. Inside the big USB plug is a USB\<-\>Serial conversion chip and at the end of the 36" cable are four wire - red power, black ground, white RX into USB port, and green TX out...

In Stock
[Buy Now](https://www.adafruit.com/product/954)
[Related Guides to the Product](https://learn.adafruit.com/products/954/guides)
### Adafruit CP2104 Friend - USB to Serial Converter

[Adafruit CP2104 Friend - USB to Serial Converter](https://www.adafruit.com/product/3309)
Discontinued - **you can grab** [Adafruit CP2102N Friend - USB to Serial Converter&nbsp;](https://www.adafruit.com/product/5335) **instead!&nbsp;**

Long gone are the days of parallel ports and serial ports. Now the USB port reigns supreme! But USB is hard, and you just...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3309)
[Related Guides to the Product](https://learn.adafruit.com/products/3309/guides)
### Small Alligator Clip to Male Jumper Wire Bundle - 6 Pieces

[Small Alligator Clip to Male Jumper Wire Bundle - 6 Pieces](https://www.adafruit.com/product/3448)
When working&nbsp;with unusual non-header-friendly surfaces, these handy cables will be your best friends! No longer will you have long, cumbersome strands of alligator clips. These compact jumper cables have a premium male header on one end and a grippy mini alligator clip on the...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3448)
[Related Guides to the Product](https://learn.adafruit.com/products/3448/guides)
### Circuit Playground Express - Base Kit

[Circuit Playground Express - Base Kit](https://www.adafruit.com/product/3517)
It's the **Circuit Playground Express Base Kit!** &nbsp;It provides&nbsp;the few things you'll need to get started with the new [Circuit Playground Express](https://www.adafruit.com/product/3333).&nbsp;This version of Circuit Playground is super powered, and will...

In Stock
[Buy Now](https://www.adafruit.com/product/3517)
[Related Guides to the Product](https://learn.adafruit.com/products/3517/guides)
### Circuit Playground Express Advanced Pack

[Circuit Playground Express Advanced Pack](https://www.adafruit.com/product/2769)
 **Circuit Playground Express** &nbsp;is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to program....

In Stock
[Buy Now](https://www.adafruit.com/product/2769)
[Related Guides to the Product](https://learn.adafruit.com/products/2769/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Infrared Receive and Transmit with Circuit Playground Express](https://learn.adafruit.com/infrared-ir-receive-transmit-circuit-playground-express-circuit-python.md)
- [CPX Glowing Disembodied Hand](https://learn.adafruit.com/cpx-glowing-disembodied-hand.md)
- [Circuit Playground Musical Glove](https://learn.adafruit.com/cpx-musical-glove.md)
- [Using the Android CircuitPython Editor](https://learn.adafruit.com/using-the-android-circuitpython-editor.md)
- [CircuitPython Essentials](https://learn.adafruit.com/circuitpython-essentials.md)
- [HalloWing Light Paintstick](https://learn.adafruit.com/hallowing-light-paintstick.md)
- [Circuit Playground Express TV Zapper](https://learn.adafruit.com/circuitpython-tv-zapper-with-circuit-playground-express.md)
- [Fireflies with MakeCode](https://learn.adafruit.com/circuit-playground-fireflies-makecode.md)
- [Halloween Monsters with CRICKIT and Circuit Playground Express](https://learn.adafruit.com/halloween-monsters-with-crickit.md)
- [MicroBlocks Circuit Playground Express Ornament](https://learn.adafruit.com/microblocks-circuitplayground-express-ornament.md)
- [Make It Glow - Your First NeoPixel Project](https://learn.adafruit.com/make-it-glow-your-first-neopixel-project.md)
- [Sound Activated Shark Mask](https://learn.adafruit.com/sound-activated-shark-mask.md)
- [Building CircuitPython](https://learn.adafruit.com/building-circuitpython.md)
- [Circuit Playground Express Laser Tag](https://learn.adafruit.com/circuit-playground-express-laser-tag.md)
- [FLORAbrella](https://learn.adafruit.com/florabrella.md)
