Table of Contents

Graphing Calculator

Introduction

What does it do?

Basic math operations
Simple cosine and sine graphs

Just write the amplitudine and the phase and you will see the corresponding graph, also allowing you to zoom in or out.

What's its purpose?

Well, if you're trying to do a digital detox and want to feel like an old school 20th century math researcher, you have the perfect choice! Not only that, but with the graph options you can visualize concepts like interference, phase shift, and amplitude without the need for an expensive oscilloscope. Or, if you are an engineer working with signals all day it can be useful for quick visual verification of parameters before sending data to a (Digital-to-Analog Converter).

What are its uses? Why is it better than the alternatives?

Phones are tempting, when you try do some quick math operations on them for some math exam you can get some Insta notifications or simply get a message and your focus can very easily be interrupted. It happened to me, it can happen to anyone. If you want to get rid of all digital devices when studying, you can use this calculator. The final purpose would be creating a full scientific calculator, yet that implies heavy optimization at the software level, due to the very limited RAM size of the microcontroller.

Implementation Description

The system is coordinated by the ATmega328P microcontroller. The user inputs data using a 4×4 Keypad. The input software module detects key presses and transmits them to the Main Logic. It validates the input and calls the Display Driver to update the graphical interface on the TFT Screen via the SPI bus. Simultaneously, the logic triggers the Audio Generator to emit a confirmation sound through the passive Buzzer using a PWM signal. The variable voltage read from the Potentiometer is used to adjust the zoom of the displayed graph. Operations history is written bidirectionally to the SD Card Module.

Hardware Design

This section outlines the physical implementation of the system, including the components used, their interconnection logic, and the communication protocols employed.

Bill of Materials (BOM)

The following table lists all the hardware components used in the project:

Component Description/Role
ATmega328P Xplained MiniMain MCU (Microcontroller Unit) based on the AVR architecture
1.8” Color TFT LCD (ST7735)High-resolution graphical output via SPI protocol
MicroSD Card ModuleExternal storage for logs/data, sharing the SPI bus
4×4 Matrix KeypadDigital input for user commands and data entry
Slide Potentiometer (10kΩ)Analog input for variable control
Passive BuzzerAudio output device for acoustic feedback and alerts

Pin Mapping and Connectivity

ComponentPin TypeMCU PinFunction
Keypad (Rows)DigitalD2, D3, D4, D5Input scanning (Pull-up)
Keypad (Cols)DigitalD6, D7, D8, D9Input scanning
BuzzerPWMD3 (shared)Audio signal generation
TFT Screen (SCK)SPI ClockD13Shared SPI clock
TFT Screen (MOSI)SPI DataD11Master Out Slave In
TFT Screen (CS/DC/RST)ControlD10, D9, D8Chip Select, Data/Cmd, Reset
SD Card (CS)ControlD4 (shared)Chip Select for SD Module
PotentiometerAnalogA010-bit ADC conversion

Electrical Schematic Description

The system design follows a modular approach. The SPI Bus (Serial Peripheral Interface) is the backbone of the hardware, allowing the MCU to communicate with both the TFT Screen and the SD Card. To avoid bus contention, separate Chip Select (CS) lines are used.

The 4×4 Keypad is connected using a matrix scanning technique, utilizing 8 digital pins to minimize I/O usage. The Passive Buzzer is connected in series to the MCU to prevent overcurrent damage to the digital pin. The Slide Potentiometer acts as a voltage divider, providing a linear voltage between 0V and 5V to the ADC (Analog-to-Digital Converter) on pin A0.

Signal Diagrams and Communication Protocols

SPI Protocol (TFT & SD Card)

The communication follows the SPI standard:

PWM (Pulse Width Modulation)

The audio output for the buzzer is generated using Timer-based PWM. By varying the frequency of the square wave, different musical notes are produced, while the duty cycle remains at 50% for optimal sound clarity.

Software Design

This section describes the firmware architecture, the development tools, and the logic implemented to coordinate the hardware peripherals.

Development Environment

The project is developed using Visual Studio Code integrated with the PlatformIO IDE extension. This environment was chosen for its advanced features, such as:

3rd-Party Libraries and Sources

To interface with the complex hardware modules, the following open-source libraries are utilized:

Algorithms and Data Structures

The firmware implementation relies on several key computational strategies:

Finite State Machine (FSM)

The application logic is structured as a Finite State Machine. This allows the system to transition between different modes (e.g., MENU_NAVIGATION, DATA_ENTRY, PROCESSING, ERROR_STATE) without blocking the execution flow, ensuring the UI remains responsive.

Non-Blocking Polling

Instead of using heavy interrupts for the keypad, a non-blocking polling algorithm is used within the main loop. This ensures that the system checks for user input while simultaneously updating the display or reading from the SD card.

SPI Bus Arbitration

Since the TFT screen and the SD card share the same SPI bus (MOSI, MISO, SCK), a manual Chip Select (CS) management algorithm is implemented. The firmware ensures that only one peripheral is active at any given time to prevent data corruption.

Circular Buffers (Optional/Planned)

For logging data to the SD card, a circular buffer structure is planned to store temporary sensor readings before performing a bulk write operation, minimizing the performance impact of SD card latency.

Implemented Functions and Sources

The code is modularized into several key functional blocks:

Obtained Results

I managed to build a fully functional embedded system that successfully integrated all specified modules. In more detail, I managed to do the following things:

Overall, the project met its initial design specifications, operating smoothly via a standard 5V USB power supply and demonstrating excellent real-time reliability.

Conclusions

Personally, it was one of the most satisfying projects I've made during uni. I learnt a lot about embedded development and I'm truly planning to create a future project(in my limited spare time).

Several key technical takeaways and challenges were identified during the project:

Download

TO BE CONTINUED Github Repo

Calendar of Progress

DateSoftwareHardware
2nd MaySoftware state: Basic arithmetic operations were successfully implemented, along with history management. Graphics for sin and cos functions are currently displayed wrong and a better user-interface can also be developedAll jumper wires are connected successfully, meaning all peripherals can be used accordingly. Possibility in the far future: Perfboard soldering

Bibliography / Resources

Hardware Resources

ATmega328P Datasheet

ATmega328P Xplained Mini User Guide

Sitronix, ST7735 1.8" Color TFT Controller DatasheetATmega328P Datasheet

SD Association, Physical Layer Simplified Specification (SPI Mode Interface)

Software Resources

PlatformIO, PlatformIO Core & IDE Documentation

Adafruit Industries, Adafruit GFX Graphics Core Library

Adafruit Industries, Adafruit ST7735 Library

Mark Stanley, Alexander Brevig, Keypad Library for Arduino

Arduino, SPI Library Reference

Arduino, SD Library Reference (FAT16/FAT32