PiCalc: Raspberry Pi Pico Based Pocket Calculator

by Makertronics in Circuits > Gadgets

16433 Views, 32 Favorites, 0 Comments

PiCalc: Raspberry Pi Pico Based Pocket Calculator

Ibles Thumbnail.png
PiCalc: Raspberry Pi Pico Based Pocked Calculator | Instructables

It's quite rare these days to find someone carrying a pocket calculator but school students who are don't allowed to carry phones may use it, or why don't they create their own pocket calculator.

In this Instructable, I will show you how I made a pocket calculator using raspberry pi pico and that's where it gets its name PiCalc.

Supplies

supplies.png

Raspberry Pi Pico

SSD1306 OLED display module 128^64

20 X SMD Momentary Switches (6x3.5mm) for Keypad

Slide Switch for Power On/Off

Lipo Battery smaller than 30mmx30mmx4mm

TP4056 Lipo Charge/Protection Circuit

Some 3D Printed Parts

Copper Clad + Glossy Paper + Ferric Chloride if you are going to make PCB by yourself

Principle Behind Keypad Matrix (Optional)

bitmap.png

Before making the calculator, we need to understand the input mechanism of the calculator.
It is based on a keypad matrix when the input is multiplexed.
In simple terms, a grid of buttons/keys is arranged such that the terminals are connected row-wise and column-wise, as can be seen in the image.
All the buttons' right terminals are connected to their respective rows and all the left ones to their respective columns giving out eight connections, namely R1, R2, R3, R4, and C1, C2 C3, C4.

Now when a user pressed the button, we need to find out which column and row that press corresponds to.
And to do that, the microcontroller reads each row one by one and while turning on/off each column's supply one by one for each row. i.e., first, all the input lines are turned high by input pullup. The microcontroller reads that input line let suppose row is the input so, we will start reading from R1 then we output a logic low on C1 then C2, C3, and then C4. If R1 turns low for any of that, it will confirm the pressing of that button.

Circuit & PCB Design

switch3649.png
schematic.png

The Circuit will consist of 20 buttons arranged in a 4X5 keypad matrix, an SSD1306 OLED display, and a raspberry pi pico on the backside.

I am going to design a single-layer PCB and that's why the column wires for the keypad will be connected externally by soldering bridge wires also the connection of the keypad matrix on the top layer to the raspberry pi pico on the bottom layer will be done by connecting vias from pico to array of vias on the left side of the PCB.

Also, the Gerber File for the Double Layer PCB can be found on this link.

You can use that file to get PCB manufactured from Seeed Studio Fusion PCB. They take care of the entire fabrication process from PCB manufacturing, parts sourcing, assembly, and testing services, so you can be sure that they are getting a quality product. After gauging market interest and verifying a working prototype, Seeed Propagate Service can help you bring the product to market with professional guidance and a strong network of connections.

PCB Manufacturing

IMG_1276.JPG
IMG_1263.JPG
IMG_1273.JPG
pcb.gif

For making PCB we are going to use Toner Transfer Method.

We will take a Copper Clad of dimensions 30 mm by 78 mm and clean it using some high grit sandpaper to remove the oxidation layer.

Then print the PCB Design(as given below) on glossy paper and align it to the copper. Use some hot press or iron to heat for 5 minutes to transfer the tonner on a glossy paper to copper clad which will later be used as a template to etch away the copper from where the tonner isn't there.

Soaking the PCB + glossy paper in warm water will help in easily removing the glossy paper.

If any trace gets damaged during the removal process, use a permanent marker to redraw the trace.

Etching the PCB

IMG_1278.JPG
IMG_1280.JPG

Now drop the PCB in Ferric Chloride solution and aggregate the solution for around 5 minutes to etch away the unwanted copper.

Use some Acetone to remove the tonner from the etched PCB and a shinny layer of copper will emerge out of it.

Drill the holes (0.8mm diameter) for OLED displays and vias for connecting keypad matrix to raspberry pi pico.

Soldering the Parts

IMG_1324.JPG
IMG_1294.JPG
IMG_1295.JPG
IMG_1321.JPG

Now it's time to solder the parts.
If you have manufactured your own PCB like me then you first have to solder the bridge wires to make the connections for the column of the keypad matrix.

Out of 4 rows, you need to do that only for 3 rows as the last row is already traced out with copper.

After that, we can go forward with soldering the buttons.

Connection to Raspberry Pi Pico

IMG_1331.JPG
IMG_1333.JPG

After soldering all the buttons on the top layer we can stick the RPi Pico on the bottom layer using some double-sided tape and then solder the wires from RPi pico to the array of vias on the right of the pico as in the image according to the schematic.

Only after these connections, we can attach the OLED display as it will cover the holes for soldering these wires.

Connecting Battery and Charging Circuit

IMG_1354.JPG
IMG_1359.JPG

After the OLED display its time to connected the battery and LiPo protection and charge circuit TP4056 along with an on/off switch.

properly insulate all the connection using heat shrink as all will be going to enclosed in an enclosure later.

Installing Thonny IDE

Capture.JPG

I have programmed the Raspberry Pi Pico using Micropython SDK, which can be easily done through Thonny IDE. It is the same IDE which some of you might remember from traditional Raspberry Pi Linux Computers.
You can get one from Windows as well as Mac from https://thonny.org/.

After downloading and installing the IDE, connect the pico to the computer while holding the Boot select button on pico which will power up it in programming mode.

A Folder will pop up on the screen, you can install the micropython firmware using the file from this link by dragging and dropping it into the folder that popped up.

Or you can also do it through Thonny IDE, By going into Run->Select Interpreter, there you will find micropython for RasberryPi Pico and at the bottom, on the window, you will see a blue text button "Install or Update Firmware".

Programming Raspberry Pi Pico

Screenshot (144).png
Screenshot (145).png
Screenshot (146).png

Before programming the Pico we need to install the library for OLED display, to do so go to the Tools Menu -> Manage Packages.
there you can search for SSD1306 and install the first one. It will be saved directly onto your PICO.

And then you can use the code given below to flash the PiCalc Firmware.

Now you have a barebone working calculator, to make it move friendly to sue we will enclose it in a 3D Printed Cover.

Downloads

3D Printing Enclosure

IMG_1349.JPG
IMG_1352.JPG

using the Eagle CAD's Fusion 360 Sync feature I transferred the 3D file of the PCB to Fusion 360 and then create an enclosure around it.

There are mainly 3 parts needed to be printed, a keypad matrix, top and bottom cover.

The 3D Print is done with 2 wall perimeter and 20% infill, there is no need for support.
There are some places where bridging will happen so keep it in mind and adjust your 3D printer accordingly.

I have also included the Step file for while construction if you wish to tweak some parameters.

Preparing Keypad

IMG_1369.JPG
IMG_1363.JPG
IMG_1365.JPG

For a better understanding of which button to be pressed, all the buttons need to be labeled.
To do so, I have printed the numbers and symbols and cut them out.

I have attached the pdf file which you can print and stick as well.

Using some paper glue I stuck them onto the 3D printed Part.
As all the prints are done in PLA, paper Glue holds good onto it.

Downloads

Assembly

animation.gif
IMG_1373.JPG

This animation is for a reference purpose to show how assembly will proceed.

Enclosing Into Single Unit

IMG_1402.JPG
IMG_1403.JPG
IMG_1372.JPG
IMG_1404.JPG

There are indents for switch and TP4056 (charge/protection circuit) and slots for USB input for charging the on/of the slide switch.
Stick then using a glue gun and stick the battery using double-sided tape as using hot glue on a lipo battery isn't recommended.

For the top part first, insert the keypad into the grid and the PCB on top of it.

The enclosure is designed for a snap fit.

Features of PiCalc

calc gif.gif
IMG_1387.JPG
IMG_1388.JPG

The PiCalc is quite versatile and can be used with long equations with decimal numbers and brackets to define execution priority. By default, the priority of execution is similar to that of the BODMAS rule.

The right side button consists of dual usage with a shift key on the bottom left corner.
For example, to use the open bracket '(' first, click the 'S' button on the bottom left corner, then click the second from the last column's top.
The left symbol on the last column can be used directly without any shift key and to use the right, one shift key is to be clicked before.

Similarly 'C' is for clearing a single element at a time, and 'CE' is to clear all history.

If an equation is written that can't be processed, 'error' will be shown on the screen and to proceed further you need to click the clear button.

Enjoy Your Own Pocket Calculator!

IMG_1385.JPG
IMG_1380.JPG

Woohoo! you created your own pocked calculator.

If you face any difficulties or you want to provide any suggestions, do comment below.