# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/088/494/medium800/sensors_IMG_20200211_160001.jpg?1581965818)

Sip and Puff (SNP) devices are one example of Assistive Technology that allow one to interact with things by applying negative or positive pressure to a straw or tube in their mouth. This is done by either sipping on the tube, like a straw, or puffing into it, like when you blow bubbles in your milk until your parental unit (or partner) makes you stop.

Sip and Puff devices have been around for a while. They have helped many people who aren't able to use things like keyboards, mice or other input devices that were designed to be used with hands. There are a number of commercial options, however a newer trend is towards people and groups developing open source designs. These can be made with off the shelf and 3D printed parts by gathering the materials, assembling them, and programming them with open source software.

![](https://cdn-learn.adafruit.com/assets/assets/000/088/381/medium800/sensors_lip_sync.jpg?1581546181)

[There are many open source sip and puff devices around](https://www.google.com/search?q=open+source+sip+and+puff) A well-known example is [LipSync](https://www.makersmakingchange.com/project/lipsync/) which was developed by [Makers Making Change](https://www.makersmakingchange.com/about-us/), and released by the [Neil Squire Society](https://www.neilsquire.ca/about/) with support from [Google.org](https://www.google.org/). Lots of technical detail can be found on the project's [GitHub page](https://github.com/makersmakingchange/LipSync). The LipSync also integrates a joystick and mount for attaching to wheelchairs, and works as an input device to allow people operate a touchscreen device.

Here, we show how with the right sensors, microcontrollers, and software, it can be relatively easy to make a very basic but expandable Sip and Puff device. It is a fun, easy project that you can use to learn a bit more about them and how they might be used.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/088/380/medium800/sensors_lps33.jpg?1581546037)

The heart of this project is a STMicroelectronics (ST) LPS33HW MEMS pressure sensor mounted to an Adafruit breakout board with built in STEMMA QT connectors and support circuitry. Importantly the LPS33HW has a metal port on top like a hat and a groove for fitting an o-ring. With 24-bit pressure data output, an absolute pressure range of 260-1260 hPa ( [hectopascals](https://en.wikipedia.org/wiki/Pascal_(unit))) ), and the ability to work in absolute or relative modes, this sensor is the perfect tool for the job.

![](https://cdn-learn.adafruit.com/assets/assets/000/088/379/medium800/sensors_feather.jpg?1581546019)

The brains of the operation is a ST STM32F405 based express Feather running CircuitPython. The STM32F405 is a fast chip with plenty of memory so it's great for CircuitPython use, and the STEMMA QT connector on the end makes this a plug-n-play project

![](https://cdn-learn.adafruit.com/assets/assets/000/088/376/medium800/sensors_atmakersorg_logo.png?1581542812)

Many thanks are due to Bill Binko of [ATMakers.org](http://atmakers.org/) for his work making Assistive Technology more widely accessible, and for taking the time to educate me on Sip and Puffs and Assistive Technology in general. Bill has his own CircuitPython powered Sip and Puff, the [AirTalker](https://github.com/ATMakersOrg/AirTalker), developed with his friend Jim to meet his needs. It even includes [Morse Code](https://en.wikipedia.org/wiki/Morse_code) detection!

![](https://cdn-learn.adafruit.com/assets/assets/000/088/405/medium800/sensors_jim_and_bill.jpg?1581613624 Bill Binko (L) and Jim Lubin (R)  Photo Courtesy of Bill Binko)

## Parts and Materials
To follow along and make your own ST LPS33HW powered Sip and Puff, you'll need the items below. Additionally if you are inspired to take it further, check out the bits on the Extending the Capabilities page for more ideas.

### Part: Adafruit Feather STM32F405 Express
quantity: 1
The STM32 Feather that powers the project. Includes a SparkFun QWIIC/ Stemma QT socket
[Adafruit Feather STM32F405 Express](https://www.adafruit.com/product/4382)

### Part: Adafruit LPS33HW Water Resistant Pressure Sensor - STEMMA QT
quantity: 1
The ST pressure sensor with integrated port to attach the tubing
[Adafruit LPS33HW Water Resistant Pressure Sensor - STEMMA QT](https://www.adafruit.com/product/4414)

### Part: Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic
quantity: 1
Small OLED Display with STEMMA QT Connectors
[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)

### Part: STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long 
quantity: 2
STEMMA QT Cables to connect the Feather, Sensor and OLED screen
[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long ](https://www.adafruit.com/product/4210)

### Part: Silicone Tubing - 1 Meter
quantity: 1
Food Safe Silicone Tubing - The ultimate silly straw!
[Silicone Tubing - 1 Meter](https://www.adafruit.com/product/3659)

### Part: Small cable ties
quantity: 1
Small plastic cable ties to keep the tubing attached to the sensor
[Small cable ties](https://www.mcmaster.com/7130k101)

## Pick a Cable

The Feather STM32F405 Express requires a USB C cable which you may not have. Pick the one below that fits your computer. Most PCs will have USB Type A. Macs made in the last few years will likely have a USB C port which is also referred to as Thunderbolt.

If you're not sure, take a look at the pictures for each cable and compare them to the ports on your computer before ordering

### Part: USB C to USB C Cable
quantity: 1
A USB C Cable for the Feather STM32F405 for computers with USB C / Thunderbolt ports
[USB C to USB C Cable](https://www.adafruit.com/product/4199)

### Part: USB Type A to Type C Cable - approx 1 meter
quantity: 1
A USB C Cable for the Feather STM32F405 for computers with traditional USB Type A ports
[USB Type A to Type C Cable - approx 1 meter](https://www.adafruit.com/product/4474)

## Optional Tool: Flush Cutters
### Part: Flush Diagonal Cutters
quantity: 1
A very useful tool you'll use all the time. It'll come in handy to cut cable ties and tubing if needed
[Flush Diagonal Cutters](https://www.adafruit.com/product/152)

## Optional Fasteners:

The guide shows using these nylon screws, nuts, and standoffs to hold the boards together. Pick these up if you want to take that approach, or find a different M2.5 fastener if you wish to take a different approach.

Available in Black or White

### Part: Black Nylon Screw and Stand-off Set – M2.5 Thread
quantity: 1
A set of black M2.5 nylon screws, standoffs and nuts. 
[Black Nylon Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)

### Part: White Nylon Screw and Stand-off Set – M2.5 Thread
quantity: 1
A set of white M2.5 nylon screws, standoffs and nuts. 
[White Nylon Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3658)

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Assemble the Sensor

![](https://cdn-learn.adafruit.com/assets/assets/000/088/334/medium800/sensors_IMG_20200211_135103-2.jpg?1581473672)

It's assembly time! First off, we're going to affix the tubing to the sensor in order to sip and puff. The port on the LPS33 isn't really meant to have tubing attached directly to it, but if we take care, we can get a surprisingly robust attachment by using a cable tie to keep the tubing in place and sealed against the port. This is definitely an off label use of the sensor port, as it is meant to be sealed against an enclosure by installing an o-ring in the little groove and fitting the port into a precisely sized hole.

![](https://cdn-learn.adafruit.com/assets/assets/000/088/364/medium800/sensors_app_note_diagram.png?1581526865 This diagram from an application note for the LPS33HW shows the ideal use case. We're improvising!)

Before we start assembly, you'll want to make sure that the end of your tubing is cut nice and straight. We want the end of the tubing to be flat, at a right angle to tube itself. Having a flat end will allow the tubing to seal properly against the sensor's port and will allow us to get the tubing as close to the circuit board as possible.

You may use flush cutters to cut the end of the tubing nice and straight. If yours are dull, or you don't have any, you can use a nice sharp hobby knife to make a clean cut. Don't saw it, try to make the cut in one stroke.

![sensors_IMG_20200211_134352.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/366/medium640/sensors_IMG_20200211_134352.jpg?1581527359)

Next, prepare your cable tie by inserting the thin tip into the rectangular end and close the loop _nearly_&nbsp;all the way but not all the way. You want to leave room to insert the tubing.

If the cable tie doesn't make a zipping sound as you close it, you may have it backwards. When you are done it should have this shape:

![sensors_IMG_20200211_152750-2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/351/medium640/sensors_IMG_20200211_152750-2.jpg?1581963052)

Next, place the cable tie over the assuredly straight end and carefully close it a bit more until the tie is just big enough for the tubing to fit thorough unimpeded.

&nbsp;

Now we'll scoot the tie up the tubing a teeny bit and place the&nbsp; very straight end of the tubing over the little sensor port and carefully push the tubing down as close to the circuit board as you can. It may help to twist the tubing back and forth slightly as you go, kinda like turning a screwdriver back and forth.

![sensors_IMG_20200211_152911.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/352/medium640/sensors_IMG_20200211_152911.jpg?1581480194)

You probably won't be able to get the tubing all the way against the PCB, but you want to make sure there is enough of the port sticking into the tubing that when you tighten the cable tie, you will squish the tubing against the port, not just squeeze the tubing shut.

Once you've got the tubing as far down as you can, hold the tubing in place with one hand while scooting the cable tie back down the tubing towards the board.

![sensors_IMG_20200211_153225.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/491/medium640/sensors_IMG_20200211_153225.jpg?1581964566)

While the cable tie is still relatively loose, you may wish to rotate it around the tubing to make sure that you'll be able to pull it tight without bumping into the STEMMA QT connectors or something else on the board. Cable ties will rotate as you tighten them, so keep that in mind.

&nbsp;

Using one hand to keep the tube in place, use the other to start tightening the cable tie and get it _pretty_ tight, but not _too_ tight. Remember that this is _not_ how these sensors are meant to be used so we don't want to crank down on it too hard.

![sensors_IMG_20200211_153253.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/354/medium640/sensors_IMG_20200211_153253.jpg?1581480326)

When you are done, viewed from the side the tubing should be squished a bit by the cable tie

![sensors_IMG_20200211_153431.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/356/medium640/sensors_IMG_20200211_153431.jpg?1581480365)

Give the tubing a little tug (not a yank) and make sure that it doesn't come off. If it does, pull or cut the cable tie off the end of the tubing and try again. Fortunately, small cable ties like these usually come in packs of 100, so you'll have plenty of times to try.

Once you're happy with it, cut the floppy end of the cable tie off with your flush cutters. I highly recommend using flush cutters for this part because diagonal cutters or other tools will often leave a surprisingly sharp nub at the end. I speak from experience :|

Huzzah! You've successfully assembled the business end of your Sip and Puff.

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Plug it all Together

![](https://cdn-learn.adafruit.com/assets/assets/000/088/357/medium800/sensors_IMG_20200211_154014-3.jpg?1581481000)

With the tubing on the sensor, next is to assemble the pieces. We'll primarily be plugging together the Feather, LPS33, and OLED screen, however you will want to attach the pieces to something, otherwise moving the tubing will move everything else around, because the other pieces are so light.

For this simple project, we will use some handy dandy [nylon screws and nuts](https://www.adafruit.com/product/3299) to attach the pieces together using the mounting holes. You may choose to mount them all to something else like a small piece of wood, ideally something with a bit of heft to keep it in place.

## Screwing the Boards Together
First, place a **6mm M2.5 screw** through the bottom left mounting hole of the Feather.

Next, using your thumb or finger to hold it in place, put the screw through the top right mounting hole on the OLED screen. **Make sure the screen is _under_ the Feather** , otherwise it won't have the clearance needed.

Finally thread a **M2.5 nylon nut** onto the end of the screw and tighten it down to keep it in place. When you're done it should look something like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/088/358/medium800/sensors_IMG_20200211_154155.jpg?1581481094)

Next we'll repeat the process to attach the sensor to the screen.

Place another M2.5 6mm screw through the top left mounting hole of the **LPS33**. Hold the screw in place with a finger or [tacky putty](https://www.amazon.com/Loctite-Fun-Tak-Mounting-2-Ounce-1865809/dp/B018A3AG0W) and the put the screw through the bottom right mounting hole on the OLED.

Keep it all together by screwing your second M2.5 nylon nut onto the screw and tighten it down to keep it all together.

Similar to attaching the screen to the Feather, the order of the boards matters when attaching the sensor to the OLED. **The LPS33 must be on top** &nbsp;or you'll run into clearance issues.

Now you should have something that looks like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/088/359/medium800/sensors_IMG_20200211_154526.jpg?1581481124)

## Plug and Play

The last step is the easiest: connect the boards together using [SparkFun QWIIC](https://www.sparkfun.com/qwiic)&nbsp;compatible**&nbsp;[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)** cables. As long as everything is connected, the order doesn't matter, but I found the routing below aesthetically pleasing.

Wired together it should look like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/088/367/medium800/sensors_assembled_pieces.jpg?1581528380)

## Optional but Suggested

As assembled, everything will work just fine, however I would suggest using another one of your cable ties to hold the tubing against the [USB-C cable](https://www.adafruit.com/?q=USB-C) that you will use to connect the Feather to your computer.

Simply plug the cable in and fold the tubing over against the cable and use a cable tie to hold the tubing and cable together, making sure to have a gentle bend to the tubing so the airflow isn't blocked.

Giving the tubing a bit of a twist will help curve it out of the way of the screen.  
  
Like when you attached the tubing to the sensor, you want to hold the cable and tubing together snugly but not so hard that you squish the tubing shut (a teeny bit of squish is OK)

![sensors_cable_ready.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/368/medium640/sensors_cable_ready.jpg?1581534600)

![sensors_cable_tied.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/369/medium640/sensors_cable_tied.jpg?1581534653)

If you are successful, now when your dog or toddler decides to play tug of war with the tubing, it will pull on the comparatively robust cable and not the sensor. This type of connection is called [strain relief](https://en.wikipedia.org/wiki/Cable_management#Cable_strain_relief) and they are commonly used with things like cables that will be tugged on and moved about.

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## CircuitPython Setup

To load CircuitPython, follow the **DFU Bootloader** instructions to get the board into bootloader mode

Visit [https://circuitpython.org/board/feather\_stm32f405\_express/](https://circuitpython.org/board/feather_stm32f405_express/) To get the latest firmware available

![](https://cdn-learn.adafruit.com/assets/assets/000/083/674/medium800/feather_boards_image.png?1573011908)

Download the **bin** file, and then program it using [**dfu-util** or **STM32CubeProgrammer**](https://learn.adafruit.com/adafruit-stm32f405-feather-express/dfu-bootloader-details)

Upon success, reset the board without the **BOOT0** jumper and you will see after a few seconds the **CIRCUITPY** disk drive appear

![](https://cdn-learn.adafruit.com/assets/assets/000/083/679/medium800/feather_boards_image.png?1573012173)

Next you can visit [https://learn.adafruit.com/welcome-to-circuitpython](https://learn.adafruit.com/welcome-to-circuitpython)and [https://learn.adafruit.com/circuitpython-essentials/](https://learn.adafruit.com/circuitpython-essentials/) to learn more about CircuitPython

# CircuitPython Notes

If you are intending to start a project that is very RAM intensive, note you cannot access the full 196KB of RAM that listed on the F405 datasheet and website - only 128KB is available to Circuitpython programs for system reasons. You'll find the same limitation on Micropython and most other F405 devices.

STM32F4 support is new compared to the SAMD and nRF boards, but is now considered stable. Working modules on this board include:

- Digital IO (LEDs/buttons)
- analog input
- analog output (DAC)
- PWM output on timer pins
- I2C
- SPI
- [NeoPixel Support](https://github.com/adafruit/circuitpython/issues/2264)
- [UART Support](https://github.com/adafruit/circuitpython/pull/2211)
- DisplayIO
- PulseIO

To come:

- I2S
- Audio
- TouchIO
- many others!

[If you find something missing or flawed, please open an issue in circuitpython](https://github.com/adafruit/circuitpython/issues?q=is%3Aissue+is%3Aopen+label%3Astm)

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Installing the Mu Editor

Mu is a simple code editor that works with the Adafruit CircuitPython boards. It's written in Python and works on Windows, MacOS, Linux and Raspberry Pi. The serial console is built right in so you get immediate feedback from your board's serial output!

Info: Mu is our recommended editor - please use it (unless you are an experienced coder with a favorite editor already!). While it has been announced end of life in 2026, it still works fine.

You are free to use whatever text editor you wish along with a terminal program to connect to the CircuitPython REPL. Thonny is one such editor.

## Download and Install Mu
Download Mu from&nbsp;[https://codewith.mu](https://codewith.mu/).

Click the&nbsp; **Download** link for downloads and installation instructions.

Click **Start Here&nbsp;** to find a wealth of other information, including extensive tutorials and and how-to's.

&nbsp;

![circuitpython_WtCP_codewithdotmu_main_page.png](https://cdn-learn.adafruit.com/assets/assets/000/105/677/medium640/circuitpython_WtCP_codewithdotmu_main_page.png?1634749167)

Warning: 

## Starting Up Mu
The first time you start Mu, you will be prompted to select your 'mode' - you can always change your mind later. For now please select **CircuitPython**!

The current mode is displayed in the lower right corner of the window, next to the "gear" icon. If the mode says "Microbit" or something else, click the **Mode** button in the upper left, and then choose "CircuitPython" in the dialog box that appears.

![circuitpython_WtCP_Mu_mode_dialogue.png](https://cdn-learn.adafruit.com/assets/assets/000/105/681/medium640/circuitpython_WtCP_Mu_mode_dialogue.png?1634750676)

Mu attempts to auto-detect your board on startup, so if you do not have a CircuitPython board plugged in with a **CIRCUITPY** drive available, Mu will inform you where it will store any code you save until you plug in a board.

To avoid this warning, plug in a board and ensure that the **CIRCUITPY** drive is mounted before starting Mu.

![circuitpython_WtCP_Mu_device_not_found.png](https://cdn-learn.adafruit.com/assets/assets/000/105/679/medium640/circuitpython_WtCP_Mu_device_not_found.png?1634749722)

## Using Mu

You can now explore Mu! The three main sections of the window are labeled below; the button bar, the text editor, and the serial console / REPL.

![](https://cdn-learn.adafruit.com/assets/assets/000/098/505/medium800/circuitpython_Mu_Window_Explained.png?1609970219)

Now you're ready to code! Let's keep going...

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## CircuitPython Code

![](https://cdn-learn.adafruit.com/assets/assets/000/088/361/medium800/sensors_IMG_20200211_165406.jpg?1581481721)

Now that you've got your pieces assembled and have CircuitPython installed on the Feather STM32F405 Express, all you have to do is is copy over a bit of code we've written to make the whole thing go. Before you continue, you'll want to make sure that your Feather is plugged into your machine and your operating system file explorer/finder has the board showing up as a drive named **CIRCUITPY**.

## Installing Project Code

To use with CircuitPython, you need to first install a few libraries, into the lib folder on your **CIRCUITPY** drive. Then you need to update **code.py** with the example script.

Thankfully, we can do this in one go. In the example below, click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, open the directory **REPLACE/** and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your **CIRCUITPY** drive.

Your **CIRCUITPY** drive should now look similar to the following image:

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/CircuitPython_Sip_and_Puff.png )

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

## Sip and Puff code on GitHub

If you wish to access the code on GitHub, it can be found [in this directory](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/CircuitPython_Sip_and_Puff)

The board should come up with the starting screen! If you see any errors, check the Mu editor's REPL for warnings or failures

![](https://cdn-learn.adafruit.com/assets/assets/000/088/400/medium800/sensors_IMG_20200211_165406.jpg?1581559246)

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Usage

## Using the Sip and Puff Code

Once installed and running, the code is pretty simple. When the program starts it will set the currently measured barometric air pressure and set it as **0**  **hPa** so that the following measurements are made relative to it. While idle the screen will display the following:

- **WAITING FOR INPUT -** This is the current measurement state. This will be updated during use to include the current measurement state to be one of **WAITING FOR INPUT** , **SIP/PUFF STARTED...** ,&nbsp; or **DETECTED:**
- **min -** The low pressure threshold in hPa. Any measurement negative or positive will have to be this many hPa above or below the ambient pressure. This helps prevent incidental variations in the air pressure from triggering events when not intended. You may wish to tune this value to your particular needs
- **hi -&nbsp;** The high pressure threshold in hPa. Measurements that are this many hPa above or below ambient pressure will be registered as a **Strong** event. Anything below it but above the low pressure threshold will be registered as a **Soft** event
- **Press -** The current pressure measurement in hPa. This value will vary in real time as negative or positive pressure is applied to the sensor. You can use these measurements to determine what your min and hi thresholds should be. If you watch this measurement while the sensor is idle, you will be able to see the regular variations in ambient pressure that make the low threshold necessary.

## Detecting Sips
While the program and sensor are idle, applying positive pressure above the **min** amount will trigger the start of a puff event.

If you don't exceed the **hi&nbsp;** threshold, releasing the pressure will result in a **SOFT SIP** &nbsp;event being triggered.  
  
If you&nbsp;_do_ exceed the&nbsp; **hi&nbsp;** threshold, when you release the pressure it will trigger a **STRONG PUFF** event.

Along with the type of event detected, the&nbsp; **Duration** of the event in seconds will be displayed.

![sensors_sip_started_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/396/medium640/sensors_sip_started_fin.jpg?1581552545)

![sensors_soft_sip_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/397/medium640/sensors_soft_sip_fin.jpg?1581552575)

![sensors_strong_sip_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/399/medium640/sensors_strong_sip_fin.jpg?1581552769)

Along with the information displayed on the OLED screen, the pressure events will also be printed to the serial console:

![](https://cdn-learn.adafruit.com/assets/assets/000/088/402/medium800/sensors_REPL_SIPS.png?1581577991)

## Detecting Puffs
While the program and sensor are idle, applying positive pressure above the **min** amount will trigger the start of a puff event.

If you don't exceed the **hi&nbsp;** threshold, releasing the pressure will result in a **SOFT PUFF** event being triggered.  
  
If you&nbsp;_do_ exceed the&nbsp; **hi&nbsp;** threshold, when you release the pressure it will trigger a **STRONG PUFF** event.

Along with the type of event detected, the&nbsp; **Duration** of the event in seconds will be displayed.

![sensors_puff_started_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/392/medium640/sensors_puff_started_fin.jpg?1581552282)

![sensors_soft_puff_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/394/medium640/sensors_soft_puff_fin.jpg?1581552319)

![sensors_string_puff_fin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/088/395/medium640/sensors_string_puff_fin.jpg?1581552352)

Like with sips, puff events will be printed to the serial log as well:

![](https://cdn-learn.adafruit.com/assets/assets/000/088/403/medium800/sensors_repl_puffs.png?1581578046)

## Configuring the Pressure Thresholds

Since people will have their own needs when it comes to how much or little pressure they will want to to trigger events, we've made it possible for you to easily change these thresholds by adding a simple JSON file to the root of the **CIRCUITPY** drive along with the code. Edit the JSON below to have your desired pressures and then save it to the **CIRCUITPY** drive, making to preserve the filename of&nbsp; **settings.json**

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Sip_and_Puff/settings.json

# CircuitPython Powered Sip & Puff with ST LPS33HW Pressure Sensor

## Extending the Capabilites

![](https://cdn-learn.adafruit.com/assets/assets/000/088/404/medium800/sensors_1-12420681401bD2.jpg?1581583030 Public Domain via publicdomainpictures.org)

While and interesting demonstration of how it works, the demo on the previous page isn't all that useful. Currently all that the code in **code.py** is doing when an event is triggered is printing the event type and duration to the serial console as it's only meant to demonstrate the basic functioning of the puff detector.

By modifying the basic structure and content of the demonstration code and combining it with bits and pieces from our many CircuitPython demos, you can make the Sip and Puff trigger all sorts of things.

## Call Me Maybe?

The [_sine qua non_](https://www.merriam-webster.com/dictionary/sine%20qua%20non) of the demo code is the pair of `on_` functions,&nbsp; `on_sip` and `on_puff` that get called when the corresponding pressure event is detected. This type of function is usually referred to as a _ **callback** _ and is very common when writing code that reacts to user input. We will take a look at the `on_sip` function as an example as the two functions work the same but for different pressure events.

```python
@detector.on_sip
def on_sip(strength, duration):
    if strength == puff_detector.STRONG:
        print("GOT STRONG SIP")
    if strength == puff_detector.SOFT:
        print("GOT SOFT SIP")
    print("%.2f long" % duration)
```

`on_sip` is a simple function that you provide to define the behavior that you want to happen when a sip event is detected. When a sip event happens, It gets called with two parameters,&nbsp;

- `strength` indicates if the event was `SOFT` or `STRONG` and can be compared to the constants of the same names in the `puff_detector` module
- `duration` is the duration of time that the sip event took from beginning to end.

You may wonder "how does the puff detector know what to call?". The answer to that question the the short statement above the `on_sip` function that starts with an `@`

```python
@detector.on_sip
```

This statement tells the `detector` that the function that follows should be remembered or _registered_ as a function that should be called when the corresponding event happens.&nbsp;

You might imagine leaving a voicemail for your friend where you say "call me on Friday to let me know if you will come to my party". Unfortunately they'll probably miss your party because no one checks their voice mail anymore, but none the less you could think of leaving that message as registering a callback with your friend. If your friend was a Feather STM32F305 Express or other micro running CircuitPython, you might imagine programming them like so:

```python
@friend.on_friday
def on_friday(rsvp):
  if rsvp:
    print("We're gonna need more guacamole")
  else:
    print("We're gonna need more tupperware for all this guacamole")
```

## Make it Your Own

To get the sip and puff to do all manner of thinks, all you have to do is make your own functions that do what you want to happen when a pressure event happens, and then register it as a callback. That's all there is to it!


## Featured Products

### Adafruit Feather STM32F405 Express

[Adafruit Feather STM32F405 Express](https://www.adafruit.com/product/4382)
ST takes flight in this Feather board. The new STM32F405 Feather ([video](https://youtu.be/CZ6TtvYJTeI)) that we designed runs CircuitPython at a blistering 168MHz – our fastest CircuitPython board ever! We put a STEMMA QT / Qwiic port on the end, so you can really easily plug...

In Stock
[Buy Now](https://www.adafruit.com/product/4382)
[Related Guides to the Product](https://learn.adafruit.com/products/4382/guides)
### Adafruit LPS33HW Water Resistant Pressure Sensor - STEMMA QT

[Adafruit LPS33HW Water Resistant Pressure Sensor - STEMMA QT](https://www.adafruit.com/product/4414)
Sometimes you need to sense pressure in a damp or caustic environment. And sometimes you need to know the relative changes in pressure as well as the absolute pressure. For the times you need to do both (or either), the LPS33HW is the pressure sensor for you. Combining protection from water...

In Stock
[Buy Now](https://www.adafruit.com/product/4414)
[Related Guides to the Product](https://learn.adafruit.com/products/4414/guides)
### Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic

[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

In Stock
[Buy Now](https://www.adafruit.com/product/938)
[Related Guides to the Product](https://learn.adafruit.com/products/938/guides)
### Silicone Tubing for Peristaltic Liquid Pump - 1 Meter

[Silicone Tubing for Peristaltic Liquid Pump - 1 Meter](https://www.adafruit.com/product/3659)
Move fluid from here to there with this very nice elastomeric silicone tubing, specifically for [our peristaltic pumps.](https://www.adafruit.com/?q=peristaltic) It's one meter long and fully silicone with the correct diameter to give great peristaltic performance.  
<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/3659)
[Related Guides to the Product](https://learn.adafruit.com/products/3659/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...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long

[USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long](https://www.adafruit.com/product/4199)
As technology changes and adapts, so does Adafruit! Rather than the regular USB A, this cable has&nbsp; **USB C to USB C** &nbsp;plugs!

USB C is the latest industry-standard connector for transmitting data&nbsp;_and_&nbsp;power. Like Lightning and MagSafe cables, USB C...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4199)
[Related Guides to the Product](https://learn.adafruit.com/products/4199/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

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

## Related Guides

- [Adafruit LPS33/LPS35 Water Resistant Pressure Sensor](https://learn.adafruit.com/lps35hw-water-resistant-pressure-sensor.md)
- [Adafruit STM32F405 Feather Express](https://learn.adafruit.com/adafruit-stm32f405-feather-express.md)
- [CircuitPython OLED and Dual Knob Sketcher](https://learn.adafruit.com/circuitpython-oled-knob-sketcher.md)
- [Gravity Falls Memory Gun](https://learn.adafruit.com/gravity-falls-memory-gun.md)
- [Animating Animatronics](https://learn.adafruit.com/animating-animatronics.md)
- [Wireless NeoPixel Controller](https://learn.adafruit.com/neotrellis-neopixel-controller.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [Magic Band Reader](https://learn.adafruit.com/magic-band-reader.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
- [CYBERDECK Expansion Plate](https://learn.adafruit.com/cyberdeck-plate.md)
- [ESP32-S3 BLE RS-232 Controller](https://learn.adafruit.com/esp32-s3-ble-rs232-controller.md)
- [Blinking an LED with the Zephyr RTOS](https://learn.adafruit.com/blinking-led-with-zephyr-rtos.md)
- [Feather TFT STEMMA Case](https://learn.adafruit.com/feather-tft-stemma-case.md)
- [Pi SSD Media Server](https://learn.adafruit.com/pi-ssd-media-server.md)
- [Automatic Naughty Cat Detector using Lobe](https://learn.adafruit.com/naughty-cat-detector-using-microsoft-lobe.md)
- [NeoPixel Menorah](https://learn.adafruit.com/neopixel-menorah.md)
- [USB MIDI Host Messenger](https://learn.adafruit.com/usb-midi-host-messenger.md)
