Please note! All the stuff in this guide works and we're improving and working on this code a bunch so be sure to check back for updates!

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. Letting you program in Python and talk to Circuitry like sensors, motors, and LEDs!

CircuitPython on Microcontrollers

For a couple years now we've had CircuitPython for microcontrollers like our SAMD21 series with Feather/Trinket/CircuitPlayground/Metro M0, as well as the ESP8266 WiFi microcontroller, nRF52 bluetooth microcontroller and SAMD51 series.

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 & Jetson Nano

CircuitPython Libraries on Linux & NVIDIA Jetson Nano

The next obvious step is to bring CircuitPython ease of use 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 microcomputers like the Jetson Nano or other 'Linux with GPIO pins available' single board computers.

We'll use a special library called adafruit_blinka (named after Blinka, the CircuitPython mascot) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. For example, on the Jetson Nano we use the python libgpiod bindings. For any I2C interfacing we'll use ioctl messages to the /dev/i2c device. 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 the Jetson Nano.

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 - Jetson.GPIO?

Jetson.GPIO is a pure python hardware interface class for the Jetson Nano. It works just fine for I2C, SPI and GPIO but doesn't work with our drivers as it's a different API

By letting you use CircuitPython libraries on the Jetson Nano via adafruit_blinka, you can unlock all of the drivers and example code we wrote! And you can keep using Jetson.GPIO if you like. 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?

Yep! Blinka can easily be updated to add other boards. We've started with the ones we've got, so we could test them thoroughly. If you have other SBC board you'd like to adapt check out the adafruit_blinka code on github, pull requests are welcome as there's a ton of different Linux boards out there!

Initial Setup

Right now, Blinka only supports the Jetson Nano Dev Kit (because that's the only board we've got for testing).

Install Jetson Nano Developer Kit on your Jetson Nano

We decided to try getting Blinka running in the Jetson Nano Developer Kit because that's the recommended installation available for the Jetson Nano. Other distros could be made to work but you'd probably need to figure out how to detect the platform. Using other operating systems and CircuitPython is your call, we cannot provide support for that.

Due to the size of the Dev Kit Image, you will need at least a minimum of a 16GB SD card.

Download and install the latest Jetson Nano Developer Kit, for example we're using https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write

There's some documentation to get started at https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit

Blinka only supports the Jetson Nano Developer Kit on the Jetson Nano because that's the recommended OS we could find and it's easy to detect which board you have

Preparing the Board

A monitor and keyboard are required to set this board up. A mouse is helpful too.

Wireless Keyboard and Mouse Combo - One USB Port!

PRODUCT ID: 1738
Add a good quality, slim chiclet keyboard as well as an optical mouse to your Raspberry Pi, Beagle Bone Black or other mini-computer with this wireless combo set. Best of all,...
$19.95
IN STOCK

After you burn the image to the SD card, you'll need to install it into the Nano. The card slot is located on the underside of the large heatsink.

Connect a monitor (HDMI or DisplayPort), USB mouse, and keyboard to continue. An End User License Agreement will need to be accepted before you can continue.

As you go through the configuration wizard, take note of the fields your name and your computer's name. These will be your username and hostname for connecting by SSH.

Logging in

Once you have completed the wizard, you can either continue using that, connect a serial console cable, or log in through SSH. We've found the easiest way to connect is through a console cable, wired to the J44 connector and then on your computer, use a serial monitor at 115200 baud.

You can also connect via SSH using either the command prompt on a Mac of Linux computer or using a terminal program such as PuTTY on windows. In either case, you will need your username and hostname from earlier in the setup wizard.

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

PRODUCT ID: 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...
OUT OF STOCK

Connect the RX, TX and ground wires of the console cable like so:

Once powered correctly and with the right SD card you should get a command prompt as the username you selected in the configuration wizard. You may need to press enter if it appears to stop.

Log in to get to a shell

Set your Python install to Python 3 Default

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

  • sudo apt 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.6 2
  • sudo update-alternatives --config python

Of course, change the version numbers if a newer version of Python is distributed.

Update Your Board and Python

Run the standard updates:

sudo apt update

sudo apt 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

Nano, which is very handy for quickly editing python scripts, isn't installed by default. So let's add that

sudo apt install nano

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.

I2C and UART are enabled by default, so you don't need to take any additional steps.

Unfortunately by default the SPI interface is disabled! Enabling SPI requires flashing the board with a separate Ubuntu computer and is beyond the scope of this guide.

Verify you have the I2C devices with the command ls /dev/i2c*

You should see at least one i2c device

You can test to see what I2C addresses are connected by running sudo i2cdetect -r -y 0(on pins 27/28) or sudo i2cdetect -r -y 1 (on pins 3/5)

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

The UART Serial Console on the Jetson Nano is connected to /dev/ttyS0. The UART GPIO Serial Port is connected to /dev/ttyTHS1.

Install Python Libraries

Now you're ready to install all the Python support.

Next, run the following command to install adafruit_blinka:

sudo pip3 install adafruit-blinka

The computer will install a few different libraries such as Adafruit-PureIO (our ioctl-only i2c library),  Jetson.GPIO (for handling GPIO), Adafruit-PlatformDetect (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:

Download: file
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great 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 1 ok!")
i2c = busio.I2C(board.SCL_1, board.SDA_1)
print("I2C 2 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

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 Jetson Nano. We'll extend the example to also show how to wire up a button/switch.

Jetson Nano boards don't have any way to set the pullup/pulldown resistors, so you'll need to use external resistors instead of built-in pullups, whenever it makes sense!
Note that this graphic matches the 2x20 Raspberry Pi pinout but it's upside-down

Parts Used

Any old LED will work just fine as long as it's not an IR LED (you can't see those) and a 220 to 2.2K resistor

Diffused Blue 10mm LED (25 pack)

PRODUCT ID: 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...
$9.95
IN STOCK

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

PRODUCT ID: 2780
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
IN STOCK

Some tactile buttons or switches along with some pull-up resistors:

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

PRODUCT ID: 1119
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but
$2.50
IN STOCK

Through-Hole Resistors - 1.0K ohm 5% 1/4W - Pack of 25

PRODUCT ID: 4294
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
IN STOCK

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

Premium Male/Male Jumper Wires - 40 x 6" (150mm)

PRODUCT ID: 758
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...
$3.95
IN STOCK

Half-size breadboard

PRODUCT ID: 64
This is a cute half size breadboard, good for small projects. It's 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip in the middle and two power rails on both...
$5.00
IN STOCK

Wiring

  • Connect the Jetson Nano Ground pin to the blue ground rail on the breadboard.
  • Connect one side of the tactile switch to Jetson Nano D4 (#7)
  • Connect a ~1K-10K pull up resistor from D4 to 3.3V
  • Connect the other side of the tactile switch to the ground rail
  • Connect the longer/positive pin of the LED to Jetson Nano D18 (#12)
  • Connect the shorter/negative pin of the LED to a 220 ohm-2.2K resistor, the other side of the resistor goes to ground rail

There's no Jetson Nano Fritzing object, so we sub'd a Raspberry Pi in

Double-check you have the right wires connected to the right location, it can be tough to keep track of GPIO 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!

sudo pip3 install --upgrade adafruit_blinka

Blinky Time!

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

Download: file
    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 the resistor is installed correctly, and you have Ground and +3.3v wires to the Jetson Nano. Also, check that the wires are going to the correct GPIO pins. If you are powering the board with an AC adapter, try powering it through the USB port.

Type Control-C to quit

Button It Up

Now that you have the LED working, let's add code so the LED turns on whenever the button is pressed:

Download: file
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
# 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

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)

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 and which pin is SDA and which pin is SCL!

Parts Used

Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

PRODUCT ID: 2652
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure and humidity! This sensor is great for all sorts...
$19.95
IN STOCK

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

Premium Male/Male Jumper Wires - 40 x 6" (150mm)

PRODUCT ID: 758
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...
$3.95
IN STOCK

Half-size breadboard

PRODUCT ID: 64
This is a cute half size breadboard, good for small projects. It's 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip in the middle and two power rails on both...
$5.00
IN STOCK

Wiring

  • Connect the Jetson Nano 3.3V power pin to Vin
  • Connect the Jetson Nano GND pin to GND
  • Connect the Nano SDA (#3) pin to the BME280 SDI
  • Connect the Nano SCL (#5) pin to to the BME280 SCK

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

After wiring, we recommend running I2C detection with sudo i2cdetect -r -y 1 to verify that you see the device, in this case its address 77

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.

(If you don't see it you can open up a github issue on circuitpython to remind us!)

Once you know the name, install it with

sudo pip3 install adafruit-circuitpython-bme280

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:

sudo 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

As of this writing there's only two examples. Here's the first one:

import time

import board
import busio
import adafruit_bme280

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bme_cs = digitalio.DigitalInOut(board.D10)
#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

while True:
    print("\nTemperature: %0.1f C" % bme280.temperature)
    print("Humidity: %0.1f %%" % bme280.humidity)
    print("Pressure: %0.1f hPa" % bme280.pressure)
    print("Altitude = %0.2f meters" % bme280.altitude)
    time.sleep(2)

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

Then in your command line run

sudo python3 bme280_simpletest.py

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

Here's the second example:

"""
Example showing how the BME280 library can be used to set the various
parameters supported by the sensor.
Refer to the BME280 datasheet to understand what these parameters do
"""
import time

import board
import busio
import adafruit_bme280

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bme_cs = digitalio.DigitalInOut(board.D10)
#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)

# Change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
bme280.mode = adafruit_bme280.MODE_NORMAL
bme280.standby_period = adafruit_bme280.STANDBY_TC_500
bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16
bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16
bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1
bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2
# The sensor will need a moment to gather initial readings
time.sleep(1)

while True:
    print("\nTemperature: %0.1f C" % bme280.temperature)
    print("Humidity: %0.1f %%" % bme280.humidity)
    print("Pressure: %0.1f hPa" % bme280.pressure)
    print("Altitude = %0.2f meters" % bme280.altitude)
    time.sleep(2)

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

Then in your command line run

sudo python3 bme280_normal_mode.py

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/

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 Jetson Nano. 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

PRODUCT ID: 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...
$39.95
IN STOCK

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

PRODUCT ID: 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...
OUT OF STOCK

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.

Adafruit CP2104 Friend - USB to Serial Converter

PRODUCT ID: 3309
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...
$5.95
IN STOCK

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 + extras

PRODUCT ID: 284
Note: These use genuine FTDI chips, either we purchase them or they are manufactured to our specifications with the requirement of genuine FTDI chips 10/22/14 -
$14.75
IN STOCK

FTDI Serial TTL-232 USB Cable

PRODUCT ID: 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...
OUT OF STOCK

There is also a GPS module with integrated serial available which works like the GPS breakout connected to the USB to TTL Serial cable.

Adafruit Ultimate GPS with USB - 66 channel w/10 Hz updates

PRODUCT ID: 4279
The Ultimate GPS module you know and love has a glow-up to let it be easily used with any computer, not just microcontrollers! With the built in USB-to-Serial converter, you...
OUT OF STOCK

You can wire up the GPS by connecting the following

  • GPS Vin  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)

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:

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 Jetson Nano you can use the built in UART on the RX/TX pins. Unlike the Raspberry Pi, the Jetson Nano isn't using the RX/TX pins for a console, those are on a different UART peripheral, so you should be good to go!

You can use the built in UART via /dev/ttyTHS1

Wire the GPS as follows:

  • Connect the Jetson Nano +3.3V pin to the Vin pin on the GPS
  • Connect the Jetson Nano Ground pin to the GPS Ground pin
  • Connect the Jetson Nano UART TX (#8) to the GPS RX pin
  • Connect the Jetson Nano UART RX (#10) to the GPS TX pin

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.

(If you don't see it you can open up a github issue on circuitpython to remind us!)

Once you know the name, install it with

sudo 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:

sudo 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

Lets start with the simplest, the echo example:

# Simple GPS module demonstration.
# Will print NMEA sentences received from the GPS, great for testing connection
# Uses the GPS only to send some commands, then reads directly from UART
import time
import board
import busio

import adafruit_gps


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

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

# Create a GPS module instance.
gps = adafruit_gps.GPS(uart)

# Initialize the GPS module by changing what data it sends and at what rate.
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
# the GPS module behavior:
#   https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf

# Turn on the basic GGA and RMC info (what you typically want)
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn on just minimum info (RMC only, location):
#gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn off everything:
#gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Tuen on everything (not all of it is parsed!)
#gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')

# Set update rate to once a second (1hz) which is what you typically want.
gps.send_command(b'PMTK220,1000')
# Or decrease to once every two seconds by doubling the millisecond value.
# Be sure to also increase your UART timeout above!
#gps.send_command(b'PMTK220,2000')
# You can also speed up the rate, but don't go too fast or else you can lose
# data during parsing.  This would be twice a second (2hz, 500ms delay):
#gps.send_command(b'PMTK220,500')

# Main loop runs forever printing data as it comes in
timestamp = time.monotonic()
while True:
    data = uart.read(32)  # read up to 32 bytes
    # print(data)  # this is a bytearray type

    if data is not None:
        # convert bytearray to string
        data_string = ''.join([chr(b) for b in data])
        print(data_string, end="")

    if time.monotonic() - timestamp > 5:
        # every 5 seconds...
        gps.send_command(b'PMTK605')  # request firmware version
        timestamp = time.monotonic()

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 DragonBoard, the device name is /dev/ttyTHS1.

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:

Download: file
# 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!

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 to share your feedback and perhaps even submit some improvements!

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!

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:

No Pullup/Pulldown support on some linux boards

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!

Not all peripherals supported

Some CircuitPython modules like neopixel, analogio, audioio and pulseio may not be supported. 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 will give you AnalogIn objects. For PWM outputs, try the PCA9685. For audio, use pygame or other Python3 libraries to play audio.

Some libraries, like 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!

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)

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
  • pulseio.pulseIn using gpiod
  • No NeoPixel support
  • No AnalogIn support (Use an MCP3008 or similar to add ADC)

Orange Pi PC Plus Boards Have:

  • 1 x I2C port with busio
  • 1 x SPI ports with busio
  • 1 x UART port with serial
  • pulseio.pulseIn using gpiod
  • 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)

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)

Odroid C2 Boards Have:

  • 1 x I2C port with 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)

DragonBoard 410c Boards Have:

  • 2 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)

NVIDIA Jetson Nano Boards Have:

  • 2 x I2C port with busio
  • No SPI support without reflashing the board
  • 2 x UART port with serial - 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)
This guide was first published on Sep 10, 2019. It was last updated on 2019-09-10 23:16:10 -0400.