# QT Py S2 Round Display Compass

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/135/477/medium800/lcds___displays_compass_hero_photo.png?1740523505)

The [GC9A01A round displays](https://www.adafruit.com/product/6178) are great for displaying a compass face. This project uses a magnetometer & accelerometer/gryo breakout to obtain the cardinal direction, then plot it onto the display with a red pointer needle overlaid on top of a beautiful compass rose.

The EYESPI ribbon and STEMMA QT cable connections make this project a breeze to assemble with only minimal soldering.&nbsp;

![A hand holds the compass with the screen visible, the needle spins around counter clockwise starting and ending on east as the person turs around.](https://cdn-learn.adafruit.com/assets/assets/000/135/495/medium640thumb/lcds___displays_compass_in_action.jpg?1740581279)

## Parts
### Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU

[Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU](https://www.adafruit.com/product/4517)
Add high-quality motion,&nbsp;direction, and orientation&nbsp;sensing to your Arduino project with this all-in-one 9 Degree of Freedom (9-DoF) sensor with sensors from ST. This little breakout contains two chips that sit side-by-side to provide 9 degrees of full-motion data.

The board...

In Stock
[Buy Now](https://www.adafruit.com/product/4517)
[Related Guides to the Product](https://learn.adafruit.com/products/4517/guides)
![Angled shot of a Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU - STEMMA QT / Qwiic.](https://cdn-shop.adafruit.com/640x480/4517-07.jpg)

### Adafruit 1.28" 240x240 Round TFT LCD Display with MicroSD

[Adafruit 1.28" 240x240 Round TFT LCD Display with MicroSD](https://www.adafruit.com/product/6178)
'Round these parts we enjoy unusually-shaped displays. And this one certainly fits the description - it's a 1.28" diagonal TFT that comes in a round shape and contains a high density 220 ppi, 240x240 pixel RGB display with full-angle viewing. It _looks_ a lot like our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/6178)
[Related Guides to the Product](https://learn.adafruit.com/products/6178/guides)
![Video of a round TFT display assembled onto a breadboard with a microcontroller. The TFT shows a blinking eyeball animation.](https://cdn-shop.adafruit.com/product-videos/640x480/6178-04.jpg)

### Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT

[Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT](https://www.adafruit.com/product/5325)
What has your favorite Espressif WiFi microcontroller, comes with&nbsp;[our favorite connector - the STEMMA QT](http://adafruit.com/stemma), a chainable I2C port, and has lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy? What a...

In Stock
[Buy Now](https://www.adafruit.com/product/5325)
[Related Guides to the Product](https://learn.adafruit.com/products/5325/guides)
![Angled shot of small square purple dev board.](https://cdn-shop.adafruit.com/640x480/5325-12.jpg)

### Adafruit EYESPI BFF for QT Py or Xiao - 18 Pin FPC Connector

[Adafruit EYESPI BFF for QT Py or Xiao - 18 Pin FPC Connector](https://www.adafruit.com/product/5772)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to add a small, colorful, and bright display to any project.

Our most recent [display...](https://www.adafruit.com/?q=eyespi&sort=BestMatch)

In Stock
[Buy Now](https://www.adafruit.com/product/5772)
[Related Guides to the Product](https://learn.adafruit.com/products/5772/guides)
![Adafruit EYESPI BFF for QT Py or Xiao - 18 Pin FPC Connector.](https://cdn-shop.adafruit.com/640x480/5772-00.jpg)

### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
![Angled shot of STEMMA QT / Qwiic JST SH 4-pin Cable.](https://cdn-shop.adafruit.com/640x480/4210-00.jpg)

### EYESPI Cable - 18 Pin 100mm long Flex PCB (FPC) A-B type

[EYESPI Cable - 18 Pin 100mm long Flex PCB (FPC) A-B type](https://www.adafruit.com/product/5239)
Connect this to that when a 18-pin FPC connector is needed. This 25 cm long cable is made of a flexible PCB. It's A-B style which means that pin one on one side will match with pin one on the other side. How handy!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/5239)
[Related Guides to the Product](https://learn.adafruit.com/products/5239/guides)
![Angled shot of a EYESPI Cable - 18 Pin 100mm long Flex PCB (FPC) A-B type. ](https://cdn-shop.adafruit.com/640x480/5239-00.jpg)

### Part: USB Type A to Type C Cable
quantity: 1
Approx 1 meter / 3 ft long
[USB Type A to Type C Cable](https://www.adafruit.com/product/4474)

### Part: Mounting Putty / Sticky Tack
quantity: 1
Pea sized glob

# QT Py S2 Round Display Compass

## 3D Printing

## 3D Printed Box

STL files for 3D printing will need to be oriented for print using either FDM or SLS machines.&nbsp;Parts were built with PLA filament.&nbsp;

STL file for printing may be downloaded using the link below.

The box was sliced with CURA using the settings below

- PLA filament 205c extruder
- 0.35 layer height
- No supports

![](https://cdn-learn.adafruit.com/assets/assets/000/135/478/medium640/lcds___displays_3dprint_box_front_angle.png?1740523909)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/479/medium640/lcds___displays_3dprint_box_top_angle.png?1740523934)

[round_eyespi_display_box.stl](https://cdn-learn.adafruit.com/assets/assets/000/135/248/original/round_eyespi_display_box.stl?1739287153)
## Original Design File

The box was designed using [OpenScad](https://openscad.org/), find the source code for it below.

```auto
wall_thickness = 1.6;
short_wall_height = 25;

difference(){
    
    cube([50+(wall_thickness*2),50+(wall_thickness*2),42+1], center=true);
    translate([0,0,1]){
        cube([50,50,42+1], center=true);
    }
    
    translate([0,20,0])
    rotate([90,0,0]){
        cylinder(r=36/2, h=30, center=true, $fn=80);
    } 
    
    translate([
        -10,
        -(50+(wall_thickness*2))/2 + 9/2 + 4,
        -(42+1)/2 + 18/2 + 1]){
    
        hull(){
            translate([0,0,-4.5])
            rotate([0,90,])
            cylinder(r=9/2, h=40, center=true, , $fn=30);
            
            translate([0,0,4.5])
            rotate([0,90,0])
            cylinder(r=9/2, h=40, center=true, $fn=30);
        }
        //cube([40,9,18], center=true);
    }
}


translate([-(50+(wall_thickness*2))/2 + 40/2,
    ((50+(wall_thickness*2))/2) - wall_thickness/2 - 8,
    -(43/2)+(short_wall_height/2)])
cube([40,wall_thickness,short_wall_height], center=true);


translate([(50+(wall_thickness*2))/2 - 40/2,
    ((50+(wall_thickness*2))/2) - wall_thickness/2 - 8 - 4,
    -(43/2)+(short_wall_height/2)])
cube([40,wall_thickness,short_wall_height], center=true);


/*
translate([0,-5,0])
cube([22, 32, 18], center=true);
*/
```

# QT Py S2 Round Display Compass

## Assembly

The only soldering required for this project are the headers on the QT Py and EYESPI BFF. After that you just need a few quick connections and to fit everything into the box.

## Solder Headers
First solder the following header types to the BFF and QT Py. Make sure that you have the appropriate header paired with the correct board and that the header is facing the proper direction relative to the board. We [have a learn guide](https://learn.adafruit.com/how-to-solder-headers/overview) that covers soldering headers if you're new to the process or want a refresher.

### QT Py ESP32-S2

Standard male header with the pins going down on the side opposite the USB-C connector.

![QT Py S2 with male header pins soldered so that the pins protrude from the bottom of the board](https://cdn-learn.adafruit.com/assets/assets/000/135/480/medium640/lcds___displays_qtpy_top_angle.png?1740524262)

![QT Py S2 seen from the top with male header pins soldered so that the pins protrude from the bottom of the board](https://cdn-learn.adafruit.com/assets/assets/000/135/481/medium640/lcds___displays_qtpy_top.png?1740524293)

![QT Py S2 seen from the bottom with male header pins soldered so that the pins protrude from the bottom of the board](https://cdn-learn.adafruit.com/assets/assets/000/135/482/medium640/lcds___displays_qtpy_bottom.png?1740524332)

### EYESPI BFF

Standard female header with the female header on the opposite side of the board from the EYESPI ribbon cable connector.

![EYESPI BFF seen from top angle with female headers soldered such that the headers are protruding from the side opposite the EYESPI ribbon connector](https://cdn-learn.adafruit.com/assets/assets/000/135/483/medium640/lcds___displays_eyespibff_top_angle.png?1740524446)

![EYESPI BFF seen from the side with female headers protruding, and without the EYESPI ribbon connector](https://cdn-learn.adafruit.com/assets/assets/000/135/484/medium640/lcds___displays_eyespibff_top.png?1740524511)

![EYESPI BFF seen from the side with EYESPI ribbon connector, and without female headers protruding](https://cdn-learn.adafruit.com/assets/assets/000/135/485/medium640/lcds___displays_eyespibff_bottom.png?1740524560)

## Connect Display
First you must carefully flip up the dark grey flap that secures the ribbon. Gently slip your fingernail or a small flat head screw driver under it, then carefully pry upward. The flap is delicate so be careful, it should not require much force once you've got something up underneath it.

- Connect one end of the EYESPI ribbon cable to the EYESPI BFF.&nbsp;
- Connect the other end of the EYESPI ribbon cable to the GC9A01A breakout.

Both connections should have the blue tab facing upward. Insert the ribbon cable, then push down the flap to secure it.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/486/medium640/lcds___displays_eyespibff_ribbon_display_full.png?1740524802)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/487/medium640/lcds___displays_eyespibff_ribbon_connected.png?1740524830)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/488/medium640/lcds___displays_gc9a01a_ribbon_connected.png?1740524850)

## Connect LSM6DSOX + LIS3MDL Breakout
Connect one end of the STEMMA QT cable to the QT Py ESP32-S2, and the other end to the LSM6DSOX + LIS3MDL breakout. Be sure to use the same STEMMA QT connector that is pictured on the LSM6DSOX + LIS3MDL breakout. The wire should be coming out of the right side, when the text on the board is facing away from you.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/489/medium640/lcds___displays_stemma_mag_gyro.png?1740526077)

## Mount LSM6DSOX + LIS3MDL Breakout Into Box
Take a pea sized glob of mounting putty and smash it around in your fingers until it's tacky, then squish it onto the back of the LSM6DSOX + LIS3MDL breakout. Place the breakout into the front left corner of the back cavity of the box behind offset walls that make the display slot.&nbsp;

The text on the breakout should be upside down or facing away from you if viewed from the top of the box with the circle cutout in the front as shown in the photo.

Make sure the edges of the breakout are snug against the walls of the box, it needs to be in the proper orientation for the compass code to function.

Once it's in place press it down firmly to stick it to the bottom of the box with the mounting putty that you put on it's bottom side.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/490/medium640/lcds___displays_lsm_in_box.png?1740526961)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/491/medium640/lcds___displays_lsm_mounting_putty.png?1740526983)

## Stack QT Py and EYESPI BFF
Plug in the male header pins on the QT Py to the female headers on the EYESPI BFF. Be sure they are in the proper orientation relative to each other! You can check the pin labels on the silk screen as well as the USB pointer label on the BFF. They should also match the photos shown here.

Do this without the USB cable plugged in so they are unpowered.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/492/medium640/lcds___displays_qtpy_stacked_qtpy.png?1740527461)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/493/medium640/lcds___displays_qtpy_stacked_eyespibff.png?1740527479)

## Place Into Box
Carefully place the display into its slot at the front of the box, feeding the EYESPI ribbon cable down into its channel made by the two offset walls.

Set the QT Py and BFF stack into the open space behind the offset walls with the USB C connector pointing towards the USB Cable hole cut out of the side of the box. Plug in your desired USB C cable to power the project, feeding it through the hole.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/494/medium640/lcds___displays_final_assembly_in_box.png?1740527782)

# QT Py S2 Round Display Compass

## Calibrate

## Project Setup

Are you new to using CircuitPython? No worries,&nbsp;[there is a full getting-started guide here](https://learn.adafruit.com/welcome-to-circuitpython "Welcome to CircuitPython").

Plug the device into your computer with a known good USB cable (not a charge-only cable). The device will appear to your computer in File Explorer or Finder (depending on your operating system) as a flash drive named&nbsp; **CIRCUITPY**. If the drive does not appear, you can&nbsp;[install CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;on your device and then return here.

Download the project files with the Download Project Bundle button below.&nbsp;Unzip the file and copy/paste the&nbsp; **code.py** &nbsp;and other project files to your&nbsp; **CIRCUITPY** &nbsp;drive using File Explorer or Finder (depending on your operating system).

## Run Calibrate Script

In order for the compass function most effectively you must obtain some calibration values from the sensor breakout by running the calibration script on this page. The script is included in the project bundle with the name&nbsp; **calibrate.py**.

To run it, connect to the serial console (for example in the Mu program Serial window), press Ctrl-C&nbsp;on your keyboard to enter the REPL. Then type `import calibrate` and press enter. Example output is shown below.

Watch the serial output and follow the directions shown there. The script will first prompt you to set the sensor down on a flat surface and leave it perfectly still. After it takes several readings it will then ask you to start moving the sensor around. Pick up the box and carefully wave it around in a figure eight motion twisting and turning it as you go. The goal is to move the sensor into every possible orientation while the calibration code keeps track of the extremes of the values in each axis.

Once the script is finish select the calibration values printed at the end and copy them. They need to be pasted into the **code.py** script of the compass on the next page.

```terminal
>>> import calibrate
Preparing gyroscope calibration. Keep board perfectly still on flat surface.
Starting gyroscope calibration..

Uncalibrated gyro:  (-0.00473421, -0.00290161, 0.00122173)
Calibrated gyro:  (-0.00946841, -0.00580322, 0.00244346)
...

Gyroscope calibrated!
Preparing magnetometer calibration. Move board around in 3D space.
Starting magnetometer calibration..

Uncalibrated: -56.3578 29.0558 -37.3283
Calibr:   -1.0 1.0 1.0
MAG_MIN = [-56.3578, 28.1935, -37.8398]
MAG_MAX = [-55.9047, 29.0558, -37.3283]
...

MAG_MIN = [-75.1973, -22.5665, -34.5221]
MAG_MAX = [-1.2131, 68.1379, 20.8126]
GYRO_CAL = [-0.0038, -0.0026, -0.0011]
```

The code for the **calibrate.py** script is shown below.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/QT_Py/QT_Py_ESP32_S2_RoundDisplay_Compass/calibrate.py

# QT Py S2 Round Display Compass

## Code the Compass

You need to run the calibration script and copy the values that it outputs into the compass script before it will be able to work properly. If you have not already done so, follow the instructions on the [Calibrate page](https://learn.adafruit.com/qt-py-s2-round-display-compass/calibrate).

## Drive Structure

After copying the files, your drive should look like the listing below. It can contain other files as well, but must contain these at a minimum.

![CIRCUITPY](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/folder-images/QT_Py_QT_Py_ESP32_S2_RoundDisplay_Compass.png?raw=true )

## Code

The **code.py** for the project is shown below.

Each section of code contains comments about its purpose.

Be sure to replace the calibration value variables near the top of the code with the ones you obtained by following the steps on the [calibrate page](https://learn.adafruit.com/qt-py-s2-round-display-compass/calibrate).

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/QT_Py/QT_Py_ESP32_S2_RoundDisplay_Compass/code.py


## Featured Products

### Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU

[Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU](https://www.adafruit.com/product/4517)
Add high-quality motion,&nbsp;direction, and orientation&nbsp;sensing to your Arduino project with this all-in-one 9 Degree of Freedom (9-DoF) sensor with sensors from ST. This little breakout contains two chips that sit side-by-side to provide 9 degrees of full-motion data.

The board...

In Stock
[Buy Now](https://www.adafruit.com/product/4517)
[Related Guides to the Product](https://learn.adafruit.com/products/4517/guides)
### Adafruit 1.28" 240x240 Round TFT LCD Display with MicroSD

[Adafruit 1.28" 240x240 Round TFT LCD Display with MicroSD](https://www.adafruit.com/product/6178)
'Round these parts we enjoy unusually-shaped displays. And this one certainly fits the description - it's a 1.28" diagonal TFT that comes in a round shape and contains a high density 220 ppi, 240x240 pixel RGB display with full-angle viewing. It _looks_ a lot like our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/6178)
[Related Guides to the Product](https://learn.adafruit.com/products/6178/guides)
### Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT

[Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT](https://www.adafruit.com/product/5325)
What has your favorite Espressif WiFi microcontroller, comes with&nbsp;[our favorite connector - the STEMMA QT](http://adafruit.com/stemma), a chainable I2C port, and has lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy? What a...

In Stock
[Buy Now](https://www.adafruit.com/product/5325)
[Related Guides to the Product](https://learn.adafruit.com/products/5325/guides)
### Adafruit EYESPI BFF for QT Py or Xiao - 18 Pin FPC Connector

[Adafruit EYESPI BFF for QT Py or Xiao - 18 Pin FPC Connector](https://www.adafruit.com/product/5772)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to add a small, colorful, and bright display to any project.

Our most recent [display...](https://www.adafruit.com/?q=eyespi&sort=BestMatch)

In Stock
[Buy Now](https://www.adafruit.com/product/5772)
[Related Guides to the Product](https://learn.adafruit.com/products/5772/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### EYESPI Cable - 18 Pin 100mm long Flex PCB (FPC) A-B type

[EYESPI Cable - 18 Pin 100mm long Flex PCB (FPC) A-B type](https://www.adafruit.com/product/5239)
Connect this to that when a 18-pin FPC connector is needed. This 25 cm long cable is made of a flexible PCB. It's A-B style which means that pin one on one side will match with pin one on the other side. How handy!

<a...></a...>

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

## Related Guides

- [ST 9-DoF Combo Breakouts and Wings](https://learn.adafruit.com/st-9-dof-combo.md)
- [Adafruit QT Py ESP32-S2 and QT Py ESP32-S2 with uFL Antenna](https://learn.adafruit.com/adafruit-qt-py-esp32-s2.md)
- [Adafruit EYESPI BFF](https://learn.adafruit.com/adafruit-eyespi-bff.md)
- [Adafruit 1.28" 240x240 Round TFT LCD](https://learn.adafruit.com/adafruit-1-28-240x240-round-tft-lcd.md)
- [IoT Filament Sensor](https://learn.adafruit.com/iot-filament-sensor.md)
- [ESP-NOW in CircuitPython](https://learn.adafruit.com/esp-now-in-circuitpython.md)
- [World Clock](https://learn.adafruit.com/world-clock.md)
- [Wireless ESP32-S2 Touch Screen Controller for Pure Data](https://learn.adafruit.com/wireless-esp32-s2-controller-for-pure-data.md)
- [Asteroid Tracker](https://learn.adafruit.com/asteroid-tracker.md)
- [No-Code Snowfall Tracker with WipperSnapper and Adafruit IO](https://learn.adafruit.com/no-code-snow-tracker-with-wippersnapper-and-adafruit-io.md)
- [IoT Moon Phase Guide](https://learn.adafruit.com/moon-phase.md)
- [LIS3MDL Triple-axis Magnetometer](https://learn.adafruit.com/lis3mdl-triple-axis-magnetometer.md)
- [Traffic Light Conference Badge](https://learn.adafruit.com/traffic-light-conference-badge.md)
- [Cartoon Character Clock](https://learn.adafruit.com/cartoon-character-clock.md)
- [QT Py Snap Fit Case](https://learn.adafruit.com/qt-py-snap-fit-case.md)
- [Mu Keyboard Shortcut Cheat Sheets](https://learn.adafruit.com/mu-keyboard-shortcut-cheat-sheets.md)
- [PyGamer - Gaming Handheld Crank](https://learn.adafruit.com/gaming-handheld-crank.md)
