Skip to main content
Version: FILS English

Rust Calculator

A calculator that take numbers and opperations as inputs and outputs results to a i2c screen

info

Author: Scrob Sebastian-Mina
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-Seby-S/tree/main

Description​

This project implements a calculator using a Raspberry Pi Pico 2w microcontroller running rust code. It supports:

  • Basic arithmetic: addition, subtraction, multiplication, division
  • More advanced functions: exponentiation, square roots, and trigonometric operations
  • Graphical interface: an OLED display that shows your input and results
  • Audible feedback: buzzer beeps confirm key presses

Input comes from 2 seperate keypads:

-a 4x3 matrix keypad used to enter numbers(0-9 keys), a '=' button and a button that retanins the previously calculated answer for ease of us;

-a 4x4 matrix keypad used to enter the signs and operations possible. The keys are for: +,-,*,/,^,radical,sin,cos,tan,cotan,log(base10),!. There is also a backspace button that if held pressed for 1 second it clears the screen, parentheses buttons and a button for decimal points(.);

Output is displayed via the I2C Oled sceen.

Motivation​

I wanted to make something practical for my project and I use calculators all the time in my life. Since I have a calculator it is easy to test and compare how my project should behave. I also like simple user input/output devices.

Architecture​

Schematic diagram

Components​

  • Raspberry Pi Pico 2w: connected to everything and runs code
  • Keypad(4x4): connect with 8 GPIO pins
  • Keypad(4x3): also connect with 7 GPIO pins
  • OLED display: connect with GPIO pins and uses I2C (4 pins)
  • Buzzer: connect with GPIO pins (2 pins)

Log​

Week 5 - 11 May​

Parts have arived and got the bords to work.

Week 12 - 18 May​

Schematics and wiring done. Now coding for the dispaly and keypad is in progress.

Week 19 - 25 May​

Finishing the coding part.

Hardware​

  • Raspberry Pi Pico 2W (RP2350): Main microcontroller handling system logic and display
  • OLED Display 0.96'' I2C: display for UI and results
  • Keypad(4x3): user input for numbers,clear key and '=' key;
  • Keypad(4x4): user input for operations,backspace,decimal poin, and paranthesis
  • 3V active buzzers: audio feedback for key presses
  • Breadboard & wires for prototyping

Schematics​

Schematic diagram2

Bill of Materials​

DeviceUsagePrice
Raspberry Pi Pico 2WThe microcontroller39 RON
Raspberry Pi Pico 2WThe debug probe39 RON
Display OLED 0.96'' I2C alboutput16 RON
Tastatura matriceala 4x4input7 RON
Tastatura numerica 4x3input18 RON
2x Buzzer Activ de 3 Vaudio feedback2 RON
Breadboard HQ (830)platform10 RON
Set Fire Tata-Tatawires8 RON
Fire Colorate Mamă-Tatăwires10 RON
Total: 149 RON

Software​

LibraryDescriptionUsage
embassy-rpPeripheral access & async drivers for the RP2040Used for GPIO, I2C, timers, and initializing peripherals
embedded-graphics2D graphics primitivesUsed for text and symbols for the OLED screen
embassy-executorAsync task executor for EmbassyRuns the async tasks
ssd1306OLED display driver crateProvides I2C interface for the OLED display
libmMath library for no-std environmentsProvides math functions (sin, cos, tan, log, ^, etc.)
heaplessFixed-capacity, no-std collectionsUsed for storing the input expression string without heap allocation
defmtLightweight logging framework for embeddedDebug/info/error logging
panic-probePanic handler with defmt integrationReports panic messages
  1. Embedded-Graphics Documentation
  2. RP2040 Datasheet
  3. Rust Embedded Book
  4. Keypad Matrix Tutorial (Theory + Wiring)
  5. SSD1306 OLED Datasheet
  6. libm Crate Documentation