Graphing Calculator

Introduction

What does it do?

Basic math operations
  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
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:

  • SCLK (Serial Clock): Generated by the ATmega328P to synchronize data transmission
  • MOSI (Master Out Slave In): Used by the MCU to send pixel data to the screen and commands to the SD card
  • MISO (Master In Slave Out): Used specifically by the SD Card to send data back to the MCU

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:

  • IntelliSense: For rapid code completion and error highlighting.
  • Unified Debugging: Allowing for seamless firmware uploads and serial monitoring.
  • Library Manager: To handle dependencies and version control for 3rd-party drivers.
  • platformio.ini Configuration: Ensuring consistent build environments across different machines.

3rd-Party Libraries and Sources

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

  • Adafruit GFX Library: A core graphics library providing a common set of graphics primitives (points, lines, circles, etc.).
  • Adafruit ST7735 Library: A hardware-specific library for the 1.8” TFT display, handling the SPI communication and initialization sequences.
  • Keypad Library: Used to manage the 4×4 matrix keypad scanning, including debouncing and multi-key handling.
  • SD Library: The standard Arduino/C++ library for the FAT16 file system operations on the MicroSD card.
  • SPI Library: A fundamental library for high-speed serial communication with the display and the SD card.

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:

  • void setup(): Initializes Serial communication, SPI bus, TFT display, SD card, and sets pin modes for the buzzer and keypad.
  • void loop(): The main execution cycle that triggers the input manager and updates the state machine.
  • char readKeypad(): Wraps the Keypad library to return the currently pressed character and trigger acoustic feedback via the buzzer.
  • void updateUI(String message, uint16_t color): A high-level function that clears specific screen regions and renders new text or graphics.
  • bool logToSD(String data): Opens the target file on the SD card, appends a timestamped entry, and ensures the file is safely closed.
  • void playTone(int frequency, int duration): Uses the tone() function to drive the passive buzzer for user alerts.

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:

  • Hardware Integration: The ATmega328P microcontroller reliably interfaces with all peripherals. The SPI bus arbitration was successfully implemented, allowing the ST7735 TFT display and the MicroSD card module to share the same data lines without interference, managed via separate Chip Select (CS) pins.
  • User Interface (UI) & Responsiveness: The 1.8” Color TFT screen provides clear visual feedback, rendering text and basic graphics efficiently. The 4×4 matrix keypad offers responsive and accurate input. Software debouncing and non-blocking polling ensure that no duplicate key presses are registered and the system does not freeze while waiting for user interaction.
  • Audio Feedback: The passive buzzer successfully generates distinct acoustic signals (using hardware timer PWM) corresponding to different system events, such as key validations, error alerts, or task completions, significantly enhancing the interactive experience.
  • Data Logging and Storage: The FAT16/FAT32 file system was properly initialized. The system can seamlessly create files, append log data, and read parameters from the MicroSD card, proving the viability of the non-volatile storage implementation.
  • Analog Processing: The slide potentiometer provides stable 10-bit analog-to-digital (ADC) readings. The voltage divider circuit works as expected, and the software successfully maps these readings to dynamic system variables (e.g., scrolling, value adjustment).
  • System Stability: The Finite State Machine (FSM) software architecture prevents blocking conditions. The system runs continuously without memory leaks or crashes, demonstrating efficient RAM management (operating safely within the 2KB limit of the ATmega328P) by utilizing the F() macro and PROGMEM for static strings.

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:

  • Memory Management: Working with only 2KB of SRAM required strict optimization. Avoiding dynamic memory allocation, minimizing buffer sizes, and utilizing Flash memory for static strings (via the F() macro) were critical techniques to prevent stack collisions and ensure system stability.
  • Protocol Arbitration: Managing the shared SPI bus between the ST7735 TFT display and the MicroSD card module reinforced the understanding of hardware-level communication. Correctly toggling the Chip Select (CS) lines was essential to avoid data corruption.
  • Software Architecture: Implementing a Finite State Machine (FSM) alongside non-blocking polling proved to be a highly effective strategy for maintaining a responsive User Interface while handling background tasks.
  • Future Improvements: Soldering all the hardware on a more robust Perfboard would be an obvious next step. Managing to add more complex operations or even to simulate different function graphics could make the product much closer to a real scientific calculator (that would mean changing the keyboard to one with more buttons or even adding one more). One of the best functionalities i can think of would be an integral solver or a differential equation solver. However, we face big issues when trying to implement these locally on the microcontroller. Thus, we may need to change the heavy duty responsibility to another computer, either connected by Bluetooth or by Wi-fi. If we are connected to another device through bluetooth or Wi-fi, why not add the option to talk to an LLM? That could be a student's daydream for a math exam where calculators are allowed.

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

Software Resources

pm/prj2026/bianca.popa1106/radu.stoican.txt · Last modified: 2026/05/12 19:17 by radu.stoican
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0