SparkFun Auto pHAT Hookup Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t1176

Contents

Introduction

Introducing, the Auto pHAT! The *perfect GIF(t) to get that HAT moving...

dor-15 GIF

Source: Youtube Doris from Disney's Meet the Robinsons

Terrible pun aside, this product isn't capable of creating DOR-15 (aka Doris), but it will get you started on your robotics adventure.

SparkFun Auto pHAT for Raspberry Pi

SparkFun Auto pHAT for Raspberry Pi

ROB-16328
$32.50
1

This device combines a few of our existing products onto a single pHAT. On the Auto pHAT you will find the following components:

  • Qwiic Motor Driver
  • Rotary Encoder Input
  • A Qwiic connector
  • There are dozens of applicable projects for this product, you can even use it to get started with your rover and robotics applications. Its limits are up to you.

    Required Materials

    The required materials will depend on your project. However, at minimum, users will need:

    Single Board Computers

    Each of the SBCs that we offer have a unique facet that separates it from the others. There is a 40-pin Raspberry Pi compatible header on each of the SBCs.

    NVIDIA Jetson Nano Developer Kit (V3)

    DEV-16271
    14
    Raspberry Pi 3 B+

    Raspberry Pi 3 B+

    DEV-14643
    $35.00
    39
    Raspberry Pi 4 Model B (4 GB)

    Raspberry Pi 4 Model B (4 GB)

    DEV-15447
    $55.00
    19
    Raspberry Pi 4 Model B (2 GB)

    Raspberry Pi 4 Model B (2 GB)

    DEV-15446
    $45.00
    4

    Raspberry Pi 3 A+

    DEV-15139
    4

    Raspberry Pi Zero W (with Headers)

    DEV-15470
    8
    Note: When using the Raspberry Pi 4 with heat sink case, a compatible header that provides enough clearance and interfaces with the Auto pHAT is required.

    SD Cards

    These SD cards in our catalog are tested and known to work with all the models of the Raspberry Pi and the Jetson Nano (excluding the NOOBS card).

    microSD Card with Adapter - 32GB (Class 10)

    microSD Card with Adapter - 32GB (Class 10)

    COM-14832
    $26.95
    1

    microSD Card with Adapter - 64GB (Class 10)

    COM-14833
    Retired

    microSD Card - 16GB (Class 10)

    COM-15051

    SparkFun Noobs Card for Raspberry Pi (16GB)

    COM-15052
    Note: For first time Raspberry Pi users, we recommend using the NOOBS version as it has the required OS pre-installed.

    Power Supplies

    Use the appropriate power supply for the SCB you choose. The battery pack and USB-C cable are specifically for the Auto pHAT to supplement the current draw of the motor driver and servo controller.

    Raspberry Pi Wall Adapter Power Supply - 5.1VDC, 3.0A, 15.3W (USB-C)

    Raspberry Pi Wall Adapter Power Supply - 5.1VDC, 3.0A, 15.3W (USB-C)

    TOL-15448
    $8.00
    7
    Wall Adapter Power Supply - 5.1V DC 2.5A (USB Micro-B)

    Wall Adapter Power Supply - 5.1V DC 2.5A (USB Micro-B)

    TOL-13831
    $8.95
    22
    Power Supply - 5V, 4A

    Power Supply - 5V, 4A

    TOL-15352
    $13.95
    USB 3.1 Cable A to C - 3 Foot

    USB 3.1 Cable A to C - 3 Foot

    CAB-14743
    $5.50
    4

    Low Current Lithium Ion Battery Pack - 2.5Ah (USB)

    TOL-15204
    3 Retired

    Servos

    The Auto pHAT has 4 available servo channels. This is perfect if for users looking to add a pan-tilt bracket for their camera, a claw, or any other servo or PWM related mechanism (like a robotic arm).

    Pan/Tilt Bracket Kit (Single Attachment)

    Pan/Tilt Bracket Kit (Single Attachment)

    ROB-14391
    $7.50
    8

    Standard Gripper Kit A - Channel Mount

    ROB-13174
    4 Retired

    Standard Gripper Kit B - Straight Mount

    ROB-13175
    1 Retired

    Chassis, Motor, and Wheels

    The motor driver on the Auto pHAT has 2 H-Bridge drive channels for DC motors. We recommend the hobby motor with encoder as the Auto pHAT was designed to match the pin layout of this product.

    Hobby Motor - Gear

    Hobby Motor - Gear

    ROB-11696
    $2.10
    4
    Hobby Gearmotor - 140 RPM (Pair)

    Hobby Gearmotor - 140 RPM (Pair)

    ROB-13302
    $5.50
    6
    Hobby Motor with Encoder - Metal Gear (DG01D-E)

    Hobby Motor with Encoder - Metal Gear (DG01D-E)

    ROB-16413
    $7.95
    4
    Micro Gearmotor - 90 RPM (6-12V)

    Micro Gearmotor - 90 RPM (6-12V)

    ROB-12285
    $13.95
    5
    Hobby Gearmotor -  65 RPM (Right Angle, Pair)

    Hobby Gearmotor - 65 RPM (Right Angle, Pair)

    ROB-13258
    $5.50
    2
    Planetary Gearmotor - 140RPM

    Planetary Gearmotor - 140RPM

    ROB-15277
    $6.50
    1
    Note: Users looking to add brushless DC motors, which are usually driven by an ESC, shouldn't be using the H-Bridge. ESCs are controlled through a PWM signal and required a specific power source. The servo/PWM controller may work, but users should also consider the arming process.

    Besides a motor, users will also need a chassis or some kind of structure to assemble all the components on. You can't really call it a vehicle, if all you have is a motor.

    Rover 5 Robot Platform

    ROB-10336
    3 Retired

    Robotics Shield Kit for Arduino - Parallax

    ROB-11494
    1 Retired

    Actobotics Kit - ActoBitty 2

    ROB-13047
    3 Retired

    Circular Robotics Chassis Kit (Three-Layer)

    ROB-14339
    Retired

    GoPiGo Beginner Starter Kit

    ROB-14801
    Retired
    STS-Pi - Build a Roving Robot!

    STS-Pi - Build a Roving Robot!

    DEV-15735
    Retired

    Wheels... these are pretty self explanatory. If you don't have them, then you can't get rolling (or tracks for "track-tion").

    Wheel - 65mm (Rubber Tire, Pair)

    Wheel - 65mm (Rubber Tire, Pair)

    ROB-13259
    $3.50
    2

    Mecanum Wheels - 65mm, (4 Pack)

    ROB-15536
    Retired

    Header

    This is an optional item. For users looking to stack HATs, a header might be required for additional clearance between boards or components.

    Extended GPIO Female Header - 2x20 Pin (16mm/7.30mm)

    Extended GPIO Female Header - 2x20 Pin (16mm/7.30mm)

    PRT-16763
    $2.25
    Extended GPIO Female Header - 2x20 Pin (13.5mm/9.80mm)

    Extended GPIO Female Header - 2x20 Pin (13.5mm/9.80mm)

    PRT-16764
    $2.25
    Note: Users shouldn't use the Raspberry Pi GPIO Tall Header (PRT-14017), as the (male) pins on the header aren't quite long enough to reach into the (female) socket on the Auto pHAT.

    Screw Driver

    To tighten and loosen the screw terminals, users will need a small flathead screw driver. The head will need to be ~1.5mm; anything around 2mm will most likely be too large.

    Tool Kit - Screwdriver and Bit Set

    Tool Kit - Screwdriver and Bit Set

    TOL-10865
    $10.95
    8
    iFixit Essential Electronics Toolkit

    iFixit Essential Electronics Toolkit

    TOL-15256
    $26.95
    1

    Magnetic Screwdriver Set (20 Piece)

    TOL-15003
    1 Retired

    Electric Hobby Screwdriver Set

    TOL-15548
    Retired

    Click the button above to toggle a list of additional accessories that are available from our catalog.

    Peripherals

    For users looking to use the desktop graphical user interface (GUI), they will also need the following:
    • TV, Display, or Monitor
    • Compatible HDMI Cable
    • USB Keyboard and Mouse
    Displays
    For beginners we recommend using a modern TV (i.e. with an HDMI input) or computer monitor, as it will undoubtedly be easier and more intuitive for users to setup.
    Compatible HDMI Cable
    If you don't have an HDMI cable (and possible adapter), these have been tested to work with following Raspberry Pi models:
    Raspberry Pi Zero W model:
    Mini HDMI Cable - 3ft

    Mini HDMI Cable - 3ft

    CAB-14274
    $5.50
    2
    Raspberry Pi 3 A+/B+ models:

    HDMI Cable - 6ft

    CAB-11572
    1 Retired

    Note: If your display doesn't have an HDMI input, you will need to source an appropriate adapter. There are DVI and VGA to HDMI adapters, that will work on older computer monitors. Unfortunately, we don't have any adapters or a list of optional products for more outdated inputs (i.e. RCA, S-video, Component, or coaxial inputs).

    USB Keyboard and Mouse
    If you don't already have a USB keyboard and mouse, we do offer a multimedia keyboard that has been tested as a plug-and-play option for the Raspberry Pi models in our catalog.
    Multimedia Wireless Keyboard

    Multimedia Wireless Keyboard

    WIG-14271
    $29.95 $19.95
    4

    Note: This keyboard is similar to a smaller laptop form factor in the button layout. Users with the Raspberry Pi Zero W models will need an additional USB (OTG) cable.

    SBC Kits

    Additionally, we do offer single board computer kits, which will include some of the accessories first-time users may already need.
    SparkFun DLI Kit for Jetson Nano

    SparkFun DLI Kit for Jetson Nano

    KIT-16308
    $229.95
    6

    SparkFun Raspberry Pi Zero W Basic Kit

    KIT-14298
    5 Retired

    Raspberry Pi 3 B+ Starter Kit

    KIT-15361
    2 Retired

    SparkFun JetBot AI Kit v2.0 Powered by Jetson Nano

    KIT-16390
    1 Retired

    Suggested Reading

    Note: First time Raspberry Pi users should also head over to the Raspberry Pi Foundation website and check out their quickstart guides:

    We have also listed a few additional resources for users to familiarize themselves with the Raspberry Pi:

    Note: First time Nvidia Jetson Nano users should also head over to the Nvidia website and check out their guides and tutorials:

    Below are some of our related tutorials that may be of interest to beginners:

    Logic Levels

    Learn the difference between 3.3V and 5V devices and logic levels.

    I2C

    An introduction to I2C, one of the main embedded communications protocols in use today.

    Serial Terminal Basics

    This tutorial will show you how to communicate with your serial devices using a variety of terminal emulator applications.

    SD Cards and Writing Images

    How to upload images to an SD card for Raspberry Pi, PCDuino, or your favorite SBC.

    Raspberry Pi SPI and I2C Tutorial

    Learn how to use serial I2C and SPI buses on your Raspberry Pi using the wiringPi I/O library for C/C++ and spidev/smbus for Python.

    Headless Raspberry Pi Setup

    Configure a Raspberry Pi without a keyboard, mouse, or monitor.

    Python Programming Tutorial: Getting Started with the Raspberry Pi

    This guide will show you how to write programs on your Raspberry Pi using Python to control hardware.

    How to Use Remote Desktop on the Raspberry Pi with VNC

    Use RealVNC to connect to your Raspberry Pi to control the graphical desktop remotely across the network.

    Hardware Overview

    Below, is an overview of the major hardware components on the Auto pHAT.

    Dimensions

    The overall dimensions of the Auto pHAT are 57mm x 65mm. For more details, users can check out the layout in the Eagle files. The board also features two cut-outs for the camera and display ribbon connections.

    Dimensions
    Dimensions of the Auto pHAT. (Click to enlarge)

    GPIO Connections

    As the Auto pHAT is also intended to integrate with other HATs, it is important to know all of the pin being utilized to avoid conflicts. Below is a layout of all the GPIO pins being utilized by the hardware on the Auto pHAT. (*Click the following links, for more information on the GPIO mapping of the Raspberry Pi or Jetson Nano.)

    GPIO Top
    GPIO header connection on the top of the Auto pHAT.
    GPIO Bottom
    GPIO header connection on the bottom of the Auto pHAT.
    (Click to enlarge)

    Raspberry Pi GPIO Map

    GPIO Pins Standard GPIO layout on the Raspberry Pi.
    Image courtesy of the Raspberry Pi Foundation.

    Power Connections

    Power to the Auto pHAT is supplied through the GPIO pins; both 5V and 3.3V are utilized.

    Pin # GPIO
    1 3.3V
    17 3.3V
    2 5V
    4 5V
    6 GND
    9 GND
    Pin # GPIO
    14 GND
    20 GND
    30 GND
    34 GND
    39 GND

    Qwiic (I2C)

    IMU (I2C)
    Pin # GPIO Function
    3 GPIO 02 (SDA) Qwiic (SDA)
    5 GPIO 03 (SCL) Qwiic (SCL)
    26 GPIO 7 Interrupt


    Encoder (I2C)
    Pin # GPIO Function
    3 GPIO 02 (SDA) Qwiic (SDA)
    5 GPIO 03 (SCL) Qwiic (SCL)
    7 GPIO 4 Interrupt
    Motor Driver (I2C)
    Pin # GPIO Function
    3 GPIO 02 (SDA) Qwiic (SDA)
    5 GPIO 03 (SCL) Qwiic (SCL)
    Servo Controller (I2C)
    Pin # GPIO Function
    3 GPIO 02 (SDA) Qwiic (SDA)
    5 GPIO 03 (SCL) Qwiic (SCL)
    Qwiic Connector
    Pin # GPIO Function
    3 GPIO 02 (SDA) Qwiic (SDA)
    5 GPIO 03 (SCL) Qwiic (SCL)

    Servo Controller

    The servo controller utilizes the same PCA9685 IC used on the Pi Servo pHAT; however, only the first 4 PWM channels are broken out. The PCA9685 provides I2C control over the 16-channels of 12-bit pulse width modulation (PWM); although only the first 4-channels are available on the Auto pHAT. The default I2C address for the servo controller on the Auto pHAT is 0x40.

    PCA9685
    The PCA9685 16-channel PWM controller IC and output headers.

    Characteristic Description
    Operating Voltage (VDD) 2.3 V to 5.5 V (Hardwired: 5V)
    Operating Temperature -40°C to 85°C
    PWM Outputs 16 Totem pole outputs (Default: Open-Drain)
    Sink 25 mA or Source 10 mA (at 5V)
    Shared PWM frequency
    Supports hot insertion
    PWM Frequency 24Hz to 1526 Hz (Default (1Eh): 200Hz)
    PWM Resolution 12-bit (4096 steps of control)
    Duty Cycle 0% to 100% (adjustable)
    Oscillator Internal: 25 MHz (Hardwired)
    External: 50 MHz (max.) input (unavailable)
    I2C Address 8 available hardware configurable addresses
    • Configuration Jumpers: 0x40 to 0x47
    • Default: 0x40
    4 programmable addresses to allow simultaneous groups control of multiple devices:
    • 1- General All Call address.
    • 3- Sub Call addresses.
    Note: For more details on the PCA9685 and its utilization as a servo controller, check out the following hookup guides on the Pi Servo pHATs:

    Pi Servo Hat Hookup Guide

    September 14, 2017

    This hookup guide will show you how to connect and use the Pi Servo Hat in a project.

    Pi Servo pHAT (v2) Hookup Guide

    July 11, 2019

    This hookup guide will get you started with connecting and using the Pi Servo pHAT on a Raspberry Pi.

    Motor Driver

    The motor driver consists of the same PSoC4245 and DRV8835 as the Serial Controlled Motor Driver and Qwiic Motor Driver. The DRV8835 H-Bridge provides two drive outputs, each capable of 1.2A at steady state. The default I2C address for the motor driver on the Auto pHAT is 0x5D.

    PSoc4245 and DRV8835
    The PSoc4245 microcontroller, DRV8835 H-Bridge, and screw terminal outputs.

    Characteristic Description
    Operating Voltage (VDD) 3 V to 11 V (Hardwired: 5V)
    Drive Channels 2 Channels
    Drive Strength 1.5A per channel (max.)
    1.2A (steady state)
    Drive Control 127 levels of control
    Direction inversion on a per motor basis
    Global Drive enable
    I2C Address 10 available hardware configurable addresses
    • Configuration Jumpers: 0x58 to 0x61
    • Default: 0x5D

    Thermal Management

    An important consideration for the motor driver is the thermal load due to the current draw of the motors. In order to dissipate the heat, users can use our Theragrip Thermal Tape to attach Small Heat Sinks across the thermally conductive area on the bottom of the board. As the thermal plane doesn't promote natural convection well, users can add a fan to help dissipate the energy, as well.

    Thermally conductive area
    Thermally conductive area on the bottom of the Auto pHAT.
    Temp to Current Load Curve
    Temperature to total driver load curve.
    (Click to enlarge)

    Note: For more details on the Serial Controller Motor Driver or Qwiic Motor Driver and its utilization, check out the following hookup guides on the Pi Servo pHATs:

    Hookup Guide for the Qwiic Motor Driver

    September 19, 2019

    Drive things "qwiic"-ly with the SparkFun Qwiic Motor Driver!

    Encoder Reader

    At the heart of the encoder reader is an ATtiny84, which is utilized on our pseudo I2C devices. The encoder reader is based off of the Qwiic Twist, but is capable of reading two, separate quadrature encoders. The default I2C address for the servo controller on the Auto pHAT is 0x73.

    ATtiny84 encoder reader
    The ATtiny84 dual encoder reader and screw terminal inputs.

    9-DoF IMU

    The 9-DoF (degree of freedom) IMU is the same ICM20948 IC used on the 9DoF IMU Breakout. It provides 10 unique measurements: 3 axes of acceleration, rotational rate, and magnetic strength data, as well as, internal temperature. Users should note the location of the IMU and the orientation of the axes (labeled on the board), when taking measurements. The default I2C address for the IMU on the Auto pHAT is 0x69.

    ICM20948
    The ICM20948 9-DoF IMU.

    Characteristic Description
    Operating Voltage (VDD) 1.71 V to 3.6 V (Hardwired: 1.8V)
    Operating Temperature -40°C to 85°C
    Gyroscope
    Full Scale Ranges:
    • ±250 dps
    • ±500 dps
    • ±1000 dps
    • ±2000 dps
    Sensitivity:
    • ±(1/131) dps
    • ±(1/65.5) dps
    • ±(1/32.8) dps
    • ±(1/16.4) dps
    Output Data Rate: 562.5, 1125, 9000 Hz
    Accelerometer
    Full Scale Ranges:
    • ±2 G
    • ±4 G
    • ±8 G
    • ±16 G
    Sensitivity:
    • ±(1/16384) G
    • ±(1/8192) G<
    • ±(1/4096) G<
    • ±(1/2048) G<
    Output Data Rate: 562.5, 1125, 4500 Hz
    Magnetometer Full Scale Range: ±4900 µT
    Sensitivity: .15 µT
    Output Data Rate: 100 Hz
    I2C Address 2 hardware configurable addresses:
    • 0x69: Jumper closed (Default)
    • 0x68: Jumper open

    Note: For more details on the ICM-20948 and its utilization as an IMU, check out the following hookup guide:

    SparkFun 9DoF IMU (ICM-20948) Breakout Hookup Guide

    June 27, 2019

    How to use the SparkFun 9DoF ICM-20948 breakout board for your motion sensing projects. This breakout is ideal for wearable sensors and IoT applications.

    Qwiic Connector

    A connector is provided for attaching other Qwiic devices.

    Auto pHAT Qwiic Connector
    Qwiic connector.

    Note: While most of our Qwiic devices should be compatible with a single board computer (SBC), not all have a supported Python package. Users who are unfamiliar with our Qwiic connect system, can check out the video below:

    Hardware Assembly

    Assembly for the Auto pHAT is fairly straight forward. It plugs directly into the GPIO pins of a Raspberry Pi. Most importantly, users need pay attention to the orientation of the pHAT and double check that the pin are lined up properly. below are a few examples for users to follow.

    Auto pHAT on Pi3 Model A+
    Auto pHAT on Raspberry Pi 3 Model A+.
    Auto pHAT on Pi3 Model B
    Auto pHAT on Raspberry Pi 3 Model B.
    (Click images to enlarge)

    Attaching Accessories

    Users will want to attach additional accessories to the Auto pHAT.

    Servos

    Servos are attached to the 3x4 right angle header. The channels and pins are indicated on the top and right of the header, when reading the silk screen. Below is an example with servos connected to channels 0 and 3. Users should pay close attention to the orientation of the servo connector, in order to match up the pin connections properly.

    Servo on channels 0 and 3
    Servos attached to channels 0 and 3.
    Close up of wiring orientation
    Verify that the connector is in the proper orientation.
    (*Hint: The signal wire is the uppermost header.)
    (Click images to enlarge)

    Note: Users who are unfamiliar with servos and their operation should check out our hobby servo and basic servo control tutorials. Additionally, here is a quick reference for common servo wiring colors.

    Hobby Servo Tutorial

    May 26, 2016

    Servos are motors that allow you to accurately control the rotation of the output shaft, opening up all kinds of possibilities for robotics and other projects.

    Basic Servo Control for Beginners

    February 25, 2020

    An introductory tutorial demonstrating several ways to use and interact with servo motors!

    servo cable colors

    Annotated image of servo wiring harness. (Click to enlarge)

    Motors

    DC motors should be connected to the inner screw terminals indicated by MTRA and MTRB on the silk screen. Below, is an example of a pair of motors connected to the Auto pHAT. The orientation of the wires (between 1 or 2) shouldn't matter as the drive direction can be configured in software.

    motors attached
    DC hobby motors (with wheels attached) connected to the Auto pHAT.
    external power through USB-C
    An external power source provided by the USB-C connetor.
    (Click images to enlarge)

    Note: Users unfamiliar with DC motors should check out our motors tutorial.

    Motors and Selecting the Right One

    December 12, 2013

    Learn all about different kinds of motors and how they operate.

    Quadrature Encoders

    Connecting quadrature encoders to the Auto pHAT is relatively simple with the screw terminals. Users should use the silk screen on the board (+, A, B, and -) to match the connections for the encoder. The datasheet for other encoders should be used if the connections aren't apparent or labeled on the product.

    motors attached
    external power through USB-C
    DC motors with encoders connected to the Auto pHAT on a Raspberry Pi 3 Model B and Nvidia Jetson Nano.

    motors attached
    Motor and encoder wiring on the Auto pHAT.

    motors attached
    Cable attachment to DC hobby motor with encoder.

    (Click images to enlarge)

    For the hobby motor with encoder, that is offered in our catalog, pin connections match the Auto pHAT screw terminal layout; with the pin map shown below. (For more details, users can check out the datasheet.)

    motor/encoder pin map
    Pin map for the motor with encoder.

    Note: Users who are unfamiliar with quadrature encoders and their operation should check out our Adventures in Science blog post on encoders.

    Clearance Issues

    Another consideration is the clearance of the pHAT from other components. Users can cover the header and screw terminal through hole pins with an insulator to avoid shorting the pins. Additionally, if the clearance between the pHAT and other components (including things like a the heat sink case for the Raspberry Pi 4) becomes an issue, a header should be used to increase the spacing.

    Note: The details for this section are in progress while we await the arrival of the compatible header.

    Desktop

    To configure the Raspberry Pi for use with the Auto pHAT, the PIXEL desktop is recommended. It will be the most convenient for users, but users can still use other methods like SSH to remotely access the Raspberry Pi. To utilize the desktop, users will need to add peripherals like a monitor and keyboard.

    Desktop setup
    Pi 3 Model B setup to access the PIXEL desktop. (Click to enlarge)

    Software Configuration

    Enable the I2C Bus

    Configuring an OS for the Auto pHAT is relatively simple; the I2C interface will need to be enabled.

    Nvidia Jetson

    The I2C bus on the Nvidia Jetson is enabled by default; no configuration is necessary.

    Raspberry Pi

    On the Raspberry Pi, this is easily accomplished within the Raspberry Pi PIXEL desktop. Using the graphical Raspberry Pi Configuration application from the Preferences menu will be the most user friendly option. Users can also make changes through the console based raspi-config application.

    configuration app

    Raspberry Pi Configuration application. (Click to enlarge)

    raspi-config tool

    From the Interfaces tab, enable the I2C interface. (Click to enlarge)

    Once done, click the OK button. Reboot the Raspberry Pi when prompted.

    Install the Python Packages

    Note: This tutorial assumes you are using the latest version of Python 3. If this is your first time using Python or I2C hardware on a Raspberry Pi, please checkout our tutorial on Python Programming with the Raspberry Pi and the Raspberry Pi SPI and I2C Tutorial.

    We've written a Python packages to easily get setup and utilize the Auto pHAT. There are two methods for installing the Python packages:

    1. Install the all inclusive SparkFun Qwiic Python package.
    2. Independently install the various Python packages:

    The all inclusive SparkFun Qwiic Python package, is recommended as is also installs the required I2C driver as well.

    Note: Don't forget to double check that the hardware I2C connection is enabled on your Raspberry Pi or other single board computer.

    SparkFun Qwiic Package

    This repository is hosted on PyPi as the sparkfun-qwiic package. On systems that support PyPi installation via pip3 (use pip for Python 2) is simple, using the following commands:

    For all users (note: the user must have sudo privileges):

    language:bash
    sudo pip3 install sparkfun-qwiic
    

    For the current user:

    language:bash
    pip3 install sparkfun-qwiic
    

    Upgrading the Python Package

    In the future, changes to the Python package might be made. Updating the installed packages has to be done individually for each package (i.e. sub-modules and dependencies won't update automatically and must be updated manually). For example, with the sparkfun-qwiic-scmd Python package use the following command (use pip for Python 2):

    For all users (note: the user must have sudo privileges):

    language:bash
    sudo pip3 install --upgrade sparkfun-qwiic-scmd
    

    For the current user:

    language:bash
    pip3 install --upgrade sparkfun-qwiic-scmd
    

    Python Package Examples

    Servo Controller

    Documentation and examples for utilizing the servo controller is hosted on ReadtheDocs.

    Note: The tutorials below, include other examples for the utilization of the sparkfun-pi-servo-hat Python package.

    Pi Servo pHAT (v2) Hookup Guide

    July 11, 2019

    This hookup guide will get you started with connecting and using the Pi Servo pHAT on a Raspberry Pi.

    Basic Servo Control for Beginners

    February 25, 2020

    An introductory tutorial demonstrating several ways to use and interact with servo motors!

    Setting Up the Pi Zero Wireless Pan-Tilt Camera

    September 14, 2017

    This tutorial will show you how to assemble, program, and access the Raspberry Pi Zero as a headless wireless pan-tilt camera.

    Demo Example

    This example is pulled from the examples in the ReadtheDocs documentation. It should be used with a 90 degree (range of rotation) servo on channel 0 of the Auto pHAT. It will swing the servo arm between 0° and 90°, in a loop.

    language:python
    #!/usr/bin/env python
    #-----------------------------------------------------------------------
    # Pi Servo Hat - Example 1
    #-----------------------------------------------------------------------
    #
    # Written by  SparkFun Electronics, June 2019
    # Author: Wes Furuya
    #
    # Compatibility:
    #     * Original: https://www.sparkfun.com/products/14328
    #     * v2: https://www.sparkfun.com/products/15316
    # 
    # Do you like this library? Help support SparkFun. Buy a board!
    # For more information on Pi Servo Hat, check out the product page
    # linked above.
    #
    # This program is distributed in the hope that it will be useful, but
    # WITHOUT ANY WARRANTY without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    # General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http:www.gnu.org/licenses/>.
    #
    #=======================================================================
    # Copyright (c) 2019 SparkFun Electronics
    #
    # Permission is hereby granted, free of charge, to any person obtaining
    # a copy of this software and associated documentation files (the
    # "Software"), to deal in the Software without restriction, including
    # without limitation the rights to use, copy, modify, merge, publish,
    # distribute, sublicense, and/or sell copies of the Software, and to
    # permit persons to whom the Software is furnished to do so, subject to
    # the following conditions:
    #
    # The above copyright notice and this permission notice shall be
    # included in all copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    #=======================================================================
    
    """
    This example should be used with a 90 degree (range of rotation) servo
    on channel 0 of the Pi Servo Hat.
    
    The extended code (commented out), at the end of the example could be
    used to test the full range of the servo motion. However, users should
    be wary as they can damage their servo by giving it a position outside
    the standard range of motion.
    """
    
    import pi_servo_hat
    import time
    
    # Initialize Constructor
    test = pi_servo_hat.PiServoHat()
    
    # Restart Servo Hat (in case Hat is frozen/locked)
    test.restart()
    
    # Test Run
    #########################################
    # Moves servo position to 0 degrees (1ms), Channel 0
    test.move_servo_position(0, 0)
    
    # Pause 1 sec
    time.sleep(1)
    
    # Moves servo position to 90 degrees (2ms), Channel 0
    test.move_servo_position(0, 90)
    
    # Pause 1 sec
    time.sleep(1)
    
    # Sweep
    #########################################
    while True:
        for i in range(0, 90):
            print(i)
            test.move_servo_position(0, i)
            time.sleep(.001)
        for i in range(90, 0, -1):
            print(i)
            test.move_servo_position(0, i)
            time.sleep(.001)
    
    #########################################
    # Code below may damage servo, use with caution
    # Test sweep for full range of servo (outside 0 to 90 degrees).
    # while True:
    #     for i in range(-23, 100):
    #         print(i)
    #         test.move_servo_position(0, i)
    #         time.sleep(.001)
    #     for i in range(100, -23, -1):
    #         print(i)
    #         test.move_servo_position(0, i)
    #         time.sleep(.001)
    

    Motor Driver

    Documentation and examples for utilizing the motor driver is hosted on ReadtheDocs.

    Demo Example

    This example is pulled from the examples in the ReadtheDocs documentation. It should be used with a DC motor on MTRA of the Auto pHAT. It will increase and decrease the speed between the 20 and 254 levels, in a loop.

    language:python
    #!/usr/bin/env python
    #-----------------------------------------------------------------------------
    # A simple test to speed up and slow down 1 motor.
    #------------------------------------------------------------------------
    #
    # Written by Mark Lindemer
    # SparkFun Electronics, April 2020
    # 
    # This python library supports the SparkFun Electroncis qwiic 
    # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
    # board computers. 
    #
    # More information on qwiic is at https://www.sparkfun.com/qwiic
    #
    # Do you like this library? Help support SparkFun. Buy a board!
    #
    #==================================================================================
    # Copyright (c) 2019 SparkFun Electronics
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy 
    # of this software and associated documentation files (the "Software"), to deal 
    # in the Software without restriction, including without limitation the rights 
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    # copies of the Software, and to permit persons to whom the Software is 
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all 
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    # SOFTWARE.
    #==================================================================================
    # Example 1
    #
    
    from __future__ import print_function
    import time
    import sys
    import math
    import qwiic_scmd
    
    myMotor = qwiic_scmd.QwiicScmd()
    
    def runExample():
        print("Motor Test.")
        R_MTR = 0
        L_MTR = 1
        FWD = 0
        BWD = 1
    
        if myMotor.connected == False:
            print("Motor Driver not connected. Check connections.", \
                file=sys.stderr)
            return
        myMotor.begin()
        print("Motor initialized.")
        time.sleep(.250)
    
        # Zero Motor Speeds
        myMotor.set_drive(0,0,0)
        myMotor.set_drive(1,0,0)
    
        myMotor.enable()
        print("Motor enabled")
        time.sleep(.250)
    
    
        while True:
            speed = 20
            for speed in range(20,255):
                print(speed)
                myMotor.set_drive(R_MTR,FWD,speed)
                time.sleep(.05)
            for speed in range(254,20, -1):
                print(speed)
                myMotor.set_drive(R_MTR,FWD,speed)
                time.sleep(.05)
    
    if __name__ == '__main__':
        try:
            runExample()
        except (KeyboardInterrupt, SystemExit) as exErr:
            print("Ending example.")
            myMotor.disable()
            sys.exit(0)
    

    Encoder Reader

    Documentation and examples for utilizing the encoder reader is hosted on ReadtheDocs.

    Demo Example

    This example is pulled from the examples in the ReadtheDocs documentation. It should be used with quadrature encoders attached to both ENC1 and ENC2 on the Auto pHAT. It will read and print out the encoder position; the ticker counter range rolls up to 32767 ticks.

    language:python
    #!/usr/bin/env python
    #-----------------------------------------------------------------------------
    # ex1_qwiic_dual_encoder_reader.py
    #
    # Simple Example demonstrating how to read encoder counts for the Qwiic Dual Encoder Reader (as part of the SparkFun Auto pHAT)
    #------------------------------------------------------------------------
    #
    # Written by  SparkFun Electronics, May 2019
    # 
    # This python library supports the SparkFun Electroncis qwiic 
    # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
    # board computers. 
    #
    # More information on qwiic is at https://www.sparkfun.com/qwiic
    #
    # Do you like this library? Help support SparkFun. Buy a board!
    #
    #==================================================================================
    # Copyright (c) 2019 SparkFun Electronics
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy 
    # of this software and associated documentation files (the "Software"), to deal 
    # in the Software without restriction, including without limitation the rights 
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    # copies of the Software, and to permit persons to whom the Software is 
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all 
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    # SOFTWARE.
    #==================================================================================
    # Example 1
    #
    
    from __future__ import print_function
    import qwiic_dual_encoder_reader
    import time
    import sys
    
    def runExample():
    
        print("\nSparkFun Qwiic Dual Encoder Reader   Example 1\n")
        myEncoders = qwiic_dual_encoder_reader.QwiicDualEncoderReader()
    
        if myEncoders.connected == False:
            print("The Qwiic Dual Encoder Reader device isn't connected to the system. Please check your connection", \
                file=sys.stderr)
            return
    
        myEncoders.begin()
    
        while True:
    
            print("Count1: %d, Count2: %s" % (myEncoders.count1, \
                myEncoders.count2, \
                ))
    
            time.sleep(.3)
    
    if __name__ == '__main__':
        try:
            runExample()
        except (KeyboardInterrupt, SystemExit) as exErr:
            print("\nEnding Example 1")
            sys.exit(0)
    

    9-DoF IMU

    Documentation and an example for utilizing the IMU is hosted on ReadtheDocs.

    Demo Example

    This example is pulled from the examples in the ReadtheDocs documentation. It display the raw data in the following order: a_x, a_y, a_z, g_x, g_y, g_z, m_x, m_y, and m_z.

    language:python
    #!/usr/bin/env python
    #-----------------------------------------------------------------------------
    # ex1_qwiic_ICM20948.py
    #
    # Simple Example for the Qwiic ICM20948 Device
    #------------------------------------------------------------------------
    #
    # Written by  SparkFun Electronics, March 2020
    # 
    # This python library supports the SparkFun Electroncis qwiic 
    # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
    # board computers. 
    #
    # More information on qwiic is at https://www.sparkfun.com/qwiic
    #
    # Do you like this library? Help support SparkFun. Buy a board!
    #
    #==================================================================================
    # Copyright (c) 2019 SparkFun Electronics
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy 
    # of this software and associated documentation files (the "Software"), to deal 
    # in the Software without restriction, including without limitation the rights 
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    # copies of the Software, and to permit persons to whom the Software is 
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all 
    # copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    # SOFTWARE.
    #==================================================================================
    # Example 1
    #
    
    from __future__ import print_function
    import qwiic_icm20948
    import time
    import sys
    
    def runExample():
    
        print("\nSparkFun 9DoF ICM-20948 Sensor  Example 1\n")
        IMU = qwiic_icm20948.QwiicIcm20948()
    
        if IMU.connected == False:
            print("The Qwiic ICM20948 device isn't connected to the system. Please check your connection", \
                file=sys.stderr)
            return
    
        IMU.begin()
    
        while True:
            if IMU.dataReady():
                IMU.getAgmt() # read all axis and temp from sensor, note this also updates all instance variables
                print(\
                 '{: 06d}'.format(IMU.axRaw)\
                , '\t', '{: 06d}'.format(IMU.ayRaw)\
                , '\t', '{: 06d}'.format(IMU.azRaw)\
                , '\t', '{: 06d}'.format(IMU.gxRaw)\
                , '\t', '{: 06d}'.format(IMU.gyRaw)\
                , '\t', '{: 06d}'.format(IMU.gzRaw)\
                , '\t', '{: 06d}'.format(IMU.mxRaw)\
                , '\t', '{: 06d}'.format(IMU.myRaw)\
                , '\t', '{: 06d}'.format(IMU.mzRaw)\
                )
                time.sleep(0.03)
            else:
                print("Waiting for data")
                time.sleep(0.5)
    
    if __name__ == '__main__':
        try:
            runExample()
        except (KeyboardInterrupt, SystemExit) as exErr:
            print("\nEnding Example 1")
            sys.exit(0)
    
    Challenge: Now that you are familiar with the basics, flew that robotics muscle. Try to implement a traction control or an anti-lock braking system (ABS) to show off your prowess.

    Troubleshooting

    Raspberry Pi

    For comprehensive information or troubleshooting issues, on the Raspberry Pi, users should check out the Raspberry Pi Foundation website and their forum.

    As a general guideline, users should use the following resources when looking for technical information or assistance that is specifically related to the Raspberry Pi itself:

    1. Raspberry Pi FAQ
    2. Raspberry Pi Beginner's Subforum
    3. Raspberry Pi Documentation and Help Guides
    4. Raspberry Pi Forum

    Nvidia Jetson Nano

    For comprehensive information or troubleshooting issues, on the Nvidia Jetson, users should check out the Nvidia website and their forum.

    As a general guideline, users should use the following resources when looking for technical information or assistance that is specifically related to the Jetson Nano itself:

    1. Jetson Support Resources
    2. Jetson Nano Getting Started Guide
    3. Developer Kit User Manual
    4. Jetson Nano Wiki
    5. Nvidia FAQ
    6. Jetson Forum
    7. Jetpack Documentation

    For users looking for technical assistance, click on the link. There you will find, basic troubleshooting tips and instructions to get started with posting a topic in our forum. Our technical support team will do their best to assist you.

    Resources and Going Further

    Product Information

    Nvidia Jetson Resources:

    Jetson Support Resources

    Raspberry Pi Resources:

    Raspberry Pi Help Guides & Documentation:

    Help Guides:
    Documentation:

    learn.sparkfun.com | CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado