Skip to content

PyComputus is the sequel to LibreComputus (nCalc). It is was more optimized and faster made to work on Raspberry Pi's.

License

Notifications You must be signed in to change notification settings

joelwizard404/PyComputus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PyComputus - Scientific Calculator for Raspberry Pi

A professional-grade scientific calculator designed for Raspberry Pi with support for physical displays (LCD/OLED), hardware button matrices, and comprehensive mathematical operations.

πŸš€ Features

Mathematical Operations

  • Basic Arithmetic: Addition, subtraction, multiplication, division, power, modulo
  • Scientific Functions: Trigonometric (sin, cos, tan, asin, acos, atan), logarithmic (log, ln), exponential, square root, factorial
  • Hyperbolic Functions: sinh, cosh, tanh
  • Constants: Ο€ (pi), e, Ο† (phi - golden ratio)
  • Expression Evaluation: Complex mathematical expressions with proper operator precedence
  • Angle Modes: Degrees and Radians

User Interface

  • Multiple Display Types: Terminal, LCD 16x2, OLED 128x64
  • Hardware Buttons: Physical button matrix support
  • Themes: Default, Dark, High Contrast
  • Sound Effects: Button clicks and error beeps (optional)

Advanced Features

  • Memory Functions: Store, recall, add, clear
  • Calculation History: Track and review past calculations
  • Persistent Storage: Save history and memory between sessions
  • Input Validation: Prevents invalid expressions
  • Expression Parser: Handles complex nested expressions
  • Configurable: YAML configuration file for easy customization

πŸ“ Project Structure

pycomputus/
β”‚
β”œβ”€β”€ πŸ“„ main.py                    # Application entry point
β”œβ”€β”€ πŸ“„ config.yaml                # Configuration file  
β”œβ”€β”€ πŸ“„ requirements.txt           # Python dependencies
β”œβ”€β”€ πŸ“„ README.md                  # Complete documentation
β”œβ”€β”€ πŸ“„ LICENSE.md                 # MIT License
β”‚
β”œβ”€β”€ πŸ“ src/                       # Core application logic
β”œβ”€β”€ display.py                    # Handles main calculator functions
β”œβ”€β”€ display.py                    # Handles display
└── keyboard.py                   # Handles keyboard
β”‚
β”œβ”€β”€ πŸ“ math_engine/               # Mathematical operations
β”‚
β”œβ”€β”€ πŸ“ ui/                        # User interface
β”‚
β”œβ”€β”€ πŸ“ hardware/                  # Hardware interface
β”‚
β”œβ”€β”€ πŸ“ utils/                     # Utilities
β”‚
β”œβ”€β”€ πŸ“ tests/                     # Unit tests
β”‚
β”œβ”€β”€ πŸ“ docs/                      # Documentation
β”‚
└── πŸ“ assets/                    # Resources

πŸ”§ Installation

Prerequisites

# Update system
sudo apt-get update
sudo apt-get upgrade

# Install Python 3 and pip
sudo apt-get install python3 python3-pip git

# Enable I2C (for LCD/OLED displays)
sudo raspi-config
# Navigate to: Interface Options -> I2C -> Enable

Quick Install

# Clone repository
git clone https://github.com/yourusername/pycomputus.git
cd pycomputus

# Install dependencies
pip3 install -r requirements.txt

# Run the calculator
python3 main.py

Optional Hardware Support

# For LCD/OLED displays
pip3 install adafruit-circuitpython-charlcd adafruit-circuitpython-ssd1306

# For sound effects
pip3 install pygame

# For button matrix
pip3 install RPi.GPIO

πŸ’» Usage

Terminal Mode (by Default)

python3 main.py

Basic Calculations

> 2 + 3
Result: 5.0

> 15 * 4
Result: 60.0

> 2^8
Result: 256.0

> sqrt(144)
Result: 12.0

Scientific Functions

> sin(45)
Result: 0.7071067811865476

> log(100)
Result: 2.0

> exp(1)
Result: 2.718281828459045

> factorial(5)
Result: 120.0

Complex Expressions

> 2 * pi * 5
Result: 31.41592653589793

> sin(30) + cos(60)
Result: 1.0

> (2 + 3) * 4
Result: 20.0

Memory Operations

> 42 + 8
Result: 50.0

> ms              # Store to memory
Stored 50.0 to memory

> 5 * 3
Result: 15.0

> mr              # Recall from memory
Result: 50.0

> m+              # Add to memory
Added 15.0 to memory
Memory: 65.0

> mc              # Clear memory
Memory cleared

Angle Mode

> mode
[Angle Mode: DEG]

> deg             # Toggle to radians
[Angle Mode: RAD]

> rad             # Toggle to degrees
[Angle Mode: DEG]

History Commands

> history         # Show calculation history
> clearhistory    # Clear history

Other Commands

> help            # Show help menu
> clear           # Clear display
> quit            # Exit calculator

βš™οΈ Configuration

Edit config.yaml to customize PyComputus:

# Display type
display:
  type: "terminal"  # terminal, lcd16x2, oled128x64

# Input mode
input:
  mode: "keyboard"  # keyboard, buttons, both

# Calculator settings
calculator:
  angle_mode: "DEG"
  decimal_places: 10
  max_history: 50
  save_history: true

# Enable sound effects
sound:
  enabled: false
  volume: 0.5

# Theme
theme:
  name: "default"  # default, dark, high_contrast

πŸ”Œ Hardware Setup

LCD 16x2 Display (I2C)

Wiring:

LCD Pin β†’ Raspberry Pi Pin
VCC    β†’ 5V (Pin 2)
GND    β†’ GND (Pin 6)
SDA    β†’ GPIO 2 (Pin 3)
SCL    β†’ GPIO 3 (Pin 5)

Configuration:

display:
  type: "lcd16x2"
  lcd:
    i2c_address: 0x27

OLED 128x64 Display (I2C)

Wiring:

OLED Pin β†’ Raspberry Pi Pin
VCC      β†’ 3.3V (Pin 1)
GND      β†’ GND (Pin 6)
SDA      β†’ GPIO 2 (Pin 3)
SCL      β†’ GPIO 3 (Pin 5)

Configuration:

display:
  type: "oled128x64"
  oled:
    i2c_address: 0x3C

Button Matrix (5x5 Example)

Wiring:

Rows: GPIO 17, 27, 22, 23, 24
Cols: GPIO 5, 6, 13, 19, 26

Configuration:

input:
  mode: "buttons"
  button_matrix:
    enabled: true
    layout: "standard"
    row_pins: [17, 27, 22, 23, 24]
    col_pins: [5, 6, 13, 19, 26]

See docs/hardware_setup.md for detailed hardware instructions.

πŸ§ͺ Testing

# Run all tests
pytest tests/

# Run with coverage
pytest --cov=src tests/

# Run specific test file
pytest tests/test_math_engine.py

πŸ“š API Documentation

CalculatorCore Class

from src.calculator_core import CalculatorCore

calc = CalculatorCore()

# Perform calculation
result = calc.calculate("2 + 3 * 4")

# Scientific function
result = calc.calculate_function("sin", 45)

# Memory operations
calc.memory_store(42)
value = calc.memory_recall()
calc.memory_add(10)
calc.memory_clear()

# Mode control
calc.toggle_angle_mode()
calc.set_angle_mode("RAD")

# History
history = calc.get_history()
calc.clear_history()

# State
state = calc.get_state()

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Install development dependencies
pip3 install -r requirements.txt

# Install pre-commit hooks
pip3 install pre-commit
pre-commit install

# Run linting
pylint src/

# Format code
black src/

# Type checking
mypy src/

πŸ™ Acknowledgments

  • Built for the Raspberry Pi community
  • Thanks to all contributors

πŸ—ΊοΈ Roadmap

  • Graphing capabilities
  • Unit conversions
  • Statistical functions
  • Complex number support
  • Programmable functions
  • Web interface
  • Mobile app companion
  • 3D printed enclosure designs

πŸ“Š Changelog

Version 1.0.0 (Current)

  • Initial release
  • Basic and scientific operations
  • Multiple display support
  • Button matrix support
  • Configuration system
  • History and memory

πŸ“ License

This project is licensed under the Mozilla Public License Version 2.0 - see the LICENSE.md file for more details.

About

PyComputus is the sequel to LibreComputus (nCalc). It is was more optimized and faster made to work on Raspberry Pi's.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages