# CircuitPython Libraries on Linux and Orange 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 Orange Pi

## CircuitPython & OrangePi

https://youtu.be/sATjQRtuFTQ

![](https://cdn-learn.adafruit.com/assets/assets/000/066/945/medium800/linux_sensors_blinkapi.png?1543728072)

## CircuitPython on Linux & Orange 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 its pretty easy to get it working with micro-computers like Orange Pi or other 'Linux with GPIO pins available' single board computers.

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 Orange Pi we use the python **libgpiod** bindings. 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 Orange 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!

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

WiringOP, a modification of WiringPi, is for GPIO usage only, it doesn't work well for various I2C or SPI devices.

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 WiringOP 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.

Danger: 

## What about other Linux SBCs or other Orange Pi's?

Yep! Blinka can easily be updated to add other boards. We've started with the one we've got, so we could test it thoroughly. If you have an OrangePi or other SBC 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!

# CircuitPython Libraries on Linux and Orange Pi

## Orange Pi PC Setup

Warning: 

Once armbian is installed, its easy to tell what board you have, simply **cat /etc/armbian-release** and look for `BOARD_NAME`

![](https://cdn-learn.adafruit.com/assets/assets/000/066/942/medium800/linux_image.png?1543727429)

# Install ARMbian on your Orange Pi

We're only going to be using armbian, other distros could be made to work but you'd probably need to figure out how to detect the platform since we rely on `/etc/armbian-release` existing.

Download and install the latest armbian, for example we're using [https://www.armbian.com/orange-pi-pc-plus/](https://www.armbian.com/orange-pi-pc-plus/)

There's some documentation to get started at [https://docs.armbian.com/User-Guide\_Getting-Started/](https://docs.armbian.com/User-Guide_Getting-Started/)

Danger: 

We've found the easiest way to connect is through a console cable, wired to the debug port, and then on your computer, use a serial monitor at 115200 baud.

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/904/medium640/linux_image.png?1543693832)

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

Once powered correctly and with the right SD card you should get a login prompt

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/899/medium640/linux_image.png?1543693853)

After logging in you may be asked to create a new username, we recommend **pi** - if our instructions end up adding gpio access for the pi user, you can copy and paste em

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/900/medium640/linux_image.png?1543693879)

![](https://cdn-learn.adafruit.com/assets/assets/000/066/901/medium800/linux_image.png?1543650219)

Once installed, you may want to enable mdns so you can `ssh pi@orangepipc` instead of needing to know the IP address:

- `sudo apt-get install avahi-daemon`

then **reboot**

# Install Python and set Python 3 to Default

There's a few ways to do this, we recommend something like this

```terminal
sudo apt-get install -y python3 git python3-pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --config python
```

Of course change the version numbers if newer Python is distributed

# Install libgpiod

libgpiod is what we use for gpio toggling. To install run this command:

```terminal
sudo apt-get install libgpiod2 python3-libgpiod
pip3 install gpiod
```

After installation you should be able to `import gpiod` from within Python3

![](https://cdn-learn.adafruit.com/assets/assets/000/066/903/medium800/linux_image.png?1543693479)

# Update Your Board and Python

Run the standard updates:

`sudo apt-get update`

`sudo apt-get upgrade`

and

`sudo pip3 install --upgrade setuptools`

Update all your python 3 packages with

`pip3 freeze - local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U`

and

`sudo bash`

` pip3 freeze - local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U`

# Enable UART, I2C and SPI

A vast number of our CircuitPython drivers use UART, I2C and SPI for interfacing so you'll want to get those enabled.

You only have to do this _once_ per board but by default all three interfaces are disabled!

Install the support software with

- `sudo apt-get install -y python-smbus python-dev i2c-tools`
- `sudo adduser pi i2c`

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/911/medium640/linux_image.png?1543718323)

Read **/etc/armbian-release** to figure out your board family, in this case its a **sun8i**

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/915/medium640/linux_image.png?1543720686)

Edit **/boot/armbianEnv.txt** and add these lines at the end, adjusting the `overlay_prefix` for your particular board

`overlay_prefix=sun8i-h3overlays=uart3 i2c0 spi-spidevparam_spidev_spi_bus=0`

![](https://cdn-learn.adafruit.com/assets/assets/000/066/935/medium800/linux_image.png?1543725601)

Once you're done with both and have rebooted, verify you have the I2C and SPI devices with the command `ls /dev/i2c* /dev/spi*`

You should see at least one i2c device and one spi device

![](https://cdn-learn.adafruit.com/assets/assets/000/066/918/medium800/linux_image.png?1543720872)

![](https://cdn-learn.adafruit.com/assets/assets/000/066/917/medium800/linux_image.png?1543720838)

You can test to see what I2C addresses are connected by running `sudo i2cdetect -y 0` (on **PA11/PA12** ) or `sudo i2cdetect -y 1` (on **PA18/PA19** )

In this case I do have a sensor on the 'standard' i2c port i2c-0 under address 0x77

![linux_image.png](https://cdn-learn.adafruit.com/assets/assets/000/066/919/medium640/linux_image.png?1543720933)

You can also install WiringOP and then run `gpio readall` to see the MUX status. If you see **ALT3** next to a pin, its a plain GPIO. If you see **ALT4** or **ALT5** , its an SPI/I2C/UART peripheral

![](https://cdn-learn.adafruit.com/assets/assets/000/066/934/medium800/linux_image.png?1543725503)

# Install Python libraries

Now you're ready to install all the python support

Run the following command to install **adafruit\_blinka**

`pip3 install adafruit-blinka```

![](https://cdn-learn.adafruit.com/assets/assets/000/066/920/medium800/linux_sensors_pip.png?1543721039)

The computer will install a few different libraries such as `adafruit-pureio` (our ioctl-only i2c library), `spidev` (for SPI interfacing), `Adafruit-GPIO` (for detecting your board) and of course `adafruit-blinka`

That's pretty much it! You're now ready to test.

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

```
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great a Digital input
pin = digitalio.DigitalInOut(board.PA6)
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 and run at the command line with

`sudo 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/066/921/medium800/linux_image.png?1543722010)

# CircuitPython Libraries on Linux and Orange Pi

## Orange Pi R1 Setup

Warning: 

Once armbian is installed, its easy to tell what board you have, simply **cat /etc/armbian-release** and look for `BOARD_NAME`

![](https://cdn-learn.adafruit.com/assets/assets/000/076/162/medium800/sensors_cat-armbian-release.png?1559106134)

# Install ARMbian on your Orange Pi

We're only going to be using armbian, other distros could be made to work but you'd probably need to figure out how to detect the platform since we rely on `/etc/armbian-release` existing.

Download and install the latest armbian, for example we're using [https://www.armbian.com/orange-pi-r1/](https://www.armbian.com/orange-pi-r1/)

There's some documentation to get started at [https://docs.armbian.com/User-Guide\_Getting-Started/](https://docs.armbian.com/User-Guide_Getting-Started/)

Danger: 

We've found the easiest way to connect is through a console cable, wired to the debug port, and then on your computer, use a serial monitor at 115200 baud. For the Orange Pi R1, you will also need to solder a header for debugging and GPIO access to the Orange Pi R1.

![sensors_orangepir1.png](https://cdn-learn.adafruit.com/assets/assets/000/076/163/medium640/sensors_orangepir1.png?1559106439)

### Color Coded Header for Raspberry Pi

[Color Coded Header for Raspberry Pi](https://www.adafruit.com/product/3907)
Here's a snazzy accessory for your Raspberry Pi Zero or Zero W, a color-coded 2x20 header! This **Color Coded Header** &nbsp;takes the mystery out of your Raspberry Pi's 2x20 pinout. No longer will you stare in confusion at all 40 pins, trying to count out which one you...

In Stock
[Buy Now](https://www.adafruit.com/product/3907)
[Related Guides to the Product](https://learn.adafruit.com/products/3907/guides)
![Color Coded 2x20 Header for Raspberry Pi](https://cdn-shop.adafruit.com/640x480/3907-00.jpg)

# Connecting the GPIO/Debug Header

Because the Orange Pi R1 does not come with any GPIO headers, you will need to solder one in order to connect breakout boards.

## Prepare the header strip:

Cut the strip to length. You will want to make a cut to the side of the blue strip that is closer to the center. After cutting, you should have one piece that is 2x13 pins and another that is 2x7 pins.

![sensors_assembly_1.png](https://cdn-learn.adafruit.com/assets/assets/000/076/170/medium640/sensors_assembly_1.png?1559111923)

![sensors_assembly_2.png](https://cdn-learn.adafruit.com/assets/assets/000/076/171/medium640/sensors_assembly_2.png?1559111963)

## Place the header:

Because the ethernet ports are on the tall side, we found that placing a small object under the header such as a small piece of foam works well.

![sensors_assembly_2b.png](https://cdn-learn.adafruit.com/assets/assets/000/076/174/medium640/sensors_assembly_2b.png?1559112471)

## And Solder!

Be sure to solder all pins for reliable electrical contact.  
  
_(For tips on soldering, be sure to check out our&nbsp;_[_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._

![sensors_assembly_3.png](https://cdn-learn.adafruit.com/assets/assets/000/076/175/medium640/sensors_assembly_3.png?1559112493)

Check your solder joints visually and continue onto the next steps

![sensors_assembly_4.png](https://cdn-learn.adafruit.com/assets/assets/000/076/176/medium640/sensors_assembly_4.png?1559112534)

## You're done!

Continue on to the next steps.

![sensors_assembly_5.png](https://cdn-learn.adafruit.com/assets/assets/000/076/177/medium640/sensors_assembly_5.png?1559112573)

# Logging in using Serial

To log in through serial, you will need to connect a USB to TTL Serial cable up to the Orange Pi. You may also need to install some software. Be sure to check out our&nbsp;[Adafruit's Raspberry Pi Lesson 5. Using a Console Cable](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable)&nbsp;guide. Although it is written for a Raspberry Pi, the drivers and cable connection should be the same.

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

Connect the serial cable's TX (White), RX (Green), and Ground (Black) wires to the 3 pins next to the ethernet ports as shown in the photo and start your terminal program.

![sensors_serial_cable.png](https://cdn-learn.adafruit.com/assets/assets/000/076/380/medium640/sensors_serial_cable.png?1559603196)

Once powered correctly and with the right SD card you should get a login prompt

![sensors_serial_cable_linux.png](https://cdn-learn.adafruit.com/assets/assets/000/076/381/medium640/sensors_serial_cable_linux.png?1559605584)

After logging in you may be asked to create a new username, we recommend **pi** - if our instructions end up adding gpio access for the pi user, you can copy and paste em

![sensors_new_user.png](https://cdn-learn.adafruit.com/assets/assets/000/076/385/medium640/sensors_new_user.png?1559606643)

![](https://cdn-learn.adafruit.com/assets/assets/000/076/386/medium800/sensors_PostLoginScreen.png?1559607082)

Once installed, you may want to enable mDNS so you can `ssh pi@orangepi.local` instead of needing to know the IP address:

- `sudo apt-get install avahi-daemon`

then **reboot**

# Connecting using DHCP and SSH

Another option that you may be available to you is to connect using SSH, or Secure Shell. To connect, you will need to have DHCP, or Dynamic Host Configuration Protocol, enabled and configured on your network and look up the IP address assigned to the Orange Pi R1.

By default, most routers have DHCP enabled and some routers will display all of the hosts connected to them through the web configuration panel. If you are able to retrieve the IP address, then you can connect through SSH.

## MacOS/Linux

Mac and Linux should have SSH installed by default and you can access it by going to the command line and typing `ssh root@192.168.0.25`if the IP address of your Orange Pi is 192.168.0.25.

## Windows

The easiest way to connect with windows is to use a Terminal program called PuTTY from&nbsp;[https://www.putty.org](https://www.putty.org).

You can read more about connecting through SSH in our&nbsp;[Adafruit's Raspberry Pi Lesson 6. Using SSH](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh)&nbsp;guide. Although this is written for Raspberry Pi, the steps should be the same.

# Set your Python install to Python 3 Default

There's a few ways to do this, we recommend something like this

```terminal
sudo apt-get install -y python3 git python3-pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --config python
```

Of course change the version numbers if newer Python is distributed

# Install libgpiod

libgpiod is what we use for gpio toggling. To install run this command:

```terminal
sudo apt-get install libgpiod2 python3-libgpiod
pip3 install gpiod
```

After installation you should be able to&nbsp;`import gpiod`&nbsp;from within Python3

![](https://cdn-learn.adafruit.com/assets/assets/000/076/409/medium800/sensors_libgpiod_import.png?1559609251)

# Install Required pip3 Modules

For the Orange Pi R1, a couple of pip modules are required to smooth out the installation.

Run the following command.

`sudo pip3 install wheel flask```

# Update Your Board and Python

Run the standard updates:

`sudo apt-get update`

`sudo apt-get upgrade`

and

`sudo pip3 install --upgrade setuptools`

Update all your python 3 packages with

`pip3 freeze - local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U`

and

`sudo bash`

`pip3 freeze - local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U`

# Enable UART, I2C and SPI

A vast number of our CircuitPython drivers use UART, I2C and SPI for interfacing so you'll want to get those enabled.

You only have to do this&nbsp;_once_&nbsp;per board but by default all three interfaces are disabled!

Install the support software with

- `sudo apt-get install -y python-smbus python-dev i2c-tools`
- `sudo adduser pi i2c`

![sensors_i2cspisetup.png](https://cdn-learn.adafruit.com/assets/assets/000/076/470/medium640/sensors_i2cspisetup.png?1559663648)

Read&nbsp; **/etc/armbian-release** &nbsp;to figure out your board family, in this case its a&nbsp; **sun8i**

![sensors_armbian-release.png](https://cdn-learn.adafruit.com/assets/assets/000/076/471/medium640/sensors_armbian-release.png?1559663849)

Edit&nbsp; **/boot/armbianEnv.txt** &nbsp;and add these lines at the end, adjusting the&nbsp;`overlay_prefix`&nbsp;for your particular board

`overlay_prefix=sun8i-h3overlays=uart1 i2c0 spi-spidev usbhost2 usbhost3param_spidev_spi_bus=1`

![](https://cdn-learn.adafruit.com/assets/assets/000/076/477/medium800/sensors_armbianEnv.png?1559674398)

Once you're done with both and have rebooted, verify you have the I2C and SPI devices with the command&nbsp;`ls /dev/i2c* /dev/spi*`

You should see at least one i2c device and one spi device

![](https://cdn-learn.adafruit.com/assets/assets/000/076/479/medium800/sensors_i2c-device-list.png?1559675376)

![](https://cdn-learn.adafruit.com/assets/assets/000/076/480/medium800/sensors_i2c-device-details.png?1559675485)

You can test to see what I2C addresses are connected by running&nbsp;`sudo i2cdetect -y 0`(on&nbsp; **PA11/PA12** )

In this case I do have a sensor on the 'standard' i2c port i2c-0 under address 0x77

![sensors_i2cdetect.png](https://cdn-learn.adafruit.com/assets/assets/000/076/481/medium640/sensors_i2cdetect.png?1559675696)

You can also install WiringOP-Zero and then run&nbsp;`gpio readall`&nbsp;to see the MUX status. If you see&nbsp; **ALT3&nbsp;** next to a pin, it's a plain GPIO. If you see&nbsp; **ALT4** &nbsp;or&nbsp; **ALT5** , its an SPI/I2C/UART peripheral

![](https://cdn-learn.adafruit.com/assets/assets/000/076/546/medium800/sensors_gpio_readall.png?1559925030)

# Install Python libraries

Now you're ready to install all the python support

Run the following command to install&nbsp; **adafruit\_blinka**

`sudo pip3 install adafruit-blinka`

![](https://cdn-learn.adafruit.com/assets/assets/000/076/485/medium800/sensors_install_blinka.png?1559681350)

The computer will install a few different libraries such as&nbsp;`adafruit-pureio`&nbsp;(our ioctl-only i2c library),&nbsp;`spidev`&nbsp;(for SPI interfacing),&nbsp;`Adafruit-GPIO`&nbsp;(for detecting your board) and of course&nbsp;`adafruit-blinka`

That's pretty much it! You're now ready to test.

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

```
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great a Digital input
pin = digitalio.DigitalInOut(board.PA6)
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 and run at the command line with

`sudo 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/076/487/medium800/sensors_test.png?1559681480)

# CircuitPython Libraries on Linux and Orange 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 Orange Pi. We'll extend the example to also show how to wire up a button/switch.

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/066/941/medium800/linux_lzt4s.png?1543727298)

# 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 will be labeled according to Raspberry Pi names so just check the Orange Pi name!

### 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!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

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 Orange Pi **Ground** pin to the **blue ground rail** on the breadboard.

- Connect one side of the tactile switch to Orange Pi **GPIO PA6**
- Connect a ~10K pull up resistor from **PA6** to **3.3V**
- Connect the other side of the tactile switch to the **ground** rail
- Connect the longer/positive pin of the LED to Orange Pi **GPIO PD14**
- 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

There's no Orange Pi PC Fritzing object, so we sub'd a Raspberry Pi in

![](https://cdn-learn.adafruit.com/assets/assets/000/076/923/medium800/sensors_odroidgpio_bb.png?1560281218)

[orangepigpio.fzz](https://cdn-learn.adafruit.com/assets/assets/000/076/924/original/orangepigpio.zip?1560281233)
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.PD14)
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 PD14, the resistor is installed correctly, and you have a Ground wire to the Orange 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.PD14)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.PA6)
button.direction = digitalio.Direction.INPUT
# use an external pullup since we don't have internal PU's
#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 Orange 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!

Danger: 

# 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!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

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 Orange Pi **3.3V** power pin to **Vin**
- Connect the Orange Pi **GND** pin to **GND**
- Connect the Pi **SDA** pin to the BME280 **SDI**
- Connect the Pi **SCL** pin to to the BME280 **SCK**

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/066/922/medium800/linux_sensors_bme_bb.png?1543722117)

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 with `sudo i2cdetect -y 0` to verify that you see the device, in this case its address **77**

![](https://cdn-learn.adafruit.com/assets/assets/000/066/923/medium800/linux_image.png?1543722169)

# 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 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/066/924/medium800/linux_sensors_search.png?1543722202)

(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/066/925/medium800/linux_sensors_pipbme.png?1543722227)

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/066/926/medium800/linux_image.png?1543722352)

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 Orange 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** icrocontroller **O** ut **S** erial **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** icrocontroller **I** n **S** erial **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.

Danger: 

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 Orange Pi PC, there's only one CS pins available for the hardware SPI pins - **SPI\_CS** known as **PC3** - and you _have_ to use it. (In theory there's an ioctl option called `no_cs` but this does not actually work)

The upshot here is - to let you use more than 1 peripheral 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 **SPI\_CS**.&nbsp; **SPI\_CS** 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&nbsp;**** SPI\_CS **. Use whatever chip select pin you define in CircuitPython and just leave the** CS** pin 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.

Warning: 

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

Out of 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...

Out of 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!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

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 Orange Pi **3.3V** power pin to **Vin**
- Connect the Orange 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 PA7** pin to to the MAX31855 **CS**

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/066/927/medium800/linux_sensors_max_bb.png?1543722604)

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/066/928/medium800/linux_sensors_max.png?1543722770)

(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/066/929/medium800/linux_sensors_pipmax.png?1543722784)

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.

Change the line that says

`cs = digitalio.DigitalInOut(board.D5)`

to

`cs = digitalio.DigitalInOut(board.PA7)`

Then in your command line run

`python3 max31855_simpletest.py`

![](https://cdn-learn.adafruit.com/assets/assets/000/066/930/medium800/linux_sensors_maxtest.png?1543724762)

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

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/066/931/medium800/linux_sensors_maxtest.png?1543724777)

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 Orange 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 Orange 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...

In 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/066/932/medium800/linux_sensors_usbgps_bb.png?1543724837)

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/066/933/medium800/linux_sensors_image.png?1543724854)

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. Unlike the Raspberry Pi, the Orange Pi isn't using the RX/TX pins for a console, those are on a different UART peripheral, so as long as you've activated UART3 (see the Install page) you should be good to go!

You can use the built in UART via `/dev/ttyS3`

Wire the GPS as follows:

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/066/936/medium800/linux_sensors_uartgps_bb.png?1543725745)

# 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/066/937/medium800/linux_sensors_image.png?1543725798)

(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 pyserial 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 the Orange Pi PC, the device name is `/dev/ttyS3` 

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/939/medium800/linux_image.png?1543726284)

# CircuitPython Libraries on Linux and Orange 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 Orange 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)


## Related Guides

- [Your Very First Circuit Sculpture](https://learn.adafruit.com/first-simple-circuit-sculpture.md)
- [Purple Air AQI Display](https://learn.adafruit.com/purple-air-aqi-display.md)
- [PyPortal Halloween Countdown](https://learn.adafruit.com/pyportal-halloween-countdown.md)
- [Using the RockBLOCK Iridium Modem](https://learn.adafruit.com/using-the-rockblock-iridium-modem.md)
- [A Sillier Mousetrap: Logging Mouse Data to Adafruit IO with the Raspberry Pi](https://learn.adafruit.com/a-sillier-mousetrap-logging-mouse-data-to-adafruit-io-with-the-raspberry-pi.md)
- [Light Up your Costume with Noods](https://learn.adafruit.com/light-up-your-costume-with-noods.md)
- [Mario Magic Wand](https://learn.adafruit.com/mario-magic-wand.md)
- [Adafruit SensorLab - Gyroscope Calibration](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration.md)
- [Motion-Activated Solder Fume Extractor With Lamp](https://learn.adafruit.com/motion-activated-solder-fume-extractor-with-lamp.md)
- [Using micro:bit and CRICKIT with MicroPython](https://learn.adafruit.com/using-micro-bit-and-crickit-with-micropython.md)
- [Commodore Keyboard to USB HID with CircuitPython](https://learn.adafruit.com/commodore-keyboard-to-usb-hid-with-circuitpython.md)
- [Smart Bathroom App](https://learn.adafruit.com/smart-bathroom-app.md)
- [Sketch Drawing Toy with CircuitPython](https://learn.adafruit.com/sketch-drawing-toy.md)
- [Bluetooth CLUE Robot Car using CircuitPython](https://learn.adafruit.com/bluetooth-clue-robot-car-using-circuitpython.md)
- [Where's My Friend? A Location-Aware Display with PyPortal and ItsASnap](https://learn.adafruit.com/where-s-my-friend-a-location-display-frame-with-pyportal.md)
