# CircuitPython Libraries on Linux and Raspberry Pi

## Overview

Info: This guide describes using CircuitPython **libraries** on small Linux computers, running under regular Python. It is not about running the CircuitPython firmware itself on those boards.

![](https://cdn-learn.adafruit.com/assets/assets/000/056/765/medium800/sensors_blinkatux.gif?1530378720)

Here at Adafruit we're always looking for ways to make _making easier_ - whether that's making breakout boards for hard-to-solder sensors or writing libraries to simplify motor control. Our new favorite way to program is **CircuitPython**.

## Why CircuitPython?

CircuitPython is a variant of MicroPython, a very small version of Python that can fit on a microcontroller. Python is the fastest-growing programming language. It's taught in schools, used in coding bootcamps, popular with scientists and of course programmers at companies use it a lot!

CircuitPython adds the Circuit part to the Python part. It lets you program in Python and talk to Circuitry like sensors, motors, and LEDs!

## CircuitPython on Microcontrollers

CircuitPython runs on microcontroller boards, such as our Feather, Metro, QT Py, and ItsyBitsy boards, using a variety of chips, such as the MicroChip SAMD21 SAMD51, the Raspberry Pi RP2040, the Nordic nRF52840, and the Espressif ESP32-S2 and ESP32-S3.

All of these chips have something in common - they are _microcontrollers_ with hardware peripherals like SPI, I2C, ADCs etc. We squeeze Python into 'em and can then make the project portable.

But...sometimes you want to do more than a microcontroller can do. Like HDMI video output, or camera capture, or serving up a website, or just something that takes more memory and computing than a microcontroller board can do...

## CircuitPython Libraries on Desktop Linux

By adding a software layer, you can use CircuitPython hardware control capabilities&nbsp;with "regular Python", as found on your desktop or single-board Linux computer/ There are tons of projects, libraries and example code for CircuitPython on microcontrollers, and thanks to the flexibility and power of Python its' pretty easy to get that code working on micro-computers like the Raspberry Pi or other single-board Linux computers with GPIO pins available.

You'll use a special library called&nbsp;[**adafruit\_blinka**](https://pypi.org/project/Adafruit-Blinka/)&nbsp;([named after Blinka, the CircuitPython mascot](https://www.adafruit.com/?q=blinka)) that provides a layer that translates the CircuitPython hardware API to whatever library the Linux board provides. For example, on Raspberry Pi we use the python&nbsp;[RPi.GPIO](https://pypi.org/project/RPi.GPIO/)&nbsp;library. For any I2C interfacing we'll use ioctl messages to the&nbsp;`/dev/i2c`&nbsp;device. For SPI we'll use the&nbsp;`spidev`&nbsp;python library, etc. These details don't matter so much because they all happen underneath the&nbsp; **adafruit\_blinka** &nbsp;layer.

The upshot is that most code we write for CircuitPython will be instantly and easily runnable on Linux computers like Raspberry Pi.

_In particular_, you'll be able to use all of our device drivers - the sensors, led controllers, motor drivers, HATs, bonnets, etc. And nearly all of these use I2C or SPI!

The rest of this guide describes how to install and set up Blinka, and then how to use it to run CircuitPython code to control hardware.

# CircuitPython Libraries on Linux and Raspberry Pi

## Running CircuitPython Code without CircuitPython

There are two parts to the CircuitPython ecosystem:

- **CircuitPython firmware** , written in C and built to run on various microcontroller boards (not PCs). The firmware includes the CircuitPython interpreter, which reads and executes CircuitPython programs, and chip-specific code that controls the hardware peripherals on the microcontroller, including things like USB, I2C, SPI, GPIO pins, and all the rest of the hardware features the chip provides.
- **CircuitPython libraries,** written in Python to use the native (built into the firmware) modules provided by CircuitPython to control the microcontroller peripherals and interact with various breakout boards.

But suppose you'd like to use CircuitPython **libraries** on a board or computer that does not have a native CircuitPython **firmware** build. For example, on a PC running Windows or macOS. Can that be done? The answer is yes, via a separate piece of software called **Blinka**. Details about Blinka follow, however it is important to realize that the **CircuitPython firmware is never used**.

Info: 

# Adafruit Blinka: a CircuitPython Compatibility Library

Enter **Adafruit**  **Blinka**. Blinka is a software library that emulates the parts of CircuitPython that control hardware. Blinka provides non-CircuitPython implementations for `board`, `busio`, `digitalio`, and other native CircuitPython modules. You can then write Python code that looks like CircuitPython and uses CircuitPython libraries, without having CircuitPython underneath.

There are multiple ways to use Blinka:&nbsp;

- Linux based Single Board Computers, for example a Raspberry Pi
- Desktop Computers + specialized USB adapters
- Boards running MicroPython

More details on these options follow.

## Raspberry Pi and Other Single-Board Linux Computers

On a Raspberry Pi or other single-board Linux computer, you can use Blinka with the regular version of Python supplied with the Linux distribution. Blinka can control the hardware pins these boards provide.

## Desktop Computers&nbsp;

On Windows, macOS, or Linux desktop or laptop ("host") computers, you can use special USB adapter boards that that provide hardware pins you can control. These boards include [MCP221A](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221)&nbsp;and [FT232H](https://learn.adafruit.com/adafruit-ft232h-breakout) breakout boards, and [Raspberry Pi Pico boards running the **u2if** software](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico). These boards connect via regular USB to your host computer, and let you do GPIO, I2C, SPI, and other hardware operations.

## MicroPython

You can also use Blinka with MicroPython, on [MicroPython-supported boards](https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico). Blinka will allow you to import and use CircuitPython libraries in your MicroPython program, so you don't have to rewrite libraries into native MicroPython code. Fun fact - this is actually the original use case for Blinka.

# Installing Blinka

Installing Blinka on your particular platform is covered elsewhere in this guide. The process is different for each platform. Follow the guide section specific to your platform and make sure Blinka is properly installed before attempting to install any libraries.

Info: 

# Installing CircuitPython Libraries

Once Blinka is installed the next step is to install the CircuitPython libraries of interest. How this is down is different for each platform. Here are the details.

## Linux Single-Board Computers

On Linux single-board computers, such as Raspberry Pi, you'll use the Python `pip3`&nbsp;program (sometimes named just `pip`) to install a library. The library will be downloaded from [pypi.org](https://pypi.org) automatically by `pip3`.

How to install a particular library using `pip3` is covered in the guide page for that library. For example, [here is the `pip3` installation information](https://learn.adafruit.com/adafruit-lis3dh-triple-axis-accelerometer-breakout/python-circuitpython#python-installation-of-lis3dh-library-2997958) for the library for the LIS3DH accelerometer.

The library name you give to `pip3` is usually of the form `adafruit-circuitpython-libraryname`. This is not the name you use with `import`. For example, the LIS3DH sensor library is known by several names:

- The GitHub library repository is [Adafruit\_CircuitPython\_LIS3DH](https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH).
- When you import the library, you write `import adafruit_lis3dh`.
- The name you use with `pip3` is `adafruit-circuitpython-lis3dh`. This the name used on [pypi.org](https://pypi.org).

Libraries often depend on other libraries. When you install a library with `pip3`, it will automatically install other needed libraries.

## Desktop Computers using a USB Adapter

When you use a desktop computer with a USB adapter, like the MCP2221A, FT232H, or u2if firmware on an RP2040, you will also use pip3. However, **do _not_ install the library with `sudo pip3`** , as mentioned in some guides. Instead, just install with `pip3`.&nbsp;

## MicroPython

For MicroPython, you will not use `pip3`. Instead you can get the library from the CircuitPython bundles. See [this guide page](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries) for more information about the bundles, and also see the [Libraries page on circuitPython.org](https://circuitpython.org/libraries).

# CircuitPython Libraries on Linux and Raspberry Pi

## CircuitPython & RasPi

![](https://cdn-learn.adafruit.com/assets/assets/000/056/768/medium800/sensors_blinkapi.gif?1530379184)

## CircuitPython Libraries on Linux & Raspberry Pi

The next obvious step is to bring CircuitPython **back** to 'desktop Python'. We've got tons of projects, libraries and example code for CircuitPython on microcontrollers, and thanks to the flexibility and power of Python it's pretty easy to get that code working with micro-computers like Raspberry Pi or other 'Linux with GPIO pins available' single board computers.

We are not running the CircuitPython interpreter itself on the Linux machine. But we _are_ running Python code written to use the CircuitPython hardware API (`busio.I2C`, `busio.SPI`, etc.)

We'll use a special library called [**adafruit\_blinka**](https://pypi.org/project/Adafruit-Blinka/) ([named after Blinka, the CircuitPython mascot](https://www.adafruit.com/?q=blinka)) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. For example, on Raspberry Pi we use the python [RPi.GPIO](https://pypi.org/project/RPi.GPIO/) library. For any I2C interfacing we'll use ioctl messages to the `/dev/i2c` device. For SPI we'll use the `spidev` python library, etc. These details don't matter so much because they all happen underneath the **adafruit\_blinka** layer.

The upshot is that any code we have for CircuitPython will be instantly and easily runnable on Linux computers like Raspberry Pi.

_In particular_, we'll be able to use all of our device drivers - the sensors, led controllers, motor drivers, HATs, bonnets, etc. And nearly all of these use I2C or SPI!

&nbsp;

## Wait, isn't there already something that does this - GPIO Zero?

[Yes! We like and use GPIO Zero a lot](https://gpiozero.readthedocs.io/en/stable/), its an excellent hardware interfacing library for Raspberry Pi. It's great for digital in/out, analog inputs, servos, some basic sensors, etc. In particular, one cool thing it does is thread/event management so you can have code run, say, when a button is pressed.

GPIO Zero excels at that, but doesn't cover SPI/I2C sensors or drivers, which is where we got stuck: for each sensor we had we'd write a driver in C/C++ for Arduino, CircuitPython using our hardware API, and then Python using smbus or similar.

By letting you use CircuitPython on Raspberry Pi via **adafruit\_blinka** , you can unlock all of the drivers and example code we wrote! _And_ you can keep using GPIO Zero for pins, buttons and LEDs. We save time and effort so we can focus on getting code that works in one place, and you get to reuse all the code we've written already.

## What about other Linux SBCs?

Plus, we're adapting and extending **adafruit\_blinka** to [support _other_ boards](https://learn.adafruit.com/circuitpython-on-orangepi-linux) such as Allwinners and BeagleBone, even some smaller linux boards like Onion.io will be able to run CircuitPython code.

If you have a board you'd like to adapt [check out the adafruit\_blinka code on github](https://github.com/adafruit/Adafruit_Blinka), pull requests are welcome as there's a _ton_ of different Linux boards out there! [You'll need to add a detection element](https://github.com/adafruit/Adafruit_Python_PlatformDetect) so we can tell what board you're running on, then the pin definitions into **adafruit\_blinka** above. As long as you're running a modern kernel, you'll have libgpiod for GPIO, smbus for I2C and spidev for SPI all ready to go.

# CircuitPython Libraries on Linux and Raspberry Pi

## Installing Blinka on Raspberry Pi

Info: 

Warning: 

# Prerequisite Pi Setup!

In this page we'll assume you've already gotten your Raspberry Pi up and running and can log into the command line

Here's the quick-start for people with some experience:

1. Download the&nbsp;[latest Raspberry Pi OS or Raspberry Pi OS Lite](https://www.raspberrypi.org/software/operating-systems/)&nbsp;to your computer
2. [Burn the OS image to your MicroSD card](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)&nbsp;using your computer
3. [Re-plug the SD card into your computer (don't use your Pi yet!) and set up your wifi connection by editing supplicant.conf](https://learn.adafruit.com/raspberry-pi-zero-creation/text-file-editing)
4. [Activate SSH support](https://learn.adafruit.com/raspberry-pi-zero-creation/text-file-editing)
5. Plug the SD card into the Pi
6. If you have an HDMI monitor we recommend connecting it so you can see that the Pi is booting OK
7. Plug in power to the Pi - you will see the green LED flicker a little. The Pi will reboot while it sets up so wait a good 10 minutes
8. [If you are running Windows on your computer, install Bonjour support so you can use&nbsp; **.local** &nbsp;names, you'll need to reboot Windows after installation](https://learn.adafruit.com/bonjour-zeroconf-networking-for-windows-and-linux#microsoft-windows)
9. [You can then&nbsp; **ssh** &nbsp;into&nbsp; **raspberrypi.local**](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh)

[The Pi Foundation has tons of guides as well](https://projects.raspberrypi.org/en/projects/raspberry-pi-getting-started)

Danger: 

# Update Your Pi and Python

Run the standard updates:

```terminal
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
```

and upgrade setuptools:

```terminal
sudo apt install --upgrade python3-setuptools
```

Info: 

Warning: 

# Setup Virtual Environment

If you are installing on the Bookworm (released in 2023) or later version of Raspberry Pi OS, you will need to install your python modules in a virtual environment. You can find more information in the&nbsp;[Python Virtual Environment Usage on Raspberry Pi](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi) guide. To Install and activate the virtual environment, use the following commands:

```terminal
cd ~
sudo apt install python3-venv
python3 -m venv env --system-site-packages
```

You will need to activate the virtual environment every time the Pi is rebooted. To activate it:

```terminal
source env/bin/activate
```

To deactivate, you can use `deactivate`, but leave it active for now.

# Automated Install

We put together a script to easily make sure your Pi is correctly configured and install Blinka. It requires just a few commands to run. Most of it is installing the dependencies.

```terminal
cd ~
pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo -E env PATH=$PATH python3 raspi-blinka.py
```

If you are installing on an earlier version such as Bullseye of Raspberry Pi OS and not using a Virtual Environment, you can call the script like:

`sudo python3 raspi-blinka.py`

If you are installing an older version of Raspberry Pi OS, your system default Python is likely Python 2. If so, it will ask to confirm that you want to proceed. Choose&nbsp; **yes**.

![sensors_Python_Sys_Default.png](https://cdn-learn.adafruit.com/assets/assets/000/098/682/medium640/sensors_Python_Sys_Default.png?1610754382)

It may take a few minutes to run. When it finishes, it will ask you if you would like to reboot. Choose&nbsp; **yes**.

![sensors_Reboot_Now.png](https://cdn-learn.adafruit.com/assets/assets/000/098/683/medium640/sensors_Reboot_Now.png?1610754482)

Once it reboots, the connection will close. After a couple of minutes, you can reconnect.

![sensors_Connection_Closed.png](https://cdn-learn.adafruit.com/assets/assets/000/098/684/medium640/sensors_Connection_Closed.png?1610754544)

# Manual Install

If you are having trouble running the automated installation script, you can follow these steps to manually install Blinka.

### Enable Interfaces

Run these commands to enable the various interfaces such as I2C and SPI:

```terminal
sudo raspi-config nonint do_i2c 0
sudo raspi-config nonint do_spi 0
sudo raspi-config nonint do_serial_hw 0
sudo raspi-config nonint do_ssh 0
sudo raspi-config nonint do_camera 0
sudo raspi-config nonint disable_raspi_config_at_boot 0
```

### Install Blinka and Dependencies

Blinka needs a few dependencies installed:

```terminal
sudo apt-get install -y i2c-tools libgpiod-dev python3-libgpiod
pip3 install --upgrade adafruit-blinka
```

### Raspberry Pi 5 Adjustments

At the moment, RPi.GPIO is installed, which causes issues. Just remove it with the following command:

```terminal
pip3 uninstall -y RPi.GPIO
```

# Check I2C and SPI

The script will automatically enable I2C and SPI. You can run the following command to verify:

```terminal
ls /dev/i2c* /dev/spi*
```

You should see the response

`/dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1`

![](https://cdn-learn.adafruit.com/assets/assets/000/056/782/medium800/sensors_ls.png?1530380749)

## Fixing CE0 and CE1 Device or Resource Busy Issue

In order to use the CE0 and CE1 pins in Python, you will need to disable them from OS usage. To do so, check out the [Reassigning or Disabling the SPI Chip Enable Lines](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/spi-sensors-devices#reassigning-or-disabling-the-spi-chip-enable-lines-3097985) section of this guide.

## Enabling Second SPI

If you are using the main SPI port for a display or something and need another hardware SPI port, you can enable it by adding the line

`dtoverlay=spi1-3cs`

to the bottom of **/boot/config.txt** and rebooting. You'll then see the addition of some /dev/spidev1.x devices:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/554/medium800/sensors_image.png?1534951162)

## Pi 5 : Cannot determine SOC peripheral base address
comment out this line :

```auto
#dtparam=spi=on
```

# Blinka Test
Warning: 

Create a new file called **blinkatest.py** with **nano** or your favorite text editor and put the following in:

```auto
import board
import digitalio
import busio

print("Hello, blinka!")

# Try to create a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

print("done!")
```

Save it, make sure your virtual environment is activated, and run at the command line with:

```terminal
python3 blinkatest.py
```

You should see the following, indicating digital i/o, I2C and SPI all worked.

![](https://cdn-learn.adafruit.com/assets/assets/000/056/785/medium800/sensors_test.png?1530381767)

# CircuitPython Libraries on Linux and Raspberry Pi

## Digital I/O

The first step with any new hardware is the 'hello world' of electronics - blinking an LED. This is very easy with CircuitPython and Raspberry Pi. We'll extend the example to also show how to wire up a button/switch and enable a pull-up resistor.

Even if you use a different library to create digital in/outs like GPIO Zero, there's a number of sensor libraries that use a digital pin for resetting, or for a chip-select. So it's good to have this part working!

# Parts Used
Any old LED will work just fine as long as its not an IR LED (you can't see those) and a 470 to 2.2K resistor

### Diffused Blue 10mm LED (25 pack)

[Diffused Blue 10mm LED (25 pack)](https://www.adafruit.com/product/847)
Need some big indicators? We are big fans of these huge diffused blue LEDs. They are really bright so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 diffused blue LEDs
- 10mm...

In Stock
[Buy Now](https://www.adafruit.com/product/847)
[Related Guides to the Product](https://learn.adafruit.com/products/847/guides)
![Single large LED lit up blue](https://cdn-shop.adafruit.com/640x480/847-00.jpg)

### Through-Hole Resistors - 470 ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 470 ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2781)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 470Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2781)
[Related Guides to the Product](https://learn.adafruit.com/products/2781/guides)
![Angled shot of 25 Through-Hole Resistors - 470 ohm 5% 1/4W.](https://cdn-shop.adafruit.com/640x480/2781-00.jpg)

Some tactile buttons or switches

### Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack

[Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack](https://www.adafruit.com/product/1119)
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all). The...

In Stock
[Buy Now](https://www.adafruit.com/product/1119)
[Related Guides to the Product](https://learn.adafruit.com/products/1119/guides)
![Angled shot of 10 12mm square tactile switch buttons.](https://cdn-shop.adafruit.com/640x480/1119-03.jpg)

We recommend using a breadboard and some female-male wires.

### Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/826)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

In Stock
[Buy Now](https://www.adafruit.com/product/826)
[Related Guides to the Product](https://learn.adafruit.com/products/826/guides)
![Angled shot of Premium Female/Male 'Extension' Jumper Wires - 40 x 6 (150mm)](https://cdn-shop.adafruit.com/640x480/826-04.jpg)

You can use a Cobbler to make this a little easier, the pins are then labeled!

### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3, Pi 4, and Pi 5!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported,...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
![Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable](https://cdn-shop.adafruit.com/640x480/2028-07.jpg)

# Wiring

Connect the Raspberry Pi **Ground** pin to the **blue ground rail** on the breadboard.

- Connect one side of the tactile switch to Raspberry Pi **GPIO #4**
- Connect the other side of the tactile switch to the **ground** rail
- Connect the longer/positive pin of the LED to Raspberry Pi **GPIO #18**
- Connect the shorter/negative pin of the LED to a 470ohm&nbsp; to 2.2K resistor, the other side of the resistor goes to **ground** rail

![](https://cdn-learn.adafruit.com/assets/assets/000/056/791/medium800/sensors_buttonled_bb.png?1530386203)

Double-check you have the right wires connected to the right location, it can be tough to keep track of Pi pins as there are forty of them!

No additional libraries are needed so we can go straight on to the example code

However, we recommend running a pip3 update!

`pip3 install --upgrade adafruit_blinka`

# Blinky Time!

The finish line is right up ahead, lets start with an example that blinks the LED on and off once a second (half a second on, half a second off):

```
import time
import board
import digitalio

print("hello blinky!")

led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
```

Verify the LED is blinking. If not, check that it's wired to GPIO #18, the resistor is installed correctly, and you have a Ground wire to the Raspberry Pi.

Type Control-C to quit

# Button It Up

Now that you have the LED working, lets add code so the LED turns on whenever the button is pressed

```
import time
import board
import digitalio

print("press the button!")

led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.D4)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

while True:
    led.value = not button.value # light when button is pressed!
```

Press the button - see that the LED lights up!

Type Control-C to quit

# CircuitPython Libraries on Linux and Raspberry Pi

## I2C Sensors & Devices

The most popular electronic sensors use _I2C_ to communicate. This is a 'shared bus' 2 wire protocol, you can have multiple sensors connected to the two SDA and SCL pins as long as they have unique addresses ([check this guide for a list of many popular devices and their addresses](https://learn.adafruit.com/i2c-addresses))

Lets show how to wire up a popular BME280. This sensor provides temperature, barometric pressure and humidity data over I2C

We're going to do this in a lot more depth than our guide pages for each sensor, but the overall technique is basically identical for any and all I2C sensors.

Honestly, the hardest part of using I2C devices is [figuring out the I2C address](https://learn.adafruit.com/i2c-addresses) and which pin is SDA and which pin is SCL!

Warning: 

# Parts Used
### Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

[Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure&nbsp;and&nbsp;humidity! This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI!

This precision sensor from...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2652)
[Related Guides to the Product](https://learn.adafruit.com/products/2652/guides)
![small, rectangle-shaped, BME280 temperature humidity pressure sensor breakout board.](https://cdn-shop.adafruit.com/640x480/2652-04.jpg)

We recommend using a breadboard and some female-male wires.

### Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/826)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

In Stock
[Buy Now](https://www.adafruit.com/product/826)
[Related Guides to the Product](https://learn.adafruit.com/products/826/guides)
![Angled shot of Premium Female/Male 'Extension' Jumper Wires - 40 x 6 (150mm)](https://cdn-shop.adafruit.com/640x480/826-04.jpg)

You can use a Cobbler to make this a little easier, the pins are then labeled!

### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3, Pi 4, and Pi 5!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported,...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
![Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable](https://cdn-shop.adafruit.com/640x480/2028-07.jpg)

# Wiring

- Connect the Raspberry Pi **3.3V** power pin to **Vin**
- Connect the Raspberry Pi **GND** pin to **GND**
- Connect the Pi **SDA** pin to the BME280 **SDI** 
- Connect the Pi **SCL** pin to to the BME280 **SCK**

![](https://cdn-learn.adafruit.com/assets/assets/000/056/786/medium800/sensors_bme_bb.png?1530382130)

Double-check you have the right wires connected to the right location, it can be tough to keep track of Pi pins as there are forty of them!

After wiring, we recommend running I2C detection to verify that you see the device, in this case its address **77**

```
sudo i2cdetect -y 1
```
![](https://cdn-learn.adafruit.com/assets/assets/000/056/787/medium800/sensors_test.png?1530382329)

# Install the CircuitPython BME280 Library

OK onto the good stuff, you can now install the Adafruit BME280 CircuitPython library.

As of this writing, not _all_ libraries are up on [PyPI](https://pypi.org/search/?q=circuitpython) so you may want to search before trying to install. Look for **circuitpython** and then the driver you want.

![](https://cdn-learn.adafruit.com/assets/assets/000/056/788/medium800/sensors_search.png?1530382430)

(If you don't see it [you can open up a github issue on circuitpython to remind us](https://github.com/adafruit/circuitpython)!)

Once you know the name, install it with

`pip3 install adafruit-circuitpython-bme280`

![](https://cdn-learn.adafruit.com/assets/assets/000/056/789/medium800/sensors_pipbme.png?1530382544)

You'll notice we also installed a _dependancy_ called **adafruit-circuitpython-busdevice**. This is a great thing about pip, if you have other required libraries they'll get installed too!

We also recommend an adafruit-blinka update in case we've fixed bugs:

`pip3 install --upgrade adafruit_blinka`

# Run that code!

The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.

Check out the examples for your library by visiting the repository for the library and looking in the example folder. In this case, it would be [https://github.com/adafruit/Adafruit\_CircuitPython\_BME280/tree/master/examples](https://github.com/adafruit/Adafruit_CircuitPython_BME280/tree/master/examples)

As of this writing there's only one example. But that's cool, here it is:

https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/main/examples/bme280_simpletest.py

Save this code to your Pi by copying and pasting it into a text file, downloading it directly from the Pi, etc.

Then in your command line run

`python3 bme280_simpletest.py`

![](https://cdn-learn.adafruit.com/assets/assets/000/056/790/medium800/sensors_bmetest.png?1530382809)

The code will loop with the sensor data until you quit with a Control-C

That's it! Now if you want to read the documentation on the library, what each function does in depth, visit our readthedocs documentation at

[https://circuitpython.readthedocs.io/projects/bme280/en/latest/](https://circuitpython.readthedocs.io/projects/bme280/en/latest/)

# CircuitPython Libraries on Linux and Raspberry Pi

## I2C Clock Stretching

In order to use certain I2C sensors, such as the [BNO055](https://www.adafruit.com/product/2472), [BNO085](https://www.adafruit.com/product/4754) and the [CCS811](https://www.adafruit.com/product/3566), you'll need to enable I2C clock stretching 'support' by greatly slowing down the I2C clock on the Raspberry Pi using the device tree overlay.

This is done by adding a line in `/boot/firmware/config.txt`.&nbsp; Log in to a terminal on your Pi and open that file in Nano, or your text editor of choice:

```auto
sudo nano /boot/firmware/config.txt
```

![](https://cdn-learn.adafruit.com/assets/assets/000/059/101/medium800/sensors_Screenshot-2018-08-14-13_06_24.png?1534274110)

Scroll down until you find a block like:

```
# Uncomment some of all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
```

This block might vary depending on what you've enabled in&nbsp;`raspi-config`. Directly below it, add the following:

```
# Clock stretching by slowing down to 10KHz
dtparam=i2c_arm_baudrate=10000
```

Clock stretching is used by certain peripheral devices to signal to the Raspberry Pi to give it more time to respond, but the Raspberry Pi's hardware I2C doesn't support this feature. However, by slowing down the bus speed, it should give the peripheral more time.

The default baudrate may be 100KHz or 1MHz, by slowing it down to 10KHz or more, you may be able to be slow enough to avoid missing clocks.

In Nano, your screen should look like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/069/870/medium800/sensors_image.png?1548367556)

Next, save the file and exit (in Nano, press&nbsp; **Ctrl-X** ,&nbsp; **y** for yes, and&nbsp; **Enter** ).

Now you can reboot your Pi and proceed to testing your I2C device:

```
sudo reboot
```

If you still get bad data, try slowing it down more, maybe to 5 KHz or 1 KHz rate. Reboot after each change

# CircuitPython Libraries on Linux and Raspberry Pi

## SPI Sensors & Devices

SPI is less popular than I2C but still you'll see lots of sensors and chips use it. Unlike I2C, you don't have everything share two wires. Instead, there's three shared wires ( **clock** , **data in** , **data out** ) and then a unique ' **chip select**' line for each chip.

The nice thing about SPI is you can have as many chips as you like, even the same kind, all share the three SPI wires, as long as each one has a unique chip select pin.

The formal/technical names for the 4 pins used are:

- SPI clock - called **SCLK** , **SCK** or **CLK**
- SPI data out - called **MOSI** for **M** icrocomputer&nbsp; **O** ut **S** erial&nbsp; **I** n. This is the wire that takes data _from_ the Linux computer _to_ the sensor/chip. Sometimes marked **SDI** or **DI** on chips
- SPI data in - called **MISO** for **M** icrocomputer **I** n **S** erial&nbsp; **O** ut. This is the wire that takes data _to_ the Linux computer _from_ the sensor/chip. Sometimes marked **SDO** or **DO** on chips
- SPI chip select - called **CS** or **CE**

Remember, connect all SCK, MOSI and MISO pins together (unless there's some specific reason/instruction not to) and a unique CS pin for each device.

Warning: 

SPI on microcontrollers is fairly simple, you have an SPI peripheral and you can transfer data on it with some low level command. Its 'your job' as a programmer to control the CS lines with a GPIO. That's how CircuitPython is structured as well. `busio` does just the SPI transmit/receive part and `busdevice` handles the chip select pin as well.

Linux, on the other hand, doesn't let you send data to SPI without a CS line, and the CS lines are fixed in hardware as well. For example on the Raspberry Pi, there's only two CS pins available for the hardware SPI pins - **CE0** and **CE1** - and you _have_ to use them. (In theory there's an ioctl option called `no_cs` but this does not actually work)

To let you use more than 2 peripherals on SPI, we decided to **let you use any CS pins** you like, CircuitPython will toggle it the way you expect. But when we transfer SPI data we always tell the kernel to use **CE0**. CE0 will toggle like a CS pin, but if we leave it disconnected, its no big deal.

**The upshot here is basically never connect anything to CE0** (or **CE1** for that matter) when using SPI in its default configuration. Use whatever chip select pin you define in CircuitPython and just leave the **CE** pins alone, it will toggle as if it is the chip select line, completely on its own, so you shouldn't try to use it as a digital input/output/whatever.

## Reassigning or Disabling the SPI Chip Enable Lines

There are some add-on boards that use the CE0 and CE1 lines such as the PiTFT, so you don't have much choice in the way it is wired. Fortunately, the Raspberry Pi OS allows you to reassign the Chip Enable lines to some unused pins or even disable them from Operating System usage altogether by loading a Device Tree Overlay, which allows them to be accessible in Python. In order to make this as easy as possible, there's a script to do all the hard work for you.

To run the script, there are a few dependencies that you will need to install first:

```terminal
cd ~
pip3 install --upgrade adafruit-python-shell click
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/main/raspi-spi-reassign.py
```

If you already know the GPIO lines you would like to use, you can pass them in as parameters to the script. For instance, if you want to assign GPIO 5 to CE0 and GPIO 6 to CE1, you can use the following command:

```terminal
sudo -E env PATH=$PATH python3 raspi-spi-reassign.py --ce0=5 --ce1=6
```

Alternatively, you can pass "disabled instead of a number to disable its usage. For instance, to disable the OS from using either Chip enable, you could run the following command:

```terminal
sudo -E env PATH=$PATH python3 raspi-spi-reassign.py --ce0=disabled --ce1=disabled
```

For all features or to run the script interactively, you can just use the following command:

```terminal
sudo -E env PATH=$PATH python3 raspi-spi-reassign.py
```

Warning: 

Warning: 

# Using the Second SPI Port

The Raspberry Pi has a 'main' SPI port, but not a lot of people know there's a second one too! This is handy if you are using the main SPI port for a PiTFT or other kernel-driven device. [You can enable this SPI #1 by adding](https://elinux.org/RPi_SPI)

`dtoverlay=spi1-3cs`

to the bottom of **/boot/config.txt** and rebooting. You'll then see the addition of some /dev/spidev1.x devices.

Here's the wiring for SPI #1:

- **SCK\_1** on GPIO #21
- **MOSI\_1** on GPIO #20
- **MISO\_1** on GPIO #19
- SPI #1 **CS0** on GPIO 18
- SPI #1 **CS1** on GPIO 17
- SPI #1 **CS2** on GPIO 16

like the main SPI, we'll use CE0 as our default but don't connect to it! Use any other pin and leave that one unused. Then update your scripts to use

`spi = busio.SPI(board.SCK_1, MOSI=board.MOSI_1, MISO=board.MISO_1)`

# Parts Used

OK now that we've gone thru the warning, lets wire up an SPI MAX31855 thermocouple sensor, this particular device doesn't have a MOSI pin so we'll not connect it.

### Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade)

[Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade)](https://www.adafruit.com/product/269)
Thermocouples are very sensitive, requiring a good amplifier with a cold-compensation reference. The MAX31855K does everything for you, and can be easily interfaced with any microcontroller, even one without an analog input. This breakout board has the chip itself, a 3.3V regulator with 10uF...

In Stock
[Buy Now](https://www.adafruit.com/product/269)
[Related Guides to the Product](https://learn.adafruit.com/products/269/guides)
![Angled shot of black, square-shaped thermocouple breakout board with a green 2-pin terminal block.](https://cdn-shop.adafruit.com/640x480/269-06.jpg)

### Thermocouple Type-K Glass Braid Insulated

[Thermocouple Type-K Glass Braid Insulated](https://www.adafruit.com/product/270)
Thermocouples are best used for measuring temperatures that can go above 100 °C. This is a bare wires bead-probe which can measure air or surface temperatures. Most inexpensive thermocouples have a vinyl covering which can melt at around 200 °C, this one uses a fiberglass braid so it...

In Stock
[Buy Now](https://www.adafruit.com/product/270)
[Related Guides to the Product](https://learn.adafruit.com/products/270/guides)
![Angled shot of a Thermocouple Type-K Glass Braid Insulated wire. ](https://cdn-shop.adafruit.com/640x480/270-02.jpg)

We recommend using a breadboard and some female-male wires.

### Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/826)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

In Stock
[Buy Now](https://www.adafruit.com/product/826)
[Related Guides to the Product](https://learn.adafruit.com/products/826/guides)
![Angled shot of Premium Female/Male 'Extension' Jumper Wires - 40 x 6 (150mm)](https://cdn-shop.adafruit.com/640x480/826-04.jpg)

You can use a Cobbler to make this a little easier, the pins are then labeled!

### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3, Pi 4, and Pi 5!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported,...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
![Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable](https://cdn-shop.adafruit.com/640x480/2028-07.jpg)

# Wiring

- Connect the Raspberry Pi **3.3V** power pin to **Vin**
- Connect the Raspberry Pi **GND** pin to **GND**
- Connect the Pi **SCLK** pin to the MAX31855 **CLK**
- Connect the Pi **MISO** pin to to the MAX31855 **DO**
- Connect the Pi **GPIO 5** pin to to the MAX31855 **CS**

![](https://cdn-learn.adafruit.com/assets/assets/000/056/793/medium800/sensors_max_bb.png?1530460084)

[Fritzing Diagram](https://cdn-learn.adafruit.com/assets/assets/000/056/795/original/max.fzz?1530483015)
Double-check you have the right wires connected to the right location, it can be tough to keep track of Pi pins as there are forty of them!

# Install the CircuitPython MAX31855 Library

OK onto the good stuff, you can now install the Adafruit MAX31855 CircuitPython library.

As of this writing, not _all_ libraries are up on PyPI so you may want to search before trying to install. Look for **circuitpython** and then the driver you want.

![](https://cdn-learn.adafruit.com/assets/assets/000/056/794/medium800/sensors_max.png?1530483010)

(If you don't see it [you can open up a github issue on circuitpython to remind us](https://github.com/adafruit/circuitpython)!)

Once you know the name, install it with

`pip3 install adafruit-circuitpython-max31855`

![](https://cdn-learn.adafruit.com/assets/assets/000/056/796/medium800/sensors_pipmax.png?1530483140)

You'll notice we also installed a few other _dependancies_ called **spidev** , **adafruit-pureio** , **adafruit-circuitpython-busdevice** and more. This is a great thing about pip, if you have other required libraries they'll get installed too!

We also recommend an adafruit-blinka update in case we've fixed bugs:

`pip3 install --upgrade adafruit_blinka`

# Run that code!

The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.

Check out the examples for your library by visiting the repository for the library and looking in the example folder. In this case, it would be [https://github.com/adafruit/Adafruit\_CircuitPython\_MAX31855/tree/master/examples](https://github.com/adafruit/Adafruit_CircuitPython_MAX31855/tree/master/examples)

As of this writing there's only one example. But that's cool, here it is:

https://github.com/adafruit/Adafruit_CircuitPython_MAX31855/blob/main/examples/max31855_simpletest.py

Save this code to your Pi by copying and pasting it into a text file, downloading it directly from the Pi, etc.

Then in your command line run

`python3 max31855_simpletest.py`

![](https://cdn-learn.adafruit.com/assets/assets/000/056/797/medium800/sensors_maxtest.png?1530483363)

The code will loop with the sensor data until you quit with a Control-C

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/056/798/medium800/sensors_maxtest.png?1530483474)

That's it! Now if you want to read the documentation on the library, what each function does in depth, visit our readthedocs documentation at

[https://circuitpython.readthedocs.io/projects/max31855/en/latest/](https://circuitpython.readthedocs.io/projects/max31855/en/latest/)

# CircuitPython Libraries on Linux and Raspberry Pi

## Using I2C or SPI by Device ID

One of the great things about Linux systems is that each of the subsystems are stored as separate devices and so you can tell if the I2C or SPI device is available by looking in the **/dev/** folder. If your I2C or SPI devices are not showing up, make sure you followed the steps on the **Installing CircuitPython Libraries on Raspberry Pi** page.

In order to maintain a certain level of compatibility with CircuitPython, `busio` was written to attempt to automatically detect which pins you had your I2C or SPI device set up to use. However, with the flexibility that the Raspberry Pi provides and the staggering number of possible pin combinations, there are definitely cases where it fails to detect it properly. This is why we wrote the Python Extended Bus library, which allows you to specify the bus and device ID so you can tell it exactly which device you want to use.

## Installing the Library

Installing the library is easy once you already have Blinka setup. Just use the following command to install:

```terminal
pip3 install adafruit-extended-bus
```

That's it!

## I2C Devices

To use an I2C device, you first need to know the device file name and from that, you can get the ID number. For instance, if you wanted to use **/dev/i2c-1** , the ID number would be **1**.

You would then pass that ID into the Extended I2C Constructor. Here's an example of how to use **/dev/i2c-1** with the BME280 sensor instead of the built-in `busio.I2C` module:

https://github.com/adafruit/Adafruit_Python_Extended_Bus/blob/main/examples/extended_bus_simpletest.py

## SPI Devices

This is less useful than I2C if you only have the first SPI port enabled because in most cases, you can already use any GPIO pin as a Chip Enable line. However, if you have multiple SPI buses enabled, then it becomes much more useful.

To use SPI Devices with this library, it is similar to I2C, but you have a bus and Chip Enable number to determine. The first number is the Bus ID and the second number is the Chip Enable ID. So for instance, if you have a SPI device named **/dev/spidev1.0** that you would like to use, then the **Bus ID** would be **1** and the **Chip Enable ID** would be **0**.

You would then pass that IDs into the Extended SPI Constructor. Here's an example of how to use **/dev/spidev1.0** with the BME280 sensor instead of the built-in `busio.SPI` module. We are using GPIO 5 for the actual Chip Enable in this example.

https://github.com/adafruit/Adafruit_Python_Extended_Bus/blob/main/examples/extended_bus_spi_test.py

# CircuitPython Libraries on Linux and Raspberry Pi

## UART / Serial

After I2C and SPI, the third most popular "bus" protocol used is serial (also sometimes referred to as 'UART'). This is a non-shared two-wire protocol with an RX line, a TX line and a fixed baudrate. The most common devices that use UART are GPS units, MIDI interfaces, fingerprint sensors, thermal printers, and a scattering of sensors.

One thing you'll notice fast is that most linux computers have minimal UARTs, often only 1 hardware port. And that hardware port may be shared with a console.

There are two ways to connect UART / Serial devices to your Raspberry Pi. The easy way, and the hard way.

We'll demonstrate wiring up & using an Ultimate GPS with both methods

### Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates

[Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates](https://www.adafruit.com/product/746)
We carry a few different GPS modules here in the Adafruit shop, but none that satisfied our every desire - that's why we designed this little GPS breakout board. We believe this is the **Ultimate** GPS module, so we named it that. It's got everything you want and...

In Stock
[Buy Now](https://www.adafruit.com/product/746)
[Related Guides to the Product](https://learn.adafruit.com/products/746/guides)
![Angled shot of GPS module breakout.](https://cdn-shop.adafruit.com/640x480/746-11.jpg)

# The Easy Way - An External USB-Serial Converter

By far the easiest way to add a serial port is to use a USB to serial converter cable or breakout. They're not expensive, and you simply plug it into the USB port. On the other end are wires or pins that provide power, ground, RX, TX and maybe some other control pads or extras.

Here are some options, they have varying chipsets and physical designs but all will do the job. We'll list them in order of recommendation.

The first cable is easy to use and even has little plugs that you can arrange however you like, it contains a CP2102

### 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)

The CP2104 Friend is low cost, easy to use, but requires a little soldering, it has an '6-pin FTDI compatible' connector on the end, but all pins are broken out the sides

Both the FTDI friend and cable use classic FTDI chips, these are more expensive than the CP2104 or PL2303 but sometimes people like them!

### FTDI Friend with Micro USB Port + extras

[FTDI Friend with Micro USB Port + extras](https://www.adafruit.com/product/284)
Long gone are the days of parallel ports and serial ports. Now the USB port reigns supreme! But USB is hard, and you just want to transfer your every-day serial data from a microcontroller to computer. What now? Enter the FTDI Friend!

The FTDI Friend is a tweaked out FTDI FT232RL chip...

In Stock
[Buy Now](https://www.adafruit.com/product/284)
[Related Guides to the Product](https://learn.adafruit.com/products/284/guides)
![Angled shot of blue rectangular FTDI breakout board.](https://cdn-shop.adafruit.com/640x480/284-03.jpg)

### FTDI Serial TTL-232 USB Cable

[FTDI Serial TTL-232 USB Cable](https://www.adafruit.com/product/70)
Just about all electronics use TTL serial for debugging, bootloading, programming, serial output, etc. But it's rare for a computer to have a serial port anymore. This is a USB to TTL serial cable, with a FTDI FT232RL usb/serial chip embedded in the head. It has a 6-pin socket at the end...

Out of Stock
[Buy Now](https://www.adafruit.com/product/70)
[Related Guides to the Product](https://learn.adafruit.com/products/70/guides)
![Coiled FTDI Serial TTL-232 USB Cable. ](https://cdn-shop.adafruit.com/640x480/70-03.jpg)

You can wire up the GPS by connecting the following

- **GPS Vin** &nbsp; to **USB**  **5V** or **3V** (red wire on USB console cable)
- **GPS Ground** to **USB Ground** (black wire)
- **GPS RX** to **USB TX** (green wire)
- **GPS TX** to **USB RX** (white wire)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/440/medium800/sensors_usbgps_bb.png?1534651676)

Once the USB adapter is plugged in, you'll need to figure out what the serial port name is. You can figure it out by unplugging-replugging in the USB and then typing `dmesg | tail -10` (or just `dmesg`) and looking for text like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/449/medium800/sensors_image.png?1534653363)

At the bottom, you'll see the 'name' of the attached device, in this case its `ttyUSB0`, that means our serial port device is available at `/dev/ttyUSB0`

# The Hard Way - Using Built-in UART

If you don't want to plug in external hardware to the Pi you _can_ use the built in UART on the RX/TX pins.

**But, if you do this, you'll lose the serial console, so if you're using a PiUART or console cable or HAT that lets you connect directly to the console, that will no longer work and you'll have to use the HDMI+Keyboard or ssh method of running commands!**

This isn't a big deal, in fact the serial login-console isn't even enabled by default on Raspbian anymore, but it's worth a warning!

## Disabling Console & Enabling Serial

Before wiring up, make sure you have disabled the console.

Run **sudo raspi-config** and select the following:

 **Interfacing Options**

![sensors_inter.png](https://cdn-learn.adafruit.com/assets/assets/000/059/443/medium640/sensors_inter.png?1534652467)

 **Serial**

![sensors_inter.png](https://cdn-learn.adafruit.com/assets/assets/000/059/444/medium640/sensors_inter.png?1534652506)

Select **No** on enabling the login shell

![sensors_inter.png](https://cdn-learn.adafruit.com/assets/assets/000/059/445/medium640/sensors_inter.png?1534652537)

Select **Yes** on enabling serial port hardware

![sensors_inter.png](https://cdn-learn.adafruit.com/assets/assets/000/059/446/medium640/sensors_inter.png?1534652574)

Once complete you should have no console and yes on serial interface:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/447/medium800/sensors_image.png?1534652609)

Then **reboot**

Once you've rebooted, you can use the built in UART via `/dev/ttyS0`

Wire the GPS as follows:

- **GPS Vin** &nbsp; to **3.**** 3V** (red wire)
- **GPS Ground** to **Ground** (black wire)
- **GPS RX** to **TX** (green wire)
- **GPS TX** to **RX** (white wire)

![sensors_uartgps_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/059/441/medium640/sensors_uartgps_bb.png?1534652222)

# Install the CircuitPython GPS Library

OK onto the good stuff, you can now install the Adafruit GPS CircuitPython library.

As of this writing, not _all_ libraries are up on PyPI so you may want to search before trying to install. Look for **circuitpython** and then the driver you want.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/451/medium800/sensors_image.png?1534653689)

(If you don't see it [you can open up a github issue on circuitpython to remind us](https://github.com/adafruit/circuitpython)!)

Once you know the name, install it with

`pip3 install adafruit-circuitpython-gps`

You'll notice we also installed a _dependancy_ called **pyserial**. This is a great thing about pip, if you have other required libraries they'll get installed too!

We also recommend an adafruit-blinka update in case we've fixed bugs:

`pip3 install --upgrade adafruit_blinka`

# Run that code!

The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.

Check out the examples for your library by visiting the repository for the library and looking in the example folder. In this case, it would be [https://github.com/adafruit/Adafruit\_CircuitPython\_GPS/tree/master/examples](https://github.com/adafruit/Adafruit_CircuitPython_GPS/tree/master/examples)

Lets start with the simplest, the echo example

https://github.com/adafruit/Adafruit_CircuitPython_GPS/blob/main/examples/gps_echotest.py

 **We'll need to configure this code to work with our UART port name.**

- If you're using a USB-to-serial converter, the device name is _probably_ `/dev/ttyUSB0` - but check `dmesg` to make sure
- If you're using the built-in UART on a Pi, the device name is `/dev/ttyS0` - note that last character is a zero

Comment out the lines that reference `board.TX`, `board.RX` and `busio.uart` and uncomment the lines that `import serial` and define the `serial` device, like so:

```
# Define RX and TX pins for the board's serial port connected to the GPS.
# These are the defaults you should use for the GPS FeatherWing.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
#RX = board.RX
#TX = board.TX

# Create a serial connection for the GPS connection using default speed and
# a slightly higher timeout (GPS modules typically update once a second).
#uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)

# for a computer, use the pyserial library for uart access
import serial
uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000)
```

And update the `"/dev/ttyUSB0"` device name if necessary to match your USB interface

Whichever method you use, you should see output like this, with **$GP**"NMEA sentences" - there probably wont be actual location data because you haven't gotten a GPS fix. As long as you see those **$GP** strings sorta like the below, you've got it working!

![](https://cdn-learn.adafruit.com/assets/assets/000/066/938/medium800/sensors_image.png?1543726216)

# CircuitPython Libraries on Linux and Raspberry Pi

## PWM Outputs & Servos

Adafruit Blinka supports PWMOut! This means you can easily pulse LEDs and control servos from your Raspberry Pi using any GPIO pin! This page will walk you through wiring up an LED and a servo, and provide an example for each.

# Update Adafruit Blinka

Before getting started, make sure you're running the latest version of Adafruit Blinka. If you have not already installed it, run the following:

`pip3 install adafruit-blinka`

If you've previously installed it, you should run a pip3 update:

`pip3 install --upgrade adafruit-blinka`

Once you're certain that you are running the latest version of Adafruit Blinka, you can continue!

# Supported Pins

PWMOut is supported on all GPIO pins on the Raspberry Pi! They are independent, and each can have a different frequency and duty cycle.

# PWM - LEDs

This example will show you how to use PWM to pulse fade an LED.

First, wire up the LED to the Raspberry Pi.

- **LED - (negative)** to **Pi GND**
- **LED + (positive)** to **470Ω resistor**
- **470Ω resistor** to **Pi GPIO5**  

![sensors_Blinka_PWM_RasPi_led_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/093/078/medium640/sensors_Blinka_PWM_RasPi_led_bb.jpg?1594653756)

Double-check you have the right wires connected to the right location, it can be tough to keep track of pins as there are forty of them!

No additional libraries are needed, so we can go straight on to the example code.

Run the following code:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_on_Linux_and_Raspberry_Pi/PWM_LED.py

Verify that the LED is pulsing. If not, check that it's wired to GPIO #5, the resistor is installed correctly, and you have a ground wire to the Raspberry Pi.

Type control-C to quit.

# Servo Control

In order to use servos, we take advantage of `pulseio`. You have two options. You can use the raw `pulseio` calls to set the frequency to 50 Hz and then set the pulse widths. Or, you can use `adafruit_motor` which manages servos for you quite nicely.

This section will cover both options.

Install `adafruit_motor` by running `pip3 install adafruit-circuitpython-motor`

First, wire up a servo to your Raspberry Pi:

- **Servo power (red wire)** to **Raspberry Pi 5V**
- **Servo ground (black/brown wire)** to **Raspberry Pi ground**
- **Servo signal (yellow/white wire)** to **Raspberry Pi GPIO5&nbsp;**

![sensors_Blinka_PWM_RasPi_servo_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/093/080/medium640/sensors_Blinka_PWM_RasPi_servo_bb.jpg?1594655309)

## `pulseio` Servo Control

Run the following code:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_on_Linux_and_Raspberry_Pi/PWM_servo_control.py

The servo should sweep back and forth repeatedly. If it does not, verify your wiring matches the diagram above.

Type control-C to quit.

## `adafruit_motor` Servo Control

Run the following code:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_on_Linux_and_Raspberry_Pi/PWM_motor_servo_control.py

The servo should sweep back and forth in steps. If it does not, verify your wiring matches the diagram above.

Type control-C to quit.

# CircuitPython Libraries on Linux and Raspberry Pi

## Using NeoPixels on the Pi 5 and Pi 500

When the Raspberry Pi 5 came out, it was released on completely different underlying hardware than the previous Raspberry Pi boards. Specifically, it used the RP1 chip to handle pretty much all of the Peripheral IO. This made some of the existing libraries such as RPi.GPIO and the NeoPixels stop working and alternatives needed to be found.

For Blinka, libgpiod was originally used because many of the other supported boards had worked with this library and [with some testing](https://adafruit-playground.com/u/MakerMelissa/pages/comparing-libgpiod-and-gpiozero-speeds-on-the-raspberry-pi-5), I found it to be about 3 times faster than the recommended gpiozero. However, this lacked some crucial features such as PWM. Eventually, I stumbled upon rpi-lgpio, which was basically a wrapper around another library called lgpio, and served as a drop-in replacement for RPi.GPIO and included PWM. Unfortunately, because the RP1 chip remained undocumented, the only option for folks to use NeoPixels was with the [Adafruit\_CircuitPython\_NeoPixel\_SPI](https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI) library and it used the SPI port, so it couldn't be use in conjunction with another SPI device.

However, with the release of the RP1 documentation, a new library was written to make use of the NeoPixels in a similar way to that of the Pi 4, freeing up the SPI port. However, at the time of this writing, changes to allow access to the PIO through the kernel are new and it will require a firmware upgrade, which is generally not recommended under normal circumstances as it hasn't been as thoroughly tested.

Warning: An update to the kernel may be required to run this on older builds.

## Installation

Make sure you already have Blinka installed. After that, you will want to first start by checking the permissions to see if a firmware update is necessary. Type the following:

```terminal
ls -l /dev/pio0
```

If the response is&nbsp;`no such file or directory`, then you will need to update the firmware. Otherwise, you can skip to the library installation step.

![](https://cdn-learn.adafruit.com/assets/assets/000/134/278/medium800/sensors_Screenshot_2024-12-23_at_10.54.25%E2%80%AFAM.png?1734980268)

You can update the firmware by running the following commands:

```terminal
sudo apt update
sudo apt upgrade -y
sudo rpi-eeprom-update -a
```

After updating it, you will need to reboot the pi:

```terminal
sudo reboot
```

## Install the Library

Making sure you have your&nbsp;[virtual environment](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi#setup-virtual-environment-3157129) activated first, you will need to install the **Adafruit\_Blinka\_Raspberry\_Pi5\_Neopixel** library:

```terminal
pip install Adafruit-Blinka-Raspberry-Pi5-Neopixel
```

## Updating Permissions

After installing the necessary items, you will want to check that you have the appropriate permissions. You can check this by running the following command again:

```terminal
ls -l /dev/pio0
```

If it shows that both group and file are owned by root, you will need to update the permissions by adding to the rules file.

![](https://cdn-learn.adafruit.com/assets/assets/000/134/280/medium800/sensors_Screenshot_2024-12-23_at_11.29.29%E2%80%AFAM.png?1734982289)

You can update the rules file, by typing the following:

```terminal
sudo nano /etc/udev/rules.d/99-com.rules
```

Add the following line to the end of the file:

```auto
SUBSYSTEM=="*-pio", GROUP="gpio", MODE="0660"
```

Go ahead and reboot once more. When you type the command to check, it should show **gpio** as one of the items:

![](https://cdn-learn.adafruit.com/assets/assets/000/134/282/medium800/sensors_Screenshot_2024-12-23_at_10.45.48%E2%80%AFAM.png?1734982645)

## Running the Example Code
To get the **led\_animation.py** example code onto your Raspberry Pi, you can use the **wget** command:

```terminal
wget https://raw.githubusercontent.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/refs/heads/main/examples/led_animation.py
```

To run the example, you will need a couple more libraries installed. Making sure you have your [virtual environment activated first](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi#setup-virtual-environment-3157129) (if you get an error, it's likely not activated), install using the following command:

```terminal
pip install adafruit-circuitpython-pixelbuf adafruit-circuitpython-led-animation
```

The example expects your NeoPixels to be connected to pin **D13** , but you can adjust the code to use **any pin** as needed. You may also need to adjust the&nbsp;`number_of_pixels` variable and `byteorder` parameter in the **Pi5Pixelbuf** initializer to match your actual hardware.

Finally, you can run the example with the following command:

```terminal
python led_animation.py
```

You should see a variety of different animations run on the NeoPixels.

# CircuitPython Libraries on Linux and Raspberry Pi

## More To Come!

That's just a taste of what we've got working so far

We're adding more support constantly, so please hold tight and [visit the adafruit\_blinka github repo](https://github.com/adafruit/Adafruit_Blinka) to share your feedback and perhaps even submit some improvements!

If you'd like to contribute, but aren't sure where to start, check out the following guides:

- [Adding a Single Board Computer to PlatformDetect for Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-platformdetect-for-blinka)
- [Adding a Single Board Computer to Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-blinka)

# CircuitPython Libraries on Linux and Raspberry Pi

## CircuitPython & OrangePi

# CircuitPython Libraries on Linux and Raspberry Pi

## CircuitPython & Jetson Nano

# CircuitPython Libraries on Linux and Raspberry Pi

## FAQ & Troubleshooting

There's a few oddities when running Blinka/CircuitPython on Linux. Here's a list of stuff to watch for that we know of!

This FAQ covers all the various platforms and hardware setups you can run Blinka on. Therefore, some of the information may not apply to your specific setup.

## Update Blinka/Platform Libraries

**Most issues can be solved by forcing Python to upgrade to the latest `blinka` / `platform-detect` libraries**. Try running

`sudo python3 -m pip install --upgrade --force-reinstall adafruit-blinka Adafruit-PlatformDetect`

### Getting an error message about 'board' not found or 'board' has no attribute

Somehow you have ended up with either the wrong&nbsp; **board** &nbsp;module or no&nbsp; **board** &nbsp;module at all.

**DO NOT** &nbsp;try to fix this by manually installing a library named&nbsp;`board`. There is&nbsp;[one out there](https://pypi.org/project/board/)&nbsp;and it has nothing to do with Blinka. You will break things if you install that library!

The easiest way to recover is to simply force a reinstall of Blinka with:  
`python3 -m pip install --upgrade --force-reinstall adafruit-blinka`

Additionally, and especially if you are using a more recent version of Python, you may run into this error if you either do not have a Virtual Environment active or setup. See the [Python Virtual Environment Usage on Raspberry Pi](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi) guide for more information or check out the guide's Installation page.

### 
       
       
       
       
       
       
       
       
       
       Mixed SPI mode devices 
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
    

Due to the way we share an SPI peripheral, you cannot have two SPI devices with different 'mode/polarity' on the same SPI bus - you'll get weird data

95% of SPI devices are mode 0, check the driver to see mode or polarity settings. For example:

- [LSM9DS1 is mode 1](https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1/blob/master/adafruit_lsm9ds1.py#L408), please use in I2C mode instead of SPI
- [MAX31865 is phase 1](https://github.com/adafruit/Adafruit_CircuitPython_MAX31865/blob/master/adafruit_max31865.py#L97), try using this on a separate SPI device, or read data twice.

### 
       
       
       
       
       
       
       
       
       
       Why am I getting AttributeError: 'SpiDev' object has no attribute 'writebytes2'? 
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
    

This is due to having an older version of [spidev](https://pypi.org/project/spidev/). You need at least version 3.4. This should have been [taken care of](https://github.com/adafruit/Adafruit_Blinka/blob/8a4686cbc7ebd7f338f64517fa42db4dc5b5c78c/requirements.txt#L6) when you installed Blinka, but in some cases it does not seem to happen.

To check what version of spidev Python is using:

> `$ python3`  
> `Python 3.6.8 (default, Oct 7 2019, 12:59:55) `  
> `[GCC 8.3.0] on linux`  
> `Type "help", "copyright", "credits" or "license" for more information.`  
> `>>> import spidev`  
> `>>> spidev. __version__ `  
> `'3.4'`  
> `>>>`

If you see a version lower then 3.4 reported, then try a force upgrade of spidev with (back at command line):

`sudo python3 -m pip install --upgrade --force-reinstall spidev`

### No Pullup/Pulldown support on some Linux boards or MCP2221

Some Linux boards, for example, AllWinner-based, do not have support to set pull up or pull down on their GPIO. Use an external resistor instead!

### Getting OSError: read error with MCP2221

If you are getting a stack trace that ends with something like:

> `return self._hid.read(64)`  
> `File "hid.pyx", line 122, in hid.device.read`  
> `OSError: read error`

Try setting an environment variable named **BLINKA\_MCP2221\_RESET\_DELAY** to a value of **0.5 or higher**.

Windows:

`set BLINKA_MCP2221_RESET_DELAY=0.5`

Linux:

`export BLINKA_MCP2221_RESET_DELAY=0.5`

This is a value in seconds to wait between resetting the MCP2221 and the attempt to reopen it. The reset is seen by the operating system as a hardware disconnect/reconnect. Different operating systems can need different amounts of time to wait after the reconnect before the attempt to reopen. Setting the above environment variable will override the default reset delay time, allowing it to be increased as needed for different setups.

### 
       
       
       
       
       
       
       
       
       
       Using FT232H with other FTDI devices. 
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
    

Blinka uses the libusbk driver to talk to the FT232H directly. If you have other FTDI devices installed that are using the FTDI VCP drivers, you may run into issues. See here for a possible workaround:

[https://forums.adafruit.com/viewtopic.php?f=19&t=166999](https://forums.adafruit.com/viewtopic.php?f=19&t=166999)

### 
       
       
       
       
       
       
       
       
       
       Getting 

This is probably only an issue for older versions of Windows. If you run into something like this, see this issue thread:

[https://github.com/pyusb/pyusb/issues/120](https://github.com/pyusb/pyusb/issues/120)

which describes copying the 32bit and 64bit DLLs into specific folders. ([example for Win7](https://github.com/pyusb/pyusb/issues/120#issuecomment-322058585))

### 
       
       
       
       
       
       
       
       
       
        Getting 

Check out this issue thread:

[https://github.com/pyusb/pyusb/issues/355](https://github.com/pyusb/pyusb/issues/355 "https://github.com/pyusb/pyusb/issues/355")

which has **lots** of discussion. It is probably worth reading through it all to determine what applies for your setup.&nbsp; Most solutions seem to rely on setting the **DYLD\_LIBRARY\_PATH** environment variable.

This issue thread has further information:

[https://github.com/orgs/Homebrew/discussions/3424](https://github.com/orgs/Homebrew/discussions/3424)

### 
       
       
       
       
       
       
       
       
       
       I can't get neopixel, analogio, audioio, rotaryio, displayio or pulseio to work! 
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
     
       
        
       
    

Some CircuitPython modules like may not be supported.

- Most SBCs do not have analog inputs so there is no `analogio`
- Few SBCs have `neopixel` support so that is only available on Raspberry Pi (and any others that have low level neopixel protocol writing
- Rotary encoders (`rotaryio`) is handled by interrupts on microcontrollers, and is not supported on SBCs at this time
- Likewise `pulseio` PWM support is not supported on many SBCs, and if it is, it will not support a carrier wave (Infrared transmission)
- For display usage, we suggest using python `Pillow` library or `Pygame`, we do not have `displayio` support

We aim to have, at a minimum, `digitalio` and `busio` (I2C/SPI). This lets you use the vast number of driver libraries

For analog inputs,[the MCP3xxx library](https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx) will give you `AnalogIn` objects. For PWM outputs, [try the PCA9685](https://github.com/adafruit/Adafruit_CircuitPython_PCA9685). For audio, use pygame or other Python3 libraries to play audio.

Some libraries, like [Adafruit\_CircuitPython\_DHT](https://github.com/adafruit/Adafruit_CircuitPython_DHT) will try to bit-bang if pulsein isn't available. Slow linux boards (\<700MHz) may not be able to read the pins fast enough), you'll just have to try!

### 
       
       
       
       
       
       
       
       
       
       Help, I'm getting the message 

It looks like **libgpiod** may not be installed on your board.

Try running the command: `sudo apt-get install libgpiod2`

### 
       
       
       
       
       
       
       
       
       
       = v5.5.0

Be sure you have the latest libgpiod.py script and run it with the `-l` or `--legacy` flag:

`sudo python3 libgpiod.py --legacy`

All Raspberry Pi Computers Have:

- 1 x I2C port with **busio** (but clock stretching is not supported in hardware, so you must set the I2C bus speed to 10KHz to 'fix it')
- 2 x SPI ports with **busio** 
- 1 x UART port with **serial** - note this is shared with the hardware console
- **pulseio.pulseIn** using gpiod
- **neopixel** support on a few pins
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_raspberry_pi.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/099/medium640/sensors_raspberry_pi.jpg?1560709288)

Google Coral TPU Dev Boards Have:

- 1 x I2C port with **busio**
- 1 x SPI ports with **busio** 
- 1 x UART port with **serial** - note this is shared with the hardware console
- 3 x PWMOut support
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)

![sensors_google_coral.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/100/medium640/sensors_google_coral.jpg?1560709528)

Orange Pi PC Plus Boards Have:

- 1 x I2C port with **busio**
- 1 x SPI ports with **busio** 
- 1 x UART port with **serial**
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_47688275371_ab6f25d2f2_k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/102/medium640/sensors_47688275371_ab6f25d2f2_k.jpg?1560709858)

Orange Pi R1 Boards Have:

- 1 x I2C port with **busio**
- 1 x SPI port with **busio** 
- 1 x UART port with **serial**
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_orange_pi_r1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/105/medium640/sensors_orange_pi_r1.jpg?1560710441)

ODROID C2 Boards Have:

- 1 x I2C port with&nbsp; **busio**
- No SPI support
- 1 x UART port with **serial** - note this is shared with the hardware console
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_product.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/107/medium640/sensors_product.jpg?1560710758)

DragonBoard 410c Boards Have:

- 2 x I2C port with&nbsp; **busio**
- 1 x SPI port with&nbsp; **busio**
- 1 x UART port with&nbsp; **serial**
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_dragonboard410c.jpg](https://cdn-learn.adafruit.com/assets/assets/000/077/714/medium640/sensors_dragonboard410c.jpg?1562085887)

NVIDIA Jetson Nano Boards Have:

- 2 x I2C port with&nbsp; **busio**
- 2 x SPI ports with **busio**
- 2 x UART port with&nbsp; **serial** &nbsp;- note one of these is shared with the hardware console
- No NeoPixel support
- No AnalogIn support (Use an MCP3008 or similar to add ADC)
- No PWM support (Use a PCA9685 or similar to add PWM)

![sensors_faq_troubleshooting.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/798/medium640/sensors_faq_troubleshooting.jpg?1568157791)

FT232H Breakouts Have:

- 1x I2C port **OR** SPI port with **busio**
- 12x GPIO pins with **digitalio**
- No UART
- No AnalogIn support
- No AnalogOut support
- No PWM support

If you are using [Blinka in FT232H mode](https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h), then keep in mind these basic limitations.

- SPI and I2C can not be used at the same time since they share the same pins.
- GPIO speed is not super fast, so trying to do arbitrary bit bang like things may run into speed issues.
- There are no ADCs.
- There are no DACs.
- UART is not available (its a different FTDI mode)

![sensors_2264-04.jpg](https://cdn-learn.adafruit.com/assets/assets/000/081/745/medium640/sensors_2264-04.jpg?1569886041)

MCP2221 Breakouts Have:

- 1x I2C port with **busio**
- 4x GPIO pins with **digitalio**
- 3x AnalogIn with **analogio**
- 1x AnalogOut with **analogio**
- 1x UART with **pyserial**
- No PWM support
- No hardware SPI support

If you are using Blinka in MCP2221 mode, then keep in mind these basic limitations.

- GPIO speed is not super fast, so trying to do arbitrary bit bang like things may run into speed issues.
- UART is available via `pyserial`, the serial COM port shows up as a second USB device during enumeration

![sensors_mcp2221_small_iso.jpg](https://cdn-learn.adafruit.com/assets/assets/000/086/115/medium640/sensors_mcp2221_small_iso.jpg?1576799406)

# CircuitPython Libraries on Linux and Raspberry Pi

## Resources

```
import time
import random
import board
import busio
import digitalio
from adafruit_apds9960.apds9960 import APDS9960
import adafruit_bme280
import neopixel
import serial

print("hello circuitpy full test!")

led = digitalio.DigitalInOut(board.D24)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.D23)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

i2c = busio.I2C(board.SCL, board.SDA)
apds = APDS9960(i2c)
apds.enable_color = True
last_color = apds.color_data

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
bme_cs = digitalio.DigitalInOut(board.D25)
bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
last_bme = None

neopix = neopixel.NeoPixel(board.D18, 16, brightness=0.1)



uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.1)

while True:
    # digitalio test
    led.value = not button.value # light when button is pressed!

    # I2C + APDS9660 test
    color = apds.color_data
    if color != last_color:
        r, g, b, c = color
        print('Red: {0}, Green: {1}, Blue: {2}, Clear: {3}'.format(r, g, b, c))
        last_color = color

    # SPI + BME test
    bme = (bme280.temperature,  bme280.humidity, bme280.pressure)
    if bme != last_bme:
        print("Temperature: %0.1f C" % bme[0])
        print("Humidity: %0.1f %%" % bme[1])
        print("Pressure: %0.1f hPa" % bme[2])
        last_bme = bme

    # UART read
    line = uart.readline()
    if line:
        print(line.decode('utf-8'))

    # neopixels
    neopix.fill((random.randint(0,255),
                 random.randint(0,255),
                 random.randint(0,255)))

```


## Featured Products

### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
### Raspberry Pi 3 - Model B - ARMv8 with 1G RAM

[Raspberry Pi 3 - Model B - ARMv8 with 1G RAM](https://www.adafruit.com/product/3055)
Did you really think the Raspberry Pi would stop getting better? At this point, we sound like a broken record, extolling on the new Pi’s myriad improvements like we’re surprised that the folks at the Raspberry Pi Foundation are continuously making their flagship board better.&nbsp;...

In Stock
[Buy Now](https://www.adafruit.com/product/3055)
[Related Guides to the Product](https://learn.adafruit.com/products/3055/guides)
### Raspberry Pi Zero W

[Raspberry Pi Zero W](https://www.adafruit.com/product/3400)
If you didn't think that the Raspberry Pi Zero could possibly get any better, then boy do we have a pleasant surprise for you!&nbsp;The new **Raspberry Pi Zero W** offers all the benefits of the Pi Zero v1.3, but with one big difference – **built-in...**

In Stock
[Buy Now](https://www.adafruit.com/product/3400)
[Related Guides to the Product](https://learn.adafruit.com/products/3400/guides)
### Raspberry Pi Zero WH (Zero W with Headers)

[Raspberry Pi Zero WH (Zero W with Headers)](https://www.adafruit.com/product/3708)
If you didn't think that the Raspberry Pi Zero W could possibly get any better, then boy do we have a pleasant surprise for you!&nbsp;The new **Raspberry Pi Zero WH&nbsp;** offers all the benefits of the Pi Zero W, but with one big difference – a **pre-soldered GPIO...**

In Stock
[Buy Now](https://www.adafruit.com/product/3708)
[Related Guides to the Product](https://learn.adafruit.com/products/3708/guides)
### Raspberry Pi 3 Model B+ Starter Pack - Includes a Pi 3 Model B+

[Raspberry Pi 3 Model B+ Starter Pack - Includes a Pi 3 Model B+](https://www.adafruit.com/product/3783)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing&nbsp;_better_! And what could make the Pi 3 better? How about a&nbsp;_faster_&nbsp;processor, 5 GHz WiFi, and updated Ethernet chip with PoE...

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

## Related Guides

- [Adafruit IoT Button with NeoPixel BFF](https://learn.adafruit.com/adafruit-iot-button-with-neopixel-bff.md)
- [Reading QR Codes with the Tiny Code Reader](https://learn.adafruit.com/reading-qr-codes-with-the-tiny-code-reader.md)
- [Adafruit NeoKey 1x4 QT I2C Breakout](https://learn.adafruit.com/neokey-1x4-qt-i2c.md)
- [Using the OPEN INSTALLER Button on circuitpython.org](https://learn.adafruit.com/using-open-installer-on-circuitpython-org.md)
- [Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN](https://learn.adafruit.com/multi-device-lora-temperature-network.md)
- [Cardboard Window Skull With Animated LED Eyes](https://learn.adafruit.com/cardboard-window-skull-animated-led-eyes.md)
- [Generating Text with ChatGPT, Pico W & CircuitPython](https://learn.adafruit.com/generating-text-with-chatgpt-pico-w-circuitpython.md)
- [MagTag Cat Fed Clock](https://learn.adafruit.com/magtag-cat-feeder-clock.md)
- [Adafruit HDC302x Precision Temperature & Humidity Sensor](https://learn.adafruit.com/adafruit-hdc3021-precision-temperature-humidity-sensor.md)
- [Holiday Tree with Feather RP2040 Scorpio](https://learn.adafruit.com/holiday-tree-with-scorpio.md)
- [Adafruit seesaw](https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout.md)
- [Welcome to CircuitPython!](https://learn.adafruit.com/welcome-to-circuitpython.md)
- [Using an IR Remote with a Raspberry Pi Media Center](https://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center.md)
- [ScoutMakes FM Radio Kit](https://learn.adafruit.com/scoutmakes-fm-radio-kit.md)
- [Adding a WiFi Co-Processor to CircuitPython](https://learn.adafruit.com/adding-a-wifi-co-processor-to-circuitpython-esp8266-esp32.md)
