# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/118/303/medium800/wearables_IMG_125.png?1675839630)

Track your punches with precision on Adafruit IO using this accelerometer-powered Boxing Glove tracker with an &nbsp;ESP32-S2 or ESP32-S3 TFT! In this guide we'll just refer to the ESP32-S3 TFT.

This project allows you to build your custom Boxing Glove Tracker using a Feather ESP32-S3 TFT running CircuitPython with an ADXL345 accelerometer. The ESP32-S3 &nbsp;TFT reads accelerometer data to measure the force of punches you throw.

The data collected by the accelerometer will then be sent to Adafruit IO, where you can visualize and analyze your training performance over time.

https://youtu.be/8GxOnhckz1g

## Using PyLeap

You can quickly transfer this project to your ESP32-S3 TFT via a WiFi connection using the PyLeap app.

[PyLeap](https://learn.adafruit.com/pyleap-app) is a free app available for iOS, iPad and Android devices. It can be downloaded from the [Apple App Store](https://learn.adafruit.com/pyleap-app) or [Google Play Store](https://play.google.com/store/apps/details?id=com.adafruit.pyleap). It allows users to easily download code files and assets and transfer them to their Adafruit devices using Bluetooth Low Energy (BLE) or WiFi.

![](https://cdn-learn.adafruit.com/assets/assets/000/118/374/medium800/wearables_IMG_1660.png?1675965441)

This project is perfect for folks that want to enter the electronics and IoT world. It's also handy for anyone who trains in boxing and wants to track their progress and improve their technique! Below are some parts you'll need to have before starting this project.&nbsp;

Let's get started!

## Parts
Featured
### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
![Adafruit ESP32-S2 TFT Feather powered on by a USB- C power source displaying the product tittle in a red, yellow, green, white and blue. ](https://cdn-shop.adafruit.com/640x480/5300-06.jpg)

Featured
### ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI

[ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI](https://www.adafruit.com/product/1231)
Filling out our accelerometer offerings, we now have the really lovely digital ADXL345 from Analog Devices, a triple-axis accelerometer with digital I2C and SPI interface breakout. We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for...

In Stock
[Buy Now](https://www.adafruit.com/product/1231)
[Related Guides to the Product](https://learn.adafruit.com/products/1231/guides)
![Angled shot of accelerometer breakout.](https://cdn-shop.adafruit.com/640x480/1231-04.jpg)

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

Featured
### Lithium Ion Battery - 3.7V 2000mAh

[Lithium Ion Battery - 3.7V 2000mAh](https://www.adafruit.com/product/2011)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 2000mAh. If you need a larger (or smaller!) battery,&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2011)
[Related Guides to the Product](https://learn.adafruit.com/products/2011/guides)
![Lithium Ion Polymer Battery 3.7v 2000mAh with JST 2-PH connector](https://cdn-shop.adafruit.com/640x480/2011-05.jpg)

Featured
### Pink and Purple Woven USB A to USB C Cable - 1 meter long

[Pink and Purple Woven USB A to USB C Cable - 1 meter long](https://www.adafruit.com/product/5153)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also made for USB C for our modernized breakout boards, Feathers, and more.&nbsp;&nbsp;[If you want something just like it but for Micro B, we...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5153)
[Related Guides to the Product](https://learn.adafruit.com/products/5153/guides)
![Angled shot of coiled pink and purple USB cable with USB A and USB C connectors.](https://cdn-shop.adafruit.com/640x480/5153-02.jpg)

## Additional Tools

Some additional supplies: an **X-acto knife** , **scissors** , and a **s**** ewing kit**.

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Gathering the Components

We will use a few components to build our Boxing Glove tracker:

1 x [ESP32-S3 with a TFT display](https://www.adafruit.com/product/5483)

1 x [ADXL345 accelerometer](https://www.adafruit.com/product/1231)

1 x [Lithium-ion 3.7 volt battery](https://www.adafruit.com/product/2011)

## ESP32-S3 TFT display
The ESP32-S3 TFT will serve as the brain of the project, collecting data from the accelerometer and displaying it for visualization on the TFT display.

The TFT display will display the data from the accelerometer, battery percentage, and if the board is connected to the internet.

![wearables_Screen_Shot_2023-02-09_at_10.59.49_AM.png](https://cdn-learn.adafruit.com/assets/assets/000/118/405/medium640/wearables_Screen_Shot_2023-02-09_at_10.59.49_AM.png?1675976223)

[For more information on the ESP32-S2 TFT Feather, check out this Learn Guide!](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather)
## ADXL345 Accelerometer
The ADXL345 accelerometer will be used to measure the acceleration and&nbsp;impact of the glove.

The accelerometer measures the acceleration of the gloves in all three dimensions (x, y, and z). This information can then be used to track the movement and impact of the gloves.

This accelerometer comes with STEMMA QT connectors so that we can plug the accelerometer into the ESP32-S2 TFT with a&nbsp;[STEMMA QT / Qwiic JST SH 4-pin Cable](https://www.adafruit.com/product/4210).

![wearables_Screen_Shot_2023-02-09_at_11.21.12_AM.png](https://cdn-learn.adafruit.com/assets/assets/000/118/407/medium640/wearables_Screen_Shot_2023-02-09_at_11.21.12_AM.png?1675976333)

[For more information on the accelerometer, check out this Learn Guide!](https://learn.adafruit.com/adxl345-digital-accelerometer)
## Battery
This project uses a thin and light Lithium Ion 3.7 volt battery to power the ESP32-S2 TFT board. I've decided to use this because it was easier to fit into the glove and prevented tearing the glove's leather.

![wearables_Screen_Shot_2023-02-09_at_3.56.15_PM.png](https://cdn-learn.adafruit.com/assets/assets/000/118/408/medium640/wearables_Screen_Shot_2023-02-09_at_3.56.15_PM.png?1675976412)

[For more information on Li-Ion batteries, check out this Learn Guide!](https://learn.adafruit.com/li-ion-and-lipoly-batteries)
# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Building the Boxing Glove Tracker

### Assembling the components

Here is a detailed, step-by-step guide for the assembling the components.

First, plug in your battery to the [ESP32-S3 TFT Feather.](https://www.adafruit.com/product/5300)

![wearables_ezgif.com-video-to-gif-2.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/336/medium640thumb/wearables_ezgif.com-video-to-gif-2.jpg?1675893834)

Then, plug your&nbsp;[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210) to the ESP32-S3 TFT then connect the other end of the cable to [ADXL345 - Triple-Axis Accelerometer](https://www.adafruit.com/product/1231).

![wearables_ezgif.com-optimize.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/339/medium640thumb/wearables_ezgif.com-optimize.jpg?1675895380)

Finally, setup your ESP32-S3 TFT by connecting it to your computer using a USB-C.

![wearables_ezgif.com-crop-2.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/340/medium640thumb/wearables_ezgif.com-crop-2.jpg?1675896908)

Now that all the components are connected, it's time to update the ESP32-S3 TFT to the latest version of CircuitPython.

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Get Started with Adafruit IO

Adafruit IO is integrated with your&nbsp;[adafruit.com account](https://accounts.adafruit.com/)&nbsp;so you don't need to create yet another online account! You need an Adafruit account to use Adafruit IO because we want to make sure the data you upload is available to only you (unless you decide to publish your data).

## I have an Adafruit.com Account already

**If you already have an Adafruit account, then you already have access to Adafruit IO**. It doesn't matter how you signed up, your account will make all three available.

To access Adafruit IO, simply visit [https://io.adafruit.com](https://io.adafruit.com) to start streaming, logging, and interacting with your data.

## Create an Adafruit Account (for Adafruit IO)

An Adafruit account makes Adafruit content and services available to you in one place. Your account provides access to the [Adafruit shop](https://www.adafruit.com/), the [Adafruit Learning System](https://learn.adafruit.com/), and [Adafruit IO](https://io.adafruit.com/). This means only one account, one username, and one password are necessary to engage with the content and services that Adafruit offers.

If you do not have an Adafruit account, signing up for a new Adafruit account only takes a couple of steps.

Begin by visiting [https://accounts.adafruit.com](https://accounts.adafruit.com).

**Click the Sign Up button** under the "Need An Adafruit Account?" title, below the Sign In section.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/220/medium800/adafruit_io_Create_account_sign_in_up_page.png?1697479894)

This will take you to the **Sign Up** page.

**Fill in the requested information,** and **click the Create Account button.**

![](https://cdn-learn.adafruit.com/assets/assets/000/125/219/medium800/adafruit_io_Create_Account_info_entered.png?1697479894)

This takes you to your Adafruit Account home page. From here, you can access all the features of your account.

You can also access the Adafruit content and services right from this page. Along the top of the page, you'll see a series of links beginning with "Shop". To access any of these, simply click the link.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/217/medium800/adafruit_io_Create_account_home_page.png?1697479894)

For example, **to begin working with Adafruit IO, click the IO link** to the right of the rest of the links. This is the same for the other links as well.

That's all there is to creating a new Adafruit account, and navigating to Adafruit IO.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/218/medium800/adafruit_io_Create_Account_io_homepage.png?1697479770)

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Creating a Feed

Creating a Feed on Adafruit IO is a very simple process. Remember, if you are using WipperSnapper you do not need to create feeds - they are created for you automagically!

When you log in to your [io.adafruit.com](https://io.adafruit.com) account, first visit the **Overview** page. This page lists information about your account, the data coming into IO from your devices, a list of WipperSnapper devices if you have any, and more.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/836/medium800/adafruit_io_overview_pg.png?1696453458)

To navigate to the feed page, click on the **Feeds** link on the header.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/837/medium800/adafruit_io_IO_-_Overview_2.png?1696453502)

On the Feeds page, click the **New Feed&nbsp;** button.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/838/medium800/adafruit_io_IO_-_Feeds_new.png?1696453879)

A pop-up will appear, and you will be presented with two text inputs:

- **Name** - A short descriptive title of your data. Letters, numbers, dashes, underscores, or spaces are valid characters, and this field is _required_. The feed name must be _unique_ to your account.
- **Description** - A long-form description of your data. This field is not required, but it's useful to provide a detailed description of your feed.

After adding a feed name and description, click Create.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/839/medium800/adafruit_io_IO_-_Feeds_2.png?1696454029)

You'll see your new feed appear on the feed page, underneath the "Default" group.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/840/medium800/adafruit_io_IO_-_Feeds_3.png?1696454144)

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_esp32s2_tft/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/129/medium640/install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg?1620922559)

![](https://cdn-learn.adafruit.com/assets/assets/000/107/769/medium800/adafruit_products_FTFT_reset_NeoPixel.jpg?1641925114)

Plug your board into your computer, using a known-good data-sync cable, directly, or via an adapter if needed.

Double-click the **reset** button (highlighted in red above), and you will see the **RGB status LED(s)** turn green (highlighted in green above). If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

For this board, tap reset and wait for the LED to turn purple, and as soon as it turns purple, tap reset again. The second tap needs to happen while the LED is still purple.

If you do not see the LED turning purple, you will need to reinstall the UF2 bootloader. See the&nbsp; **Factory Reset** &nbsp;page in this guide for details.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **FTHRS2BOOT**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **FTHRS2BOOT**.

![adafruit_products_FTFT_FTHRS2BOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/107/771/medium640/adafruit_products_FTFT_FTHRS2BOOT.png?1641926447)

![adafruit_products_FTFT_drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/107/772/medium640/adafruit_products_FTFT_drag_UF2.png?1641926456)

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![install_circuitpython_on_most_boards_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/130/medium640/install_circuitpython_on_most_boards_CIRCUITPY.jpg?1620923145)

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## WiFi Pairing

## Setup WiFi Credentials

PyLeap&nbsp;depends on adding WiFi credentials to detect Adafruit devices over WiFi.&nbsp;

Create a file with the name **settings.toml** in the root directory of the **CIRCUITPY** drive.

Add the following below:

The file contains the keys `CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD`. Once these are defined, CircuitPython will automatically connect to the network and start the webserver used for the workflow.

The web server is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS.

Here is an example **settings.toml** :

```auto
# To auto-connect to Wi-Fi
CIRCUITPY_WIFI_SSID="YOUR-WIFI-NETWORK-NAME"
CIRCUITPY_WIFI_PASSWORD="YOUR-WIFI-NETWORK-PASSWORD"

# To enable modifying files from the web. Change this too!
# Leave the User field blank in the browser.
CIRCUITPY_WEB_API_PASSWORD="passw0rd"

CIRCUITPY_WEB_API_PORT=80
```

Drag the **settings.toml** &nbsp;file to the **CIRCUITPY** drive.

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/117/092/medium800/circuitpython_Screen_Shot_2022-12-14_at_6.06.29_PM.png?1671059418)

Open the PyLeap app. Select WiFi and scan for Adafruit devices.

After seeing the spinning Blinka animation, you should see a screen with WiFi devices found. Once you've found your device in the peripheral device list, press the Connect button to&nbsp;continue.

![](https://cdn-learn.adafruit.com/assets/assets/000/117/094/medium800/circuitpython_IMG_0033.png?1671059667)

If WiFi devices were not found, either rescan for WiFi devices or double check your WiFi credentials.

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## PyLeap Boxing Glove Tracker Code

![](https://cdn-learn.adafruit.com/assets/assets/000/118/366/medium800/wearables_Screen_Shot_2023-02-09_at_12.32.24_PM.png?1675963979)

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

This code is doing several things:

- Connecting to the internet
- Connecting to Adafruit IO
- Gathering accelerometer data and battery percentage data
- Displaying accelerometer and battery data on the TFT
- Sending accelerometer data to a feed in Adafruit IO

## Acquiring WiFi credentials

These few lines of code extract the values for the Adafruit IO username and Adafruit IO API key from the **settings.toml** &nbsp;file mentioned [here](https://learn.adafruit.com/pyleap-app/wifi-pairing).

The values for `aio_username` and `aio_key` are&nbsp;in the **settings.toml** file.

```auto
aio_username = os.getenv('aio_username')
aio_key = os.getenv('aio_key')
```

Info: 

## Connecting to WiFi

This code block connects to a WiFi network using the `wifi.radio.connect` function and passes in the network’s SSID and password as arguments. The values of the SSID and password are read from environment variables `CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD`.

```auto
# Wi-Fi
try:
    print("Connecting to %s" % os.getenv('CIRCUITPY_WIFI_SSID'))
    wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
    print("Connected to %s!" % os.getenv('CIRCUITPY_WIFI_SSID'))
# Wi-Fi connectivity fails with error messages, not specific errors, so this except is broad.
except Exception as e:  # pylint: disable=broad-except
    print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 30 seconds.")
    time.sleep(30)
    microcontroller.reset()
```

## Creating a Socket Pool

Next, the code initializes a socket pool and an MQTT client for communicating with the Adafruit IO cloud service.

The `socketpool.SocketPool` function creates a pool of sockets for management of network connections. It takes the `wifi.radio` object as an argument to allow for network communication over the WiFi connection.

```python
pool = socketpool.SocketPool(wifi.radio)
```

## Initializing a MQTT Client

The `MQTT.MQTT` function is then used to initialize a new MQTT client object, which will be used to send and receive messages with the Adafruit IO cloud service. This function takes several arguments:

- `broker`: the hostname of the MQTT broker (Adafruit IO in this case).
- `username` and `password`: the credentials for authenticating with the Adafruit IO service are stored in the **settings.toml** &nbsp;file.
- `socket_pool`: the socket pool created in the previous step.
- `ssl_context`: an SSL context created using the `create_default_context` method from the `ssl` module. This provides secure communication between the device and the Adafruit IO service.

Finally, the `IO_MQTT` function is used to initialize an "Adafruit IO MQTT helper", a convenient wrapper around the MQTT client that provides a simple API for working with Adafruit IO.

```auto
mqtt_client = MQTT.MQTT(
    broker="io.adafruit.com",
    username= aio_username,
    password= aio_key,
    socket_pool=pool,
    ssl_context=ssl.create_default_context(),
)

# Initialize Adafruit IO MQTT "helper"
io = IO_MQTT(mqtt_client)
```

## Connecting to Adafruit IO

Now to check the connection status of Adafruit IO, and if it is not connected, it is trying to connect to the MQTT broker using the `io.connect()` method.

If the connection to Adafruit IO fails, an error message is printed, and the board will hard reset after 30 seconds.

The `except` block is broad to catch all exceptions and the `broad-except`.

```auto
try:
    # If Adafruit IO is not connected...
    if not io.is_connected:
    # Connect the client to the MQTT broker.
        print("Connecting to Adafruit IO...")
        io.connect()
        print("Connected to Adafruit IO!")
except Exception as e:  # pylint: disable=broad-except
    print("Failed to get or send data, or connect. Error:", e,
    "\nBoard will hard reset in 30 seconds.")
    time.sleep(30)
    microcontroller.reset()
```

## Adding a threshold

These lines of code set two variables, `threshold` and `time_interval`.

`threshold` is set to 20; this value filters out movement that might&nbsp;trigger punch detection.

`time_interval` is set to 0.5, which is the time interval in seconds; I added this to limit the amount of data points created. You can change this to cater to your Adafruit IO plan.

```auto
threshold = 20 # set threshold value here
time_interval = 0.5 # set the time interval in seconds
```

## Accessing the Accelerometer&nbsp;

Now to create an I2C bus object using the `board.STEMMA_I2C()` method, and then create an instance of an ADXL345 accelerometer using that I2C bus object.

The `ADXL345` class is imported from an external library and represents an ADXL345 3-axis accelerometer, which can measure acceleration along the X, Y, and Z axes.

The accelerometer is being initialized using the I2C bus object so that the accelerometer can communicate with the microcontroller board over the I2C bus.

```auto
# create the I2C bus object
i2c = board.STEMMA_I2C()
# For ADXL345
accelerometer = ADXL345(i2c)
```

## Accessing the built-in battery monitor&nbsp;

Next to create an instance of the LC709203F class named `battery_monitor` and set the `pack_size` attribute of the `battery_monitor` object to `PackSize.MAH400`.

The `pack_size` attribute is used to set the capacity of the battery being monitored by the LC709203F. In this case, `PackSize.MAH400` is used to specify a battery capacity of 400 milliampere-hours (mAh).

```auto
battery_monitor = LC709203F(i2c)
battery_monitor.pack_size = PackSize.MAH400
```

## Setting the Current Time

This line `t0 = time.monotonic()` sets the variable `t0` to the current time as returned by the `monotonic` method of the `time` module. The `monotonic` method returns the number of seconds that have passed since an unspecified time in the past, guaranteed never to go back even if the system time is changed.

```auto
t0 = time.monotonic()
```

## Storing Acceleration Data

These few lines use a `while` loop to read the `x`, `y`, and `z` components of the accelerometer’s acceleration and then store the variables.

```python
while True:
    x, y, z = accelerometer.acceleration
    t1 = time.monotonic()
    dt = t1 - t0

    total_acceleration = math.sqrt(x**2 + y**2 + z**2)
```

The sleep interval between two acceleration readings is determined by the `time_interval` variable. The code runs in a continuous loop until manually stopped.

```python
if total_acceleration >= threshold:
        print("Battery Percent: {:.2f} %".format(battery_monitor.cell_percent))
        print("Collision strength: %.2f" % total_acceleration)
        io.publish("punch-strength", total_acceleration)

        # add code here to trigger an event or alert the user
    t0 = t1
    time.sleep(time_interval)
```

## Displaying Collision Strength Data in Adafruit IO

In this `if`-statement, if the total acceleration is greater than or equal to the threshold, the battery percent and total acceleration will be displayed on the TFT, and the total acceleration value will be&nbsp;published to a&nbsp;feed named "punch-strength" in Adafruit IO.

Great! Let's attach components to the glove!

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Using PyLeap 

To upload this project to your ESP32-S2 TFT, select the project in the project list.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/118/367/medium800/wearables_IMG_1656mod.png?1675964412)

Then, once the project cell has collapsed, press the "Run it" button to download and transfer the project over to your ESP32-S2 TFT.

![](https://cdn-learn.adafruit.com/assets/assets/000/118/372/medium800/wearables_IMG_1657moded2.png?1675964655)

It's that easy! Now, let's set up an Adafruit IO account.

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Attaching the Components 

Danger: 

Before starting to pack the electronics into the glove, it is important to disconnect the battery from the ESP32-S3 TFT.

This is because the needle used to sew the ESP32-S3 TFT over the opening in the glove may hit the electronics, and it would not be safe to do so while the board is powered on.

Make a small incision in the wrist area of your boxing glove with an X-acto knife or pair of scissors. It should be 1 inch wide.

![wearables_ezgif.com-video-to-gif-2.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/385/medium640thumb/wearables_ezgif.com-video-to-gif-2.jpg?1675966528)

### Prepare the Components

&nbsp;

Once the battery is disconnected, you will want to pack the battery to the left and the accelerometer on the right into the incision you've made in the wrist area of the glove.&nbsp;

Check the diagram below for&nbsp;placement.

![wearables_ezgif.com-optimize-2.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/386/medium640thumb/wearables_ezgif.com-optimize-2.jpg?1675966877)

![](https://cdn-learn.adafruit.com/assets/assets/000/118/361/medium800/wearables_adafruit_io_Boxing_Glove_tracker_attachedmoded2.png?1675961593)

Make sure to add padding behind both electronics to secure them in place.

Also, leave some battery wire along with the connected JST sticking out of the opening for easy reconnection later.

### Secure the Electronics

&nbsp;

Now it's time to secure the electronics in place. With a needle and thread, sew the ESP32-S3 TFT over the opening, ensuring that the TFT covers the entire opening and that the edges are securely sewn to the glove.&nbsp;

![wearables_ezgif.com-crop-4.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/388/medium640thumb/wearables_ezgif.com-crop-4.jpg?1675967720)

This will keep the electronics in place and prevent them from shifting or coming loose during use. When your board is secure, plug the battery into the ESP32-S3 TFT.&nbsp;

# PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO

## Use

![](https://cdn-learn.adafruit.com/assets/assets/000/118/390/medium800/wearables_IMG_1630.png?1675969742)

After making sure you are connected to the internet and Adafruit IO on your TFT display, throw a few air punches to trigger the collision detection.

If you are not able to activate the collision detection, try lowering the threshold in the **code.py** file shown below in the code:

![wearables_ezgif.com-crop-5.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/399/medium640thumb/wearables_ezgif.com-crop-5.jpg?1675972327)

```auto
threshold = 25 # set threshold value here
```

When a punch is thrown, and collision(s) are detected, you should see the accelerometer data along with the battery percentage shown on the TFT display.

After receiving confirmation that you are connected to Adafruit IO, you should see new data points saved and added to a line graph on your feed.

![wearables_ezgif.com-video-to-gif-3.gif](https://cdn-learn.adafruit.com/assets/assets/000/118/403/medium640thumb/wearables_ezgif.com-video-to-gif-3.jpg?1675972876)

Be sure to customize this project however you'd like!&nbsp;


## Guide Products

### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
### ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI

[ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI](https://www.adafruit.com/product/1231)
Filling out our accelerometer offerings, we now have the really lovely digital ADXL345 from Analog Devices, a triple-axis accelerometer with digital I2C and SPI interface breakout. We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for...

In Stock
[Buy Now](https://www.adafruit.com/product/1231)
[Related Guides to the Product](https://learn.adafruit.com/products/1231/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)
### Lithium Ion Battery - 3.7V 2000mAh

[Lithium Ion Battery - 3.7V 2000mAh](https://www.adafruit.com/product/2011)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 2000mAh. If you need a larger (or smaller!) battery,&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2011)
[Related Guides to the Product](https://learn.adafruit.com/products/2011/guides)
### Pink and Purple Woven USB A to USB C Cable - 1 meter long

[Pink and Purple Woven USB A to USB C Cable - 1 meter long](https://www.adafruit.com/product/5153)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also made for USB C for our modernized breakout boards, Feathers, and more.&nbsp;&nbsp;[If you want something just like it but for Micro B, we...](https://www.adafruit.com/product/4111)

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

## Related Guides

- [Adafruit ESP32-S2 TFT Feather](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather.md)
- [CYBERDECK Bonnet and HAT for Raspberry Pi 400](https://learn.adafruit.com/cyberdeck-bonnet-and-hat.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [Mini Weather Station ESP32-S3 TFT](https://learn.adafruit.com/mini-weather-station-esp32-s2-tft.md)
- [Icicle Crown with Pebble Pixels & WLED](https://learn.adafruit.com/icicle-crown-with-pebble-pixels-wled.md)
- [Adafruit Fruit Jam](https://learn.adafruit.com/adafruit-fruit-jam.md)
- [PyLeap App](https://learn.adafruit.com/pyleap-app.md)
- [Using the CircuitPython Extension for Visual Studio Code](https://learn.adafruit.com/using-the-circuitpython-extension-for-visual-studio-code.md)
- [Glitter Positioning System](https://learn.adafruit.com/glitter-positioning-system.md)
- [PowerWash Simulator Nozzle Controller](https://learn.adafruit.com/powerwash-simulator-nozzle-controller.md)
- [4x4 Rotary Encoder MIDI Messenger](https://learn.adafruit.com/4x4-rotary-encoder-midi-messenger.md)
- [Touch Tone Phone Dial-a-Song](https://learn.adafruit.com/touch-tone-phone-dial-a-song.md)
- [RGB Matrix Portal Room CO2 Monitor](https://learn.adafruit.com/matrix-portal-room-co2-monitor.md)
- [QT Py RP2040 USB to Serial MIDI Friends](https://learn.adafruit.com/qt-py-rp2040-usb-to-serial-midi-friends.md)
- [Case for Feather RP2040 USB Host](https://learn.adafruit.com/case-for-feather-rp2040-usb-host.md)
- [NAU7802 Pet Food Scale](https://learn.adafruit.com/nau7802-pet-food-scale.md)
