# Programmable Wireless BLE Gesture Mouse

## Overview

https://youtu.be/Mx4dEaTXgFA

Most computers require a mouse to navigate the user interface. In this project, you'll learn how you can build a mouse that connects via Bluetooth BLE and converts accelerometer readings to mouse cursor movements.

![](https://cdn-learn.adafruit.com/assets/assets/000/104/404/medium800/proximity_hero-case-feather.jpg?1631123162)

The project is built around the Adafruit Feather nRF52840 Sense. It has BLE connectivity and a lot of onboard sensors. Its accelerometer is used for sending movement data that is converted to move your mouse cursor around the screen.

![proximity_hero-case-open.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/406/medium640/proximity_hero-case-open.jpg?1631123415)

Right-clicks are sent with the onboard button. Scrolling is done by covering the proximity sensor and tilting the Feather nRF52840 Sense up or down depending on the direction that you want to scroll.&nbsp;

The 3D printed case features cut-outs on the top so that you can access the button and proximity sensor while keeping your board protected.

![proximity_hero-mouse-click.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/405/medium640/proximity_hero-mouse-click.jpg?1631123380)

## Parts
Parts from Adafruit used to build this project.

- [Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
- [Slide Switch](https://www.adafruit.com/product/805)
- [400mAh Battery](https://www.adafruit.com/product/3898)
- [M2.5 Hardware](https://www.adafruit.com/product/3299)
- [Silicon Ribbon Wire](https://www.adafruit.com/product/3890)

&nbsp;

![proximity_parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/360/medium640/proximity_parts.jpg?1630934285)

Featured
### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
![Angled shot of blue, rectangular, microcontroller.](https://cdn-shop.adafruit.com/640x480/4516-06.jpg)

Featured
### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

In Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)
![Small, black, SPDT slide switch.](https://cdn-shop.adafruit.com/640x480/805-03.jpg)

Featured
### Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh

[Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh](https://www.adafruit.com/product/3898)
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 **400mAh** for a total of about 1.9 Wh. If you need a larger (or smaller!)...

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

Featured
### 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)
![Black Nylon Screw and Stand-off Set with M2.5 Threads, kit box](https://cdn-shop.adafruit.com/640x480/3299-00.jpg)

Featured
### Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long

[Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long](https://www.adafruit.com/product/3890)
For those who are fans of our silicone-covered wires, but are always looking to _up their wiring game_. We now have **Silicone Cover Ribbon cables!** These may look _a lot_ like <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3890)
[Related Guides to the Product](https://learn.adafruit.com/products/3890/guides)
![10 wire Silicone Cover Stranded-Core Ribbon Cable](https://cdn-shop.adafruit.com/640x480/3890-01.jpg)

# Programmable Wireless BLE Gesture Mouse

## CircuitPython on Feather Sense

[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.

The following instructions will show you how to install CircuitPython. If you've already installed CircuitPython but are looking to update it or reinstall it, the same steps work for that as well!

## Set up CircuitPython Quick Start!

Follow this quick step-by-step for super-fast Python power :)

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

&nbsp;

Download and save it to your desktop (or wherever is handy).

![sensors_Feather_Sense_UF2_download.png](https://cdn-learn.adafruit.com/assets/assets/000/089/139/medium640/sensors_Feather_Sense_UF2_download.png?1583870836)

Plug your Feather Sense into your computer using a known-good USB cable.

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

Double-click the **Reset** button next to the USB connector on your board, and you will see the NeoPixel RGB LED turn green (identified by the arrow in the image). If it turns red, check the USB cable, try another USB port, etc. **Note:** The little red LED next to the USB connector will pulse red. That's ok!

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

![sensors_Feather_Sense_NeoPixel.jpg](https://cdn-learn.adafruit.com/assets/assets/000/089/140/medium640/sensors_Feather_Sense_NeoPixel.jpg?1583870890)

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

&nbsp;

&nbsp;

&nbsp;

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

![sensors_Feather_Sense_FTHRSNSBOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/089/141/medium640/sensors_Feather_Sense_FTHRSNSBOOT.png?1583870933)

![sensors_Feather_Sense_Drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/089/142/medium640/sensors_Feather_Sense_Drag_UF2.png?1583870948)

The LED will flash. Then, the&nbsp; **FTHRSNSBOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

&nbsp;

That's it, you're done! :)

![sensors_Feather_Sense_CIRCUITPY.png](https://cdn-learn.adafruit.com/assets/assets/000/089/143/medium640/sensors_Feather_Sense_CIRCUITPY.png?1583870972)

Warning: 

# Programmable Wireless BLE Gesture Mouse

## Code the BLE Gesture Mouse

Once you've finished setting up your Feather nRF52840 Sense with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

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

## Upload the Code and Libraries to the Feather nRF52840 Sense
After downloading the Project Bundle, plug your Feather nRF52840 Sense into the computer's USB port. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the Feather nRF52840 Sense's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your Feather nRF52840 Sense **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp;lib&nbsp;folder and the **code.py** &nbsp;file.

![](https://cdn-learn.adafruit.com/assets/assets/000/104/394/medium800/proximity_bleGestureMouseFiles.jpg?1631103319)

## How the CircuitPython Code Works
The Feather nRF52840 Sense is able to use the onboard accelerometer's x and y position data to move your computer's mouse around the screen. The `lsm6ds33` is setup at the beginning of the code.

```python
#  setup accelerometer
lsm6ds33 = adafruit_lsm6ds.lsm6ds33.LSM6DS33(i2c)
```

In the loop, `x` and `y` are setup to hold the value of the `lsm6ds33`'s coordinates.

The&nbsp;`map_range()` function from the `simpleio` library is used to convert the accelerometer data to usable mouse movement data for both vertical and horizontal movement. The degree of motion from the accelerometer also affects the speed of the mouse's cursor movements.

Additionally, `map_range()` is used for scrolling, converting the mapped vertical movement of the mouse to scrolling direction and speed.

```python
while ble.connected:
        #  sets x and y values for accelerometer x and y values
        #  x and y are swapped for orientation of feather
        y, x, z = lsm6ds33.acceleration

        #  map range of horizontal movement to mouse x movement
        horizontal_mov = simpleio.map_range(steps(x), 1.0, 20.0, -15.0, 15.0)
        #  map range of vertical movement to mouse y movement
        vertical_mov = simpleio.map_range(steps(y), 20.0, 1.0, -15.0, 15.0)
        #  map range of mouse y movement to scrolling
        scroll_dir = simpleio.map_range(vertical_mov, -15.0, 15.0, 3.0, -3.0)
```

Left-clicks are sent with the Feather nRF52840 Sense's onboard button.

```python
#  if onboard button is pressed, sends left mouse click
        if not click.value:
            mouse.click(Mouse.LEFT_BUTTON)
            time.sleep(0.2)
```

Scrolling is done by covering the APDS9960 proximity sensor and tilting the Feather Sense up or down. If the proximity sensor is covered, then `mouse.move(wheel=int``(scroll_dir))` is sent. Otherwise, the mouse's cursor will move freely around the screen.

```python
#  if the proximity sensor is covered
        #  scroll the mouse
        if apds9960.proximity > distance:
            mouse.move(wheel=int(scroll_dir))
        #  otherwise move mouse cursor in x and y directions
        else:
            mouse.move(x=int(horizontal_mov))
            mouse.move(y=int(vertical_mov))
```

The value that triggers scrolling can be adjusted with the `distance` variable if you need to increase or decrease sensitivity.

```python
#  variable for distance for proximity scrolling
distance = 245
```

# Programmable Wireless BLE Gesture Mouse

## 3D Printing

## CAD Parts List

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material. Original design source may be downloaded using the links below.

- blemouse-top-cover.stl
- blemouse-case.stl

![proximity_cad-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/410/medium640/proximity_cad-parts.jpg?1631123883)

## CAD Assembly

The Feather nRF52840 Sense is secured to the case with 4x M2.5 x 10mm screws and hex nuts. The slide switch press fits into the built-in holder. The battery is placed next to the Feather. The top cover snap fits over the case with access to the proximity sense and a button actuator for the on-board user switch.

![sensors_cad-explode.gif](https://cdn-learn.adafruit.com/assets/assets/000/104/439/medium640thumb/sensors_cad-explode.jpg?1631192534)

[Download CAD source](https://cdn-learn.adafruit.com/assets/assets/000/104/411/original/CAD.zip?1631124049)
[Download STLs.zip](https://cdn-learn.adafruit.com/assets/assets/000/104/412/original/STLs.zip?1631124062)
## Slicing Parts

No supports are required. Slice with setting for PLA material.&nbsp;

The parts were sliced using CURA using the slice settings below.

- PLA filament 220c extruder
- 0.2 layer height
- 10% gyroid infill
- 60mm/s print speed
- 60c heated bed

![proximity_cura-slicer.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/407/medium640/proximity_cura-slicer.jpg?1631123611)

## Design Source Files

The project assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, STL and more. Electronic components like Adafruit's board, displays, connectors and more can be downloaded from the&nbsp;[Adafruit CAD parts GitHub Repo](https://github.com/adafruit/Adafruit_CAD_Parts).

![proximity_4516-Feather-nRF52840.gif](https://cdn-learn.adafruit.com/assets/assets/000/104/408/medium640thumb/proximity_4516-Feather-nRF52840.jpg?1631123714)

# Programmable Wireless BLE Gesture Mouse

## Wiring Switch

## Wire for Switch

Use a piece of ribbon cable to connect the switch to the Feather. A 2-wire piece will connect to the Enable and Ground pins.

Wire Length: 9cm (3.5in)

![proximity_parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/361/medium640/proximity_parts.jpg?1630934464)

## Tinning Wire

Using wire stripper, remove a bit of insulation for the tips of each wire. Add a bit of solder to the exposed wire. This will help to prevent the strands of wire from fraying.

Use a pair of helping third hands to hold the wire in place while soldering.

![proximity_switch-wire-tinning.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/362/medium640/proximity_switch-wire-tinning.jpg?1630934528)

## Solder Wire

Cut one of the three leads from the slide. Either the far left or right but not the middle! Trim the remaining leads short, about half the original length.

Add a bit of solder to the leads of the slide switch. This will make it easier to attach the wires.

Solder the 2-wire ribbon cable to the leads on the slide switch.

![proximity_switch-wire-solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/363/medium640/proximity_switch-wire-solder.jpg?1630934599)

## Wired Switch

Double check the solder joints in the wire and slide are solid and properly soldered.

![proximity_switch-wire-soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/364/medium640/proximity_switch-wire-soldered.jpg?1630934635)

## Solder Switch to Feather

Add a bit of solder to the Enable and Ground pins on the bottom of the Feather.

Solder the wires to the Enable and Ground pins on the Feather.

Use helping third hands to keep the board in place while soldering.

![proximity_switch-feather-wire.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/365/medium640/proximity_switch-feather-wire.jpg?1630934680)

## Feather Switch

Double check the Enable and Ground pins have been properly soldered to the wires.

![proximity_switch-feather-soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/366/medium640/proximity_switch-feather-soldered.jpg?1630934727)

# Programmable Wireless BLE Gesture Mouse

## Assembly

## Screws for Case

Use the following hardware to secure the Feather to the case.

- 4x M2.5 x 10mm screws
- 4x M2.5 hex nuts

![proximity_case-feather-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/367/medium640/proximity_case-feather-screws.jpg?1630934745)

## Install Hardware

Start by inserting an M2.5 screw through one of the mounting holes on the bottom of the case.

![proximity_case-screw-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/368/medium640/proximity_case-screw-install.jpg?1630935205)

## Secure Feather

While holding the screw in place, install the Feather into the case with the USB port facing the cut out. Line up the mounting holes and fit the screw through the mounting hole.

Insert and fasten hex nuts to the screw to secure the Feather to the case. Repeat for the remaining mounting holes.

![proximity_case-nuts-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/369/medium640/proximity_case-nuts-install.jpg?1630934821)

## Install Switch

Insert the slide switch into the built-in holder with the actuator fitting through the hole. Fit the body of the slide switch at an angle and firmly press fit down into place.

![proximity_case-switch-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/370/medium640/proximity_case-switch-install.jpg?1630934921)

## Switch Actuator

The actuator from the switch should be accessible through the side of the case. The built-in holder keeps the slide switch in place and prevents it from being pressed all the way into the case.

![proximity_case-switch-nub.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/371/medium640/proximity_case-switch-nub.jpg?1630935021)

## Connect Battery

Plug in the power cable from the 400mAh battery to the JST connector on the Feather.

![proximity_battery-plug.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/372/medium640/proximity_battery-plug.jpg?1630935143)

## Install Battery

Fit the battery into the case and place it right above the slide switch holder. Optionally use mounting tack or double-sided tape to keep the battery secured in place.

![proximity_battery-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/373/medium640/proximity_battery-installed.jpg?1630935175)

## Install Cover

Orient the top cover with the case. The top cover features a built-in actuator for the User Switch on the Feather. The hole allows accessible to the proximity sensor.

![proximity_case-cover-orient.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/374/medium640/proximity_case-cover-orient.jpg?1630935292)

## Snap Fit Cover

Place the top cover over the case and firmly press them together to snap fit closed.

![proximity_case-cover-snapfit.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/375/medium640/proximity_case-cover-snapfit.jpg?1630935320)

## Case USB port

The microUSB port is accessible on the back side of the case. Use the microUSB port for programming and recharging the 400mAh battery.

![proximity_case-usb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/376/medium640/proximity_case-usb.jpg?1630935401)

# Programmable Wireless BLE Gesture Mouse

## BLE Pairing

## BLE Pairing – MacOS

To pair the CircuitPython device to macOS, open the System Preferences app. Click on the Bluetooth icon.

In the bottom of the list of BLE devices, click on the **CIRCUITPY** device. Click the connect button to pair.

To disconnect or remove the BLE device, click on the X icon next to the label.

![proximity_macos-ble-connect.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/413/medium640/proximity_macos-ble-connect.jpg?1631124340)

![proximity_macos-ble-connected.jpg](https://cdn-learn.adafruit.com/assets/assets/000/104/414/medium640/proximity_macos-ble-connected.jpg?1631124442)


## Guide Products

### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

In Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)
### Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh

[Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh](https://www.adafruit.com/product/3898)
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 **400mAh** for a total of about 1.9 Wh. If you need a larger (or smaller!)...

In Stock
[Buy Now](https://www.adafruit.com/product/3898)
[Related Guides to the Product](https://learn.adafruit.com/products/3898/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)
### Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long

[Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long](https://www.adafruit.com/product/3890)
For those who are fans of our silicone-covered wires, but are always looking to _up their wiring game_. We now have **Silicone Cover Ribbon cables!** These may look _a lot_ like <a...></a...>

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

## Related Guides

- [Adafruit Feather nRF52840 Sense](https://learn.adafruit.com/adafruit-feather-sense.md)
- [Qualia S3 Compass](https://learn.adafruit.com/qualia-s3-compass.md)
- [Buttermilk Boat with Circuit Playground Express](https://learn.adafruit.com/boat-with-circuit-playground-express.md)
- [Arcade Fightstick](https://learn.adafruit.com/arcade-fightstick.md)
- [Party Parrot Zoetrope](https://learn.adafruit.com/party-parrot-zoetrope.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
- [LED Matrix Scoreboard](https://learn.adafruit.com/led-matrix-scoreboard.md)
- [Eye of Newt](https://learn.adafruit.com/eye-of-newt.md)
- [Superhero Power Gauntlet](https://learn.adafruit.com/superhero-power-gauntlet.md)
- [Pick the Perfect Plant: Battery-Powered Sun Tracking](https://learn.adafruit.com/battery-powered-sun-tracking.md)
- [Grill Thermometer Dashboard](https://learn.adafruit.com/grill-thermometer-dashboard.md)
- [Building the Assistive Technology Ultimate Remote](https://learn.adafruit.com/building-the-assistive-technology-ultimate-remote.md)
- [Pip-Boy 2040 Wrist-Mounted Prop](https://learn.adafruit.com/pip-boy-2040.md)
- [Chilled Drinkibot](https://learn.adafruit.com/chilled-drinkibot.md)
- [Pico W YBox3](https://learn.adafruit.com/pico-w-ybox3.md)
- [Circuit Playground Seashell Pendant](https://learn.adafruit.com/circuit-playground-seashell-pendant.md)
