Our project is a simple but fully functional calculator built using an STM32F4 microcontroller, a 4x4 matrix keypad, and a 16x2 I2C LCD display.
The calculator allows the user to enter numeric values and mathematical operators directly through the physical keypad. Each keypress is detected by the microcontroller, which then builds the expression step by step. After entering the complete expression, the STM32 processes and evaluates it using our programmed calculation logic.
Once the result is computed, it is displayed clearly on the I2C LCD screen, allowing the user to view both the input expression and the final answer. At the same time, the result is also sent to the UART terminal for monitoring and debugging purposes, making it easier to verify the system’s accuracy.
The calculator supports:
- Addition (+)
- Subtraction (–)
- Multiplication (×)
- Division (÷)
- Clear function
- Wire the keypad: rows to PD7–PD10, columns to PE11–PE14 (as defined in
keypad.h). - Wire the I²C LCD: SDA/PB9, SCL/PB8, power and ground (confirm 3.3 V/5 V compatibility).
- (Optional) Setup UART: PA2 (TX), PA3 (RX) to board’s serial adapter or USB-to-UART.
- Include
main.c,keypad.c/h,i2c_lcd.c/h. - Adjust I²C address in
i2c_lcd.hif your LCD backpack uses a different address (common alternatives: 0x27 or 0x3F). - Confirm HAL initialization and clock configuration as per your board.
- Build and flash the firmware.
- On startup, LCD shows “INPUT!” then a guide: “A = + B = - E = * C = / D = = F = Clr”.
- Use keypad to enter digits and operators.
- Press
Dto compute result — displayed on LCD and sent over UART. - Press
Fto clear and start a new expression.
- Supports
+,-,*,/. - Handles division by zero: displays
Err!. - Limits input to defined max expression length (e.g. 16 chars).
10- 5=→ result 5
10 * 6 =→ result 60
55 + 10 =→ result 65
- 9 / 0 = →
Err!
Our STM32-based calculator successfully performs different arithmetic operations using the physical 4×4 keypad, with each result immediately displayed on the I2C LCD. For subtraction, entering 10 – 5 correctly shows the result 5. Multiplying 10 × 6 gives the expected output of 60 , while adding 55 + 10 produces 65 . The system also properly handles error conditions—when attempting 9 ÷ 0, the calculator detects the invalid operation and displays an error message instead of crashing. These examples demonstrate that the device can manage basic computations reliably while also responding appropriately to special cases.
https://drive.google.com/file/d/1MnQXwcoD1rWdlUXneGOctZT2vfwn0tTh/view?usp=drive_link





Comments