Qwiic pHAT Extension for Raspberry Pi 400 Hookup Guide

Pages
Contributors: bboyho, Elias The Sparkiest
Favorited Favorite 1

Introduction

The SparkFun Qwiic pHAT extension for the Raspberry Pi 400 is the quick and easy solution to access the GPIO, stack your favorite pHAT right-side up, or connect a Qwiic-enabled device to the I2C bus (GND, 3.3V, SDA, and SCL).

SparkFun Qwiic pHAT Extension for Raspberry Pi 400

SparkFun Qwiic pHAT Extension for Raspberry Pi 400

DEV-17512
$5.50

Required Materials

To follow along with this tutorial, you will need the following materials. You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

Raspberry Pi 400

You'll need a Raspbery Pi 400s. There are two options available. One that is just the Raspberry Pi 400 sold individually. Another that is sold in a kit with everything but the monitor.

Raspberry Pi 400 Personal Computer Kit

Raspberry Pi 400 Personal Computer Kit

KIT-17377
$100.00
43
Raspberry Pi 400 Personal Computer (Unit Only)

Raspberry Pi 400 Personal Computer (Unit Only)

DEV-17376
$70.00
6

Qwiic-Enabled Device

Now you probably didn't buy the Qwiic pHAT extension if you didn't have any Qwiic products to use with it, right? If you don't have any Qwiic products, the following might not be a bad place to start since they have a Python drivers written for the devices.

SparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)

SparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)

SEN-15335
$18.50
6
SparkFun GPS Breakout - XA1110 (Qwiic)

SparkFun GPS Breakout - XA1110 (Qwiic)

GPS-14414
$34.95
6
SparkFun Proximity Sensor Breakout - 20cm, VCNL4040 (Qwiic)

SparkFun Proximity Sensor Breakout - 20cm, VCNL4040 (Qwiic)

SEN-15177
$7.50
1

SparkFun Environmental Combo Breakout - CCS811/BME280 (Qwiic)

SEN-14348
20 Retired

You'll need our handy Qwiic cables to easily connect sensors to your Qwiic pHAT. Below are a few options.

Qwiic Cable - 100mm

Qwiic Cable - 100mm

PRT-14427
$1.50
Qwiic Cable - 50mm

Qwiic Cable - 50mm

PRT-14426
$0.95

Qwiic Cable - 200mm

PRT-14428
Retired

Qwiic Cable - 500mm

PRT-14429
1 Retired

Required Setup Tools

As a desktop, these devices are required. If you received the Raspberry Pi 400 Kit, you'll just need a display and cable. Depending on your display, you may need an HDMI converter to connect to older monitors and TVs.

Suggested Reading

If you aren't familiar with the Qwiic system, we recommend reading here for an overview.

Qwiic Connect System
Qwiic Connect System

We would also recommend taking a look at the following tutorials if you aren't familiar with them.

Serial Peripheral Interface (SPI)

SPI is commonly used to connect microcontrollers to peripherals such as sensors, shift registers, and SD cards.

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.

Raspberry gPIo

How to use either Python or C++ to drive the I/O lines on a Raspberry Pi.

Hardware Overview

2x20 Raspberry Pi Header

The Qwiic pHAT extension connects to the Raspberry Pi 400's 2x20 port via the right angle header.

Right Angle 2x20 Header

The Raspberry Pi 400's horizontal headers are rerouted and extends out to the vertical headers at the top of the board. Each pin includes a label with their associated pin function.

Vertical Header Pins with Labels

Qwiic Connectors

The Qwiic pHAT extension includes Qwiic connectors on both sides of the board.

Qwiic Connectors

Mounting Holes

There are 10 mounting holes on the board. Below is the board highlighted for boards designed with the Pi Zero footprint. You can add standoffs to the mounting holes where the arrows are pointing.

Mounting Holes for pHATs with Pi Zero Footprint

For boards designed with the Raspberry Pi footprint, you can add standoffs to the mounting holes where the arrows are pointing.

Mounting Holes with Raspberry Pi Footprint

For Qwiic-enabled devices utilizing the standard 1.0"x1.0" sized boards, you can add two standoffs for each Qwiic-enabled device where the arrows are pointing.

Mounting Holes for Standard Sized 1.0"x1.0" Qwiic-Enabled Device

Board Dimensions

The board is about 65mm x 78.42mm (~2.55in x ~3.08in).

Board Dimensions

By adding two large silicone bumpers under the board for stability, the height comes to about ~21.32mm (~0.84in) between the header pin and the bottom of the Silicon bumper.

Hardware Assembly

Included with the Qwiic pHAT extension board is a set of large silicone bumpers. These are meant to hold the board up when it is attached to a Raspberry Pi 400 and placed on a table. You only need 2 out of the 4 silicone bumpers so you can use the left over bumpers for other projects.

Large Silicone Bumpers

To attach the two silicone bumpers, peel one bumper and attach it to the bottom of the board between the mounting holes of the Pi Zero's footprint. Repeat for the second bumper. Your setup should look similar to the image below.

Large Silicone Bumpers Attached to the Bottom of the Qwiic pHAT Extension Board

At this point, we'll assume that you have flashed an image and inserted the microSD card into the Raspberry Pi 400. With the straight header pins facing up, slide the Qwiic pHAT extension into the Raspberry Pi 400's GPIO port. The right angle connector is keyed so there's only one way to insert the board into the GPIO port.

Qwiic pHAT Extension being Inserted into a Raspberry Pi 400

When removing the pHAT extension, simply wiggle the board slowly up and down as the board is being pulled away from the Raspberry Pi 400.

Qwiic-Enabled Devices

If you have a Qwiic-enabled device, simply insert a Qwiic cable of your choice between the Qwiic board and the Qwiic pHAT extension. While you can connect to either Qwiic connector, the right side of the Qwiic pHAT extension will provide more space since most of the Pi's peripherals will be inserted to the left of the board.

Qwiic-Enabled Device Connected to the Qwiic pHAT Extension

Breadboard Prototyping

Connecting to the Raspberry Pi 400's GPIO is easy with the pin functions printed on the board for reference. We recommend using M/F jumper wires to connect when prototyping your circuit on a breadboard.

Prototyping on a Breadboard using the Qwiic pHAT Extension

Stacking pHATs

Boards designed with the Raspberry Pi or Pi Zero footprint can be stacked on top of the Qwiic pHAT Extension allowing it to be viewed right-side up. Below is an image of the Top pHAT connected to the Raspberry Pi 400.

Top pHAT Stacked on the

Depending on the design of the pHAT, you may require additional height if there are any wires being attached to the bottom of the pHAT. If this is the case, you can add additional height using an extended GPIO headers.

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

Mounting with Standoffs

You can attach standoffs to two of the Qwiic mounting holes to secure an Qwiic-enabled device.

Qwiic 9DoF secured to the Qwiic pHAT Extension

Got a wobbly pHAT on the Qwiic pHAT extension? You can attach standoffs to two of the mounting holes across from the vertical header pins on the Qwiic pHAT extension. Of course, you can always use all four mounting holes depending on your personal preference. Below is a Top pHAT using the Raspberry Pi's footprint but you can also mount a board that uses a Raspberry Pi Zero's footprint as well.

pHAT secured to the Qwiic pHAT Extension

Raspberry Pi 400 Peripherals

If you have not already, connect your peripherals (e.g. display cable, mouse, power, etc) to the Raspberry Pi 400! Your setup will look similar to the image below.

Peripherals Connected to the Raspberry Pi 400

Getting an OS

We recommend checking out the Raspberry Pi 4 Hookup Guide to install the operating system to flash the image to your microSD card for detailed instructions.

Raspberry Pi 4 Kit Hookup Guide

March 14, 2020

Guide for hooking up your Raspberry Pi 4 Model B basic, desktop, or hardware starter kit together.

If you're starting from scratch with a blank microSD card, you'll want to install Raspbian. If you've already got a working Raspbian system, skip ahead to the next section. Be patient — each of these steps can take a while depending on the speed of your microSD card.

  1. Download an Image — Download your favorite Linux distribution. For beginners, we recommend getting NOOBS image.
  2. Flashing the Image — Follow the instructions from the Raspberry Pi 4 Kit Hookup Guide to flash your microSD card. You can also follow the official Raspberry Pi installation instructions.

Configuring the Pi

The peripherals are not turned on by default. For those using Qwiic-enabled devices, you will want to enable I2C port. There are two methods to adjust the settings. This is outlined in our Raspberry Pi I2C tutorial.

Raspberry Pi SPI and I2C Tutorial

October 29, 2015

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.

We've included the following instructions from the tutorial. To enable it, follow the steps below.

Raspberry Pi Configuration via Desktop GUI

You can use the Desktop GUI by heading to the Pi Start Menu > Preferences > Raspberry Pi Configuration.

Raspberry Pi Configuration via GUI

Click on image for a closer view.

A window will pop up with different tabs to adjust settings. What we are interested is the Interfaces tab. Click on the tab and select Enable for I2C. At this point, you can enable additional interfaces depending on your project needs. Click on the OK button to same.

Adjusting Interfaces via Interface Tab

Click on image for a closer view.

We recommend restarting your Pi to ensure that the changes to take effect. Click on the Pi Start Menu > Preferences > Shutdown. Since we just need to restart, click on the Restart button.

Shutdown Turn Off, Restart, Log Off

Click on images for a closer view.

raspi-config Tool via Terminal

Again, we can use raspi-config to enable it.

  1. Run sudo raspi-config.
  2. Use the down arrow to select 5 Interfacing Options
  3. Arrow down to P5 I2C.
  4. Select yes when it asks you to enable I2C
  5. Also select yes if it asks about automatically loading the kernel module.
  6. Use the right arrow to select the <Finish> button.
  7. Select yes when it asks to reboot.

Enabling I2C on the Raspberry Pi

Raspi-config for I2C

The system will reboot. When it comes back up, log in and enter the following command

language:bash
ls /dev/*i2c*

The Pi should respond with

language:bash
/dev/i2c-1

Which represents the user-mode I2C interface.

Scanning for I2C Devices

If you are using the Raspberry Pi to quickly connect to I2C devices, the best place to start would be to scan for an I2C device on the bus.

Utilities

There is a set of command-line utility programs that can help get an I2C interface working. You can get them with the apt package manager. Enter the following command.

language:bash
sudo apt-get install -y i2c-tools

In particular, the i2cdetect program will probe all the addresses on a bus, and report whether any devices are present. Enter the following command in the command line. The -y flag will disable interactive mode so that you do not have to wait for confirmation. The 1 indicates that we are scanning for I2C devices on I2C bus 1 (e.g. i2c-1).

language:bash
i2cdetect -y 1

You will get an output from your Raspberry Pi similar to the output below.

language:bash
pi@raspberrypi:~/$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

This map indicates that there is a peripheral at address 0x60. Your address may vary depending on what is connected to the I2C bus. For advanced users, you can try to read and write its registers using the i2cget, i2cset and i2cdump commands.

Qwiic Py Drivers

Now that you have I2C set up on your Pi, you can start programming your Qwiic devices on your Pi or if you'd like to start with some examples, we have a host of Python drivers for Qwiic breakouts available in the GitHub repository linked below. You can read more about Python for the SparkFun Qwiic system in this blog post.

GPIO Pins

The Raspberry Pi 400 uses the standard 2x20 GPIO pins. With the help of the Qwiic pHAT extension, the Pi 400's horizontal GPIO pins are rerouted to a vertical position. There are several programming languages available to use on the Raspberry Pi. We recommend Python to control the pins. Check the following tutorials below to get started.

Python Programming Tutorial: Getting Started with the Raspberry Pi

June 27, 2018

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

Raspberry gPIo

October 29, 2015

How to use either Python or C++ to drive the I/O lines on a Raspberry Pi.

Stack a Hat

With the Pi 400 2x20 pins rerouted to a vertical position, you can stack on a HAT. Check out a few of the HATs below from the SparkFun catalog.

Raspberry Pi SSD Kit for Raspberry Pi - 512GB

Raspberry Pi SSD Kit for Raspberry Pi - 512GB

KIT-26688
$55.00
SparkFun GPS-RTK Dead Reckoning pHAT for Raspberry Pi

SparkFun GPS-RTK Dead Reckoning pHAT for Raspberry Pi

GPS-21305
$289.95
Raspberry Pi SSD Kit for Raspberry Pi - 256GB

Raspberry Pi SSD Kit for Raspberry Pi - 256GB

KIT-26687
$40.00
1

Raspberry Pi LCD - 7" Touchscreen

LCD-13733
56

Resources and Going Further

For more information, check out the resources below:

Now that you have your Qwiic pHAT extension ready to go, it's time incorporate it into a project! Check out any tutorials that are tagged with Raspberry Pi for ideas.

Setting up a Raspberry Pi 3 as an Access Point

This guide will show you how to configure a Raspberry Pi as an access point and connect it to your local Ethernet network to share Internet to other WiFi devices.

Pi AVR Programmer HAT Hookup Guide

In this tutorial, we will use a Raspberry Pi 3 and the Pi AVR Programmer HAT to program an ATMega328P target. We are going to first program the Arduino bootloader over SPI, and then upload an Arduino sketch over a USB serial COM port.

How to Install CH340 Drivers

How to install CH340 drivers (if you need them) on Windows, Mac OS X, and Linux.

Qwiic Atmospheric Sensor (BME280) Hookup Guide

Measure temperature, humidity, barometric pressure with the SparkFun Atmospheric Sensor Breakout BME280 (Qwiic).