# Desk Calculator with CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/103/366/medium800thumb/projects_ezgif.com-optimize%287%29.jpg?1626183473)

Consider the humble calculator. Now just an app that you always have with you on your telephone, an electronic calculator used to be a [technological marvel](https://www.thecalculatorsite.com/articles/units/history-of-the-calculator.php).

In this project, you'll build your own calculator with an Adafruit Feather RP2040, 128x64 OLED display, and 20 keys. Optional 3D printed parts like an enclosure and even the keycaps themselves make for a sharp presentation. Make it your own by customizing the code, or use the hardware for your own MacroPad-inspired project.

## Custom Printed Circuit Board

This project needs a custom PCB. You can pick up the [KiCad](https://www.kicad.org/) (design) files or the Gerber (production) files below and upload them to the PCB house of your choice, or you can [use this link to order them from OSH Park](https://oshpark.com/shared_projects/Jmfp8iGD). You are free to modify the design files and use them in your own designs. (In copyright terms, the design files are [licensed as CC0](https://creativecommons.org/publicdomain/zero/1.0/))

OSH Park's standard turnaround is 9 to 12 days from order to shipment, so plan accordingly.

The board files were designed in [KiCad](https://www.kicad.org/), open source software that is free to download & use.

[Gerber Files for ordering PCB](https://github.com/adafruit/Adafruit_Learning_System_Guides/raw/main/CircuitPython_KeyPad_Calculator/design-files/pcb/calculator2/gerb.zip)
[PCB Design Files for KiCad](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/CircuitPython_KeyPad_Calculator/design-files/pcb/calculator2)
## Required Parts

Along with the custom PCB, you'll need basic tools, soldering supplies, and the Adafruit parts listed below.

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
![Angled shot of black rectangular microcontroller "Feather RP2040"](https://cdn-shop.adafruit.com/640x480/4884-04.jpg)

### Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather](https://www.adafruit.com/product/4650)
A Feather board without ambition is a Feather board without FeatherWings! This is the&nbsp; **FeatherWing 128x64 OLED** : it adds a gorgeous 128x64 monochrome OLED plus 3 user buttons to&nbsp;_any_&nbsp;Feather main board. Using our&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4650)
[Related Guides to the Product](https://learn.adafruit.com/products/4650/guides)
![Video of a Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather - STEMMA QT / Qwiic connected to a temp and humidity sensor. Display reads "Adafruit" and various Temp and Humidity measures.  ](https://cdn-shop.adafruit.com/product-videos/640x480/4650-08.jpg)

### White Nylon Machine Screw and Stand-off Set – M2.5 Thread

[White Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3658)
Totaling 420 pieces, this **White Nylon&nbsp;M2.5 Screw Set** &nbsp;is a must-have smörgåsbord for your workstation.&nbsp;You'll have more than enough screws, nuts, and hex standoffs to construct&nbsp;your maker projects&nbsp;for days on end! M2.5 screws fit nearly...

In Stock
[Buy Now](https://www.adafruit.com/product/3658)
[Related Guides to the Product](https://learn.adafruit.com/products/3658/guides)
![White Nylon Screw and Stand-off Set with M2.5 Threads, kit box](https://cdn-shop.adafruit.com/640x480/3658-00.jpg)

### Pink and Purple Woven USB A to USB C Cable - 2 meters long

[Pink and Purple Woven USB A to USB C Cable - 2 meters long](https://www.adafruit.com/product/5044)
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; [If you want something just like it but for Micro B, we have a B...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5044)
[Related Guides to the Product](https://learn.adafruit.com/products/5044/guides)
![Angled shot of a pink/purple woven USB cable plugged into a laptop port and a small dev board.](https://cdn-shop.adafruit.com/640x480/5044-04.jpg)

### Header Kit for Feather - 12-pin and 16-pin Female Header Set

[Header Kit for Feather - 12-pin and 16-pin Female Header Set](https://www.adafruit.com/product/2886)
These two&nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[Feather](https://www.adafruit.com/categories/777)&nbsp;boards and you're in business!

What do they do? They get soldered on either side of the Feather...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2886)
[Related Guides to the Product](https://learn.adafruit.com/products/2886/guides)
![Angled shot of a Header Kit for Feather - 12-pin and 16-pin Female Header Set. ](https://cdn-shop.adafruit.com/640x480/2886-00.jpg)

### Stacking Headers for Feather - 12-pin and 16-pin female headers

[Stacking Headers for Feather - 12-pin and 16-pin female headers](https://www.adafruit.com/product/2830)
These two **Female Stacking Headers** alone are, well, lonely. But pair them with any of our [Feather](https://www.adafruit.com/categories/777) boards and you're in business!

What do they do? They stack. Put the headers through your Feather and then you can...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2830)
[Related Guides to the Product](https://learn.adafruit.com/products/2830/guides)
![Angled shot of a Stacking Headers for Feather - 12-pin and 16-pin female headers. ](https://cdn-shop.adafruit.com/640x480/2830-00.jpg)

### 1N4148 Signal Diode - 10 pack

[1N4148 Signal Diode - 10 pack](https://www.adafruit.com/product/1641)
You have some electrons over here, and you want them over there but you don't want the electrons from over there to be able to come over here? That's what a diode is for, these are directional current valves and have the benefit of being waaay smaller than vacuum tubes.  
<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/1641)
[Related Guides to the Product](https://learn.adafruit.com/products/1641/guides)
![Ten pack of diodes](https://cdn-shop.adafruit.com/640x480/1641-02.jpg)

Info: 

### Kailh Mechanical Key Switches - Linear Red - 10 pack

[Kailh Mechanical Key Switches - Linear Red - 10 pack](https://www.adafruit.com/product/4952)
For crafting your very own custom keyboard, these **Kailh Red Linear mechanical key switches** are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a **smooth linear** keystroke:

- Type Linear
- Operating...

In Stock
[Buy Now](https://www.adafruit.com/product/4952)
[Related Guides to the Product](https://learn.adafruit.com/products/4952/guides)
![Angled shot of ten red Kailh key switches.](https://cdn-shop.adafruit.com/640x480/4952-00.jpg)

### Relegendable Plastic Keycaps for MX Compatible Switches 10 pack

[Relegendable Plastic Keycaps for MX Compatible Switches 10 pack](https://www.adafruit.com/product/5039)
Get ready&nbsp;to customize your keeb with a 10&nbsp;pack of two-part plastic keycaps for your next mechanical keyboard or&nbsp;[NeoKey](https://www.adafruit.com/?q=neokey&sort=BestMatch)&nbsp;project.

Each keycap comes with a off-white base and a clear cover piece. You...

In Stock
[Buy Now](https://www.adafruit.com/product/5039)
[Related Guides to the Product](https://learn.adafruit.com/products/5039/guides)
![Angled shot of ten white plastic keycaps.](https://cdn-shop.adafruit.com/640x480/5039-08.jpg)

### Little Rubber Bumper Feet - Pack of 4

[Little Rubber Bumper Feet - Pack of 4](https://www.adafruit.com/product/550)
Keep your electronics from going barefoot, give them little rubber feet! These small sticky bumpers are our favorite accessory for any electronic kit or device. They are sticky, but not impossible to remove. They're small enough to fit onto any board, and have just enough height to give...

In Stock
[Buy Now](https://www.adafruit.com/product/550)
[Related Guides to the Product](https://learn.adafruit.com/products/550/guides)
![Angled Shot of the Little Rubber Bumper Feet - Pack of 4](https://cdn-shop.adafruit.com/640x480/550-06.jpg)

## Optional parts
### Part: Tapered Heat-Set Inserts for Plastic
quantity: 1
Brass, M2.5 x 0.45 mm Thread Size, 3.4 mm Installed Length (Pack of 100)
[Tapered Heat-Set Inserts for Plastic](https://www.mcmaster.com/94180A321/)

# Desk Calculator with CircuitPython

## 3D Printed Parts

While these parts are all optional, they'll greatly refine the look of your calculator and make it more pleasant to use.

Some of the models were developed with [FreeCAD](https://www.freecadweb.org/), others with [OpenSCAD](http://openscad.org/). Both packages are open source software packages that are free to download & use.

[3D Printed Parts - All Files, All Formats](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/CircuitPython_KeyPad_Calculator/design-files/3dprints)
## Base Enclosure
The base enclosure protects your desk or table from being scratched by the solder junctions on the PCB, and prevents you from delivering static shocks to the circuit when holding the calculator in hand. It also holds the keypad at an angle that makes it more comfortable to use. The main alternative to printing the base enclosure is to add adhesive rubber feet directly to the bottom side of the PCB.

![projects_Screenshot_2021-07-08_11-17-38.png](https://cdn-learn.adafruit.com/assets/assets/000/103/325/medium640/projects_Screenshot_2021-07-08_11-17-38.png?1625761094)

You can choose either the "snap-fit" version or the "screw-in" version. In the first case, the PCB is retained by two vee-shaped protrusions from the sides. In the second case, the PCB is retained by M2.5×6 screws using heat-set threaded inserts. (the snap-fit version also includes the holes for the heat-set inserts, but you don't need to use them)

In your slicer, use the "lay flat" operation to place the bottom of the enclosure directly on the print bed. Default slicing settings should suffice. If desired, clean up the shallow-angled top face by lightly sanding after 3D printing. Attach bumper feet to the bottom for anti-skid goodness.

The enclosure was designed in FreeCAD; you can load the **FCStd** file into FreeCAD to make changes to the model. Use the **stl** file for 3D printing.

## Keyswitch Plate
The keyswitch plate helps ensure that the keyswitches are soldered in without any rotation, and provides stability during use; you can get by without it, but it's easy to end up with some of your keys looking wonky. If you print it, remember that you must snap the keyswitches into it **before** soldering the keyswitches to the PCB.

The plate was designed in OpenSCAD; you can load the **scad** file into OpenSCAD to refine the model. Use the **stl** file for 3D printing.

![projects_Screenshot_2021-07-08_11-24-14.png](https://cdn-learn.adafruit.com/assets/assets/000/103/326/medium640/projects_Screenshot_2021-07-08_11-24-14.png?1625761482)

## Keycaps
You can print custom keycaps for your calculator. These are [based on KeyV2 by @rsheldiii](https://github.com/rsheldiii/KeyV2). The values are tuned for the author's Prusa I3 mk3s with an 0.4mm nozzle, PLA filament and 0.2mm "speed" printing profile. Each key takes about 20 minutes and uses about 2g of plastic, so it can be well worth the time to dial in the design for your printer.

![projects_Screenshot_2021-07-08_11-27-26.png](https://cdn-learn.adafruit.com/assets/assets/000/103/327/medium640/projects_Screenshot_2021-07-08_11-27-26.png?1625761685)

The geometry of the stems must be very precise, so begin by printing a single "central row" switch to check it for fit and function in your keyswitches. If the keyswitch from the provided STL does not fit, use the [OpenSCAD Customizer](https://en.m.wikibooks.org/wiki/OpenSCAD_User_Manual/Customizer) to increase **$stem\_slop** and/or **$stem\_inner\_slop** until you get a good fit (Start by changing things in 0.5mm increments). If they fall out too readily, decrease **$stem\_slop** and/or **$stem\_inner\_slop** similarly. **$stem\_slop** controls the outside of the stem, so increasing it makes the fit against the outside of the "box" of the keycap plunger looser and increasing it makes it tighter. **$stem\_inner\_slop** controls the inside of the stem, so increasing it leaves a greater gap for the " **+**" of the keycap plunger and decreasing it leaves a smaller gap.

![projects_Screenshot_2021-07-08_11-35-21.png](https://cdn-learn.adafruit.com/assets/assets/000/103/330/medium640/projects_Screenshot_2021-07-08_11-35-21.png?1625762144)

It can be visually difficult to tell whether the interference is at the inside or the outside; you can modify each number alternately until you get a fit or can tell which one is wrong.

Next, print a whole column of switches and confirm that they all fit; on the author's printer, one set of **slop** values was OK for all rows, but your experience may differ.

Expect to repeat this process a few times; here is the pile of switches the author discarded as unusable while perfecting the design & fine tuning the **slop** values.

![projects_PXL_20210703_162245504(1).jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/332/medium640/projects_PXL_20210703_162245504%281%29.jpg?1625762343)

The model should load with the tops of the keys on the build surface. For two-tone keys, configure your slicer to pause at 0.8mm Z-height for a color change. This really makes the legend stand out, and can be done on most 3D printers.

For fit testing, you can print the whole thing in one color, but be sure to choose the color that the stem will ultimately be printed in; the author found that two different spools of PLA required different fine-tuning numbers.

![projects_Screenshot_2021-07-08_11-29-59.png](https://cdn-learn.adafruit.com/assets/assets/000/103/328/medium640/projects_Screenshot_2021-07-08_11-29-59.png?1625761837)

## Screen Bezel
Use your slicer's "lay flat" function to place the top of the bezel directly on the printing surface. Default print settings suffice for this print.

The bezel was designed in FreeCAD; you can load the **FCStd** file into freecad to refine the model. Use the **stl** file for 3D printing.

![projects_Screenshot_2021-07-08_11-14-59.png](https://cdn-learn.adafruit.com/assets/assets/000/103/324/medium640/projects_Screenshot_2021-07-08_11-14-59.png?1625760974)

The little cutout allows the reset switch to be pressed, in the event you need to restart the calculator or access the UF2 bootloader for updates.

# Desk Calculator with CircuitPython

## Prepare the Feather & OLED FeatherWing

The stacking style described below is well-matched to the height of the 3D printed keycaps. If you plan to use different keycaps, particularly low-profile keycaps, you should do a test fit of everything to check the height of the keycap vs the height of the screen. If you want a shorter screen height, there are lots of options you can explore with various ways of stacking short headers.

## Solder male headers to the OLED

Insert male headers into the OLED from the bottom, then insert it into a solderless breadboard. Solder the male headers from the top side. Double check after soldering just one pad on each header that the headers are straight, not at an angle. Then, finish soldering the rest of the pads.

![projects_ksnip_20210707-171304.png](https://cdn-learn.adafruit.com/assets/assets/000/103/322/medium640/projects_ksnip_20210707-171304.png?1625760631)

## Solder stacking headers to the Feather

Insert the stacking headers into the Feather from the top, then insert the OLED into it. Solder the stacking headers from the bottom side. Double check after soldering just one pad on each header that the headers are straight, not at an angle. Then, finish soldering the rest of the pads.

![projects_ksnip_20210707-171256-crop.png](https://cdn-learn.adafruit.com/assets/assets/000/103/323/medium640/projects_ksnip_20210707-171256-crop.png?1625760659)

## Alternative Stacking for Shorter Keycaps
If you're using short keycaps like the relegendable ones, here's one alternative way to stack it up. The short female headers go into the calculator PCB; the male headers' long ends are inserted into the bottom of the Feather microcontroller board and soldered from the top; and (standard) female headers are inserted from the bottom side of that PCB.

To get even shorter, you can desolder the STEMMA QT connector from the OLED and use short female headers on the OLED, or move the position of the microcontroller **below** the main PCB, which would require adding an opening in the main enclosure to access the USB connector.

These modifications probably also require modifications to the display bezel 3D print.

![projects_ksnip_20210713-085910.png](https://cdn-learn.adafruit.com/assets/assets/000/103/367/medium640/projects_ksnip_20210713-085910.png?1626184809)

![projects_PXL_20210713_135401632(1).jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/370/medium640/projects_PXL_20210713_135401632%281%29.jpg?1626185059)

# Desk Calculator with CircuitPython

## Solder the PCB

## Finish board edges
Often, PCBs come with little bits of the FR4 material poking out of the sides. Simply sand these away with some coarse sand-paper.

(This Sanding block design is [by eponra on Thingiverse](https://www.thingiverse.com/thing:4664353))

![projects_ksnip_20210701-091112.png](https://cdn-learn.adafruit.com/assets/assets/000/103/333/medium640/projects_ksnip_20210701-091112.png?1625762508)

## Solder the diodes

&nbsp;

The board has 20 diodes, one for each keyswitch.

First, form the leads of the diodes using the 0.300" position on a lead former. You can use a standard PCB header as an improvised lead former if you don't have one.

(This resistor lead forming tool is by [dnewman on thingiverse](https://www.thingiverse.com/thing:26025); the 2nd position on the narrow-short-imperial stl is correct for this project)

![projects_ksnip_20210701-091131.png](https://cdn-learn.adafruit.com/assets/assets/000/103/337/medium640/projects_ksnip_20210701-091131.png?1625762852)

![projects_ksnip_20210707-171228.png](https://cdn-learn.adafruit.com/assets/assets/000/103/338/medium640/projects_ksnip_20210707-171228.png?1625762901)

Next, Carefully noting the orientation of the diode, insert them in the labeled positions: Match the black strip on the diode body with the strip on the soldermask and insert the dioes into the board. Bend the leads slightly so that the diodes will not fall out of the board.

Then, flip the board over and solder the diodes from the back. Finally, use flush cutters to trim away the excess leads.

![projects_ksnip_20210701-093012.png](https://cdn-learn.adafruit.com/assets/assets/000/103/335/medium640/projects_ksnip_20210701-093012.png?1625762769)

![projects_ksnip_20210701-092954.png](https://cdn-learn.adafruit.com/assets/assets/000/103/336/medium640/projects_ksnip_20210701-092954.png?1625762803)

## Solder the headers
Solder two rows of female headers into the two rows of pins at the top of the board. By inserting a Feather board with male headers into the female headers during soldering, you can ensure that the headers are properly aligned, not at a wonky angle. After soldering just one or two positions on each connector, check that they are properly aligned before soldering the rest.

![projects_ksnip_20210707-171310.png](https://cdn-learn.adafruit.com/assets/assets/000/103/339/medium640/projects_ksnip_20210707-171310.png?1625763019)

## Solder the keyswitches
Warning: 

If you are using the 3D printed plate—highly recommended—press the keyswitches into the plate from the back until they click. Carefully note the orientation of each keyswitch; if you will be using the screw-mount case, also note the position of the two screw access holes.

Then, once all the switches are in place in the plate, carefully fit them into the PCB, and solder.

![projects_ksnip_20210707-171221.png](https://cdn-learn.adafruit.com/assets/assets/000/103/340/medium640/projects_ksnip_20210707-171221.png?1625763272)

If you are **not** using the 3D printed plate, fit and solder just one or two switches at a time, starting in the corners. Without the plate, the keyswitch can rotate a surprising amount within the holes; center the leads carefully as rotated keyswitches mean rotated keycaps and the esthetic result is not as good. (The effect was deliberately exaggerated for this photo)

![projects_ksnip_20210713-092433.png](https://cdn-learn.adafruit.com/assets/assets/000/103/371/medium640/projects_ksnip_20210713-092433.png?1626186305)

# Desk Calculator with CircuitPython

## Assemble the Calculator

## Attach the Bezel to the OLED Display
In the M2.5 fastener set, find 4 each of the longest screw (M2.5×10) and the shortest standoff (M2.5×6 F-F)

Ensuring that the reset switch is positioned below the cutout tab, insert each screw from the front of the bezel, then through the OLED display. Using the stand-off like a nut, tighten the screen in place.

Adjust the rotation of the standoff nuts so that the OLED display can be pressed down onto the headers of the Feather.

![projects_PXL_20210712_204714660.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/353/medium640/projects_PXL_20210712_204714660.jpg?1626122893)

## If using heat-set inserts

Place the inserts loosely in the holes, with the narrow side down. With a soldering iron heated to 240°C (or the lowest setting available, if it's above 240°C), gently press the insert down into the plastic, keeping the iron in line with the post. **Note that this is not perpendicular to the base!** If you are using Adafruit's [heat-set insert rig](https://learn.adafruit.com/heat-set-rig) one easy way to get the angle right is to print a second enclosure and stack them back to back so that the posts are vertical. Have more questions about using heat-set inserts? [Check out our guide about them!](https://learn.adafruit.com/heat-set-rig/)

Place the PCB in the enclosure and secure using 4 M2.5×6 screws.

## If using the snap fit case

Place the PCB in the enclosure and gently press down until it moves past the snap fit ridges. You can release the PCB by gently flexing the sides of the enclosure away from each other.

## Placing the keycaps
Simply ease the caps onto the stems and check that they operate smoothly. For tricky keys like 9 and 6 you may find that you've swapped their positions or rotated them, which leads to the key profile being inconsistent.

![projects_PXL_20210708_160314216(1).jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/354/medium640/projects_PXL_20210708_160314216%281%29.jpg?1626123424)

## Stack the PCBs

Stack the RP2040 Feather and the OLED FeatherWing on top of the keypad PCB, and insert a USB cable for power and connection to your PC.

# Desk Calculator with CircuitPython

## Install 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_rp2040/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/102/705/medium800/adafruit_products_FeatherRP_buttons_highlighted.jpg?1623167565)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

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 **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

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

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/101/659/original/flash_nuke.uf2?1618945856)
# Desk Calculator with CircuitPython

## Upload the CircuitPython code

Info: 

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

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython.&nbsp;[You can learn about Mu and installation in this tutorial](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor "Mu tutorial").

## Download the Project Bundle

Your project will use a specific set of CircuitPython libraries and the&nbsp; **code.py** &nbsp;file. In order to get the libraries you need, click on the&nbsp; **Download Project Bundle** &nbsp;link below, and uncompress the .zip file.

Drag the contents of the uncompressed bundle directory onto your board's **CIRCUITPY** &nbsp;drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.

![Files](https://adafruit.github.io/Adafruit_Learning_System_Guides/CircuitPython_KeyPad_Calculator_code.png)

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

## Adapting to other Adafruit Feather boards

The code can be adapted to most Adafruit Feather boards that support CircuitPython, but the Feather RP2040 board names some pins differently than most boards, so you'll need to make modifications. Find the portion of the code that creates the KeyMatrix and change D24/D25 to A4/A5 for most other Feathers:

```auto
km=keypad.KeyMatrix(
    row_pins=(board.A2, board.A1, board.A3, board.A0, board.D0),
    column_pins=(board.A5, board.D11, board.D12, board.A4))
```

# Desk Calculator with CircuitPython

## Use your Calculator

## Basic functions

Enter a number by typing digits; use the "." key to insert a decimal point.

To perform an operation, press the operation key, enter another number, then press "=". The pending operation is shown on the bottom line. Because the "7-segment"-style font does not have a "/" or "÷" character, "d" is shown to indicate a division operation.

To perform a percentage operation, press the operation key, enter another number, then press "%".

- The operation **×** _ **number** _ **%** multiplies by a percentage, 20 \* 25% is 4.
- The operation **+** _ **number** _ **%** adds a percentage, 20 + 25% is 24.
- The operation **- _number_ %** subtracts a percentage, 20 - 25% is 16.
- The operation **÷ _number_ %** divides by a percentage, 20 / 25% is 80.

## Square Root

Press the **√** key to compute the square root of the last number entered or calculated. For example, to calculate the "golden ratio" you can type: **1 + 5 √ / 2** which is equivalent to (1+√5)/2.

## Clear and Backspace

The button marked **C** is a combination backspace/clear button. If a number has been entered, press backspace to erase it one digit at a time. If no number is entered (or the number has been erased) press it to clear the pending operation. If no number or operation is entered, press it to set the last number calculated to **0.0**.

## Pasting to a Host Computer

Hold&nbsp; **fn** and press **=** to paste the last number calculated to an attached computer.

## Make it your own

The author had so many ideas and not enough time to implement them.

- The **fn** key exists to access just one special feature. There should be more! Do you want to add parentheses? Trig functions? Exponents? Go wild!
- Investigate 2/3/4 line layouts & experiment with different fonts
- Add a mode where it operates as a pure numeric keypad or macro pad
- Install a battery under the PCB so you can go mobile
- Use the [**udecimal**](https://jepler-udecimal.readthedocs.io/en/latest/) library to upgrade to arbitrary-precision numbers


## Featured Products

### Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x64 OLED Add-on For Feather](https://www.adafruit.com/product/4650)
A Feather board without ambition is a Feather board without FeatherWings! This is the&nbsp; **FeatherWing 128x64 OLED** : it adds a gorgeous 128x64 monochrome OLED plus 3 user buttons to&nbsp;_any_&nbsp;Feather main board. Using our&nbsp;<a...></a...>

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

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

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

[White Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3658)
Totaling 420 pieces, this **White Nylon&nbsp;M2.5 Screw Set** &nbsp;is a must-have smörgåsbord for your workstation.&nbsp;You'll have more than enough screws, nuts, and hex standoffs to construct&nbsp;your maker projects&nbsp;for days on end! M2.5 screws fit nearly...

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

[Pink and Purple Woven USB A to USB C Cable - 2 meters long](https://www.adafruit.com/product/5044)
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; [If you want something just like it but for Micro B, we have a B...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5044)
[Related Guides to the Product](https://learn.adafruit.com/products/5044/guides)
### Kailh Mechanical Key Switches - Linear Red - 10 pack

[Kailh Mechanical Key Switches - Linear Red - 10 pack](https://www.adafruit.com/product/4952)
For crafting your very own custom keyboard, these **Kailh Red Linear mechanical key switches** are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a **smooth linear** keystroke:

- Type Linear
- Operating...

In Stock
[Buy Now](https://www.adafruit.com/product/4952)
[Related Guides to the Product](https://learn.adafruit.com/products/4952/guides)
### Kailh Mechanical Key Switches - Tactile Brown - 10 pack

[Kailh Mechanical Key Switches - Tactile Brown - 10 pack](https://www.adafruit.com/product/4954)
For crafting your very own custom keyboard, these **&nbsp;Kailh Brown Linear mechanical key switches** &nbsp;are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a **tactile keystroke** - it's not clicky like the...

In Stock
[Buy Now](https://www.adafruit.com/product/4954)
[Related Guides to the Product](https://learn.adafruit.com/products/4954/guides)
### Kailh Mechanical Key Switches - Clicky White - 10 pack

[Kailh Mechanical Key Switches - Clicky White - 10 pack](https://www.adafruit.com/product/4955)
For crafting your very own custom keyboard, these **&nbsp;Kailh&nbsp;White Linear mechanical key switches** &nbsp;are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a **clicky tactile** keystroke with a snappy feel and an...

In Stock
[Buy Now](https://www.adafruit.com/product/4955)
[Related Guides to the Product](https://learn.adafruit.com/products/4955/guides)
### Kailh Mechanical Key Switches - Linear Black - 10 pack

[Kailh Mechanical Key Switches - Linear Black - 10 pack](https://www.adafruit.com/product/4953)
For crafting your very own custom keyboard, these **&nbsp;Kailh Black&nbsp;Linear mechanical key switches** &nbsp;are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a&nbsp; **smooth linear&nbsp;** keystroke with a...

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

## Related Guides

- [Adafruit 128x64 OLED FeatherWing ](https://learn.adafruit.com/adafruit-128x64-oled-featherwing.md)
- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [Bubble Table with LED Animations and IR Remote Control](https://learn.adafruit.com/bubble-table-with-led-animations-and-ir-remote-control.md)
- [Edit CircuitPython Code on iOS with Runestone](https://learn.adafruit.com/editing-circuitpython-on-ios-with-runestone.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [NeoTrellis MIDI Feedback Controller](https://learn.adafruit.com/neotrellis-midi-feedback-controller.md)
- [CNC Rotary Macropad](https://learn.adafruit.com/cnc-rotary-macropad.md)
- [STEMMA Lego base plates](https://learn.adafruit.com/stemma-lego-base-plates.md)
- [LED Rocket Lamp](https://learn.adafruit.com/led-rocket-lamp.md)
- [Darth Faders](https://learn.adafruit.com/darth-faders.md)
- [Adafruit Floppy FeatherWing with 34-Pin IDC Connector](https://learn.adafruit.com/adafruit-floppy-featherwing-with-34-pin-idc-connector.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [Motorized POV LED Display](https://learn.adafruit.com/motorized-pov-led-display.md)
- [Customizing USB Devices in CircuitPython](https://learn.adafruit.com/customizing-usb-devices-in-circuitpython.md)
- [Neocontroller Color Grading Input Box](https://learn.adafruit.com/neocontroller-color-grading-input-box.md)
- [Driving TM1814 addressable LEDs](https://learn.adafruit.com/driving-tm1814-addressable-leds.md)
