## Arduino: Valuation calculator of infix mathematical expressions.

This project refers to an Arduino sketch that implements a calculator which valuates infix mathematical expressions using appropriate algorithms and data structures. The mathematical expressions are given through the USB port, while the valuation and presentation of results is done by Arduino. The results are displayed in an appropriate LCD display.

The software is well designed to allow retrieving data from a different input too (eg. elementary keyboard). However, in this application we did not have available pins left over to connect a keyboard as we made in previous projects. The mathematical expressions are given by the user in infix notation and with the help of the algorithm ‘Shunting-yard’ and the appropriate stack we perform its conversion to an equivalent postfix one. Also, the postfix expression is valuated with an efficient algorithm.

Currently the calculator supports operator precedence, associativity operators, parentheses, operators of multiple arguments (unary / binary operators) multi-digit integers, floating point result.

Expression Example: **32 + 111 / (4 – !43) * 33 / (2 + !3) + ((3 – 2) / (2 + 1))**

For more information, you can get the project itself:

`infix_calculator_lcd_keypad_shield_serial‘

Various images of the application.

Valuation calculator of infix mathematical expressions – 1.

Valuation calculator of infix mathematical expressions – 2.

Here is the code to use the calculator in Python via USB.

You need to have the package PySerial installed.

#!/usr/bin/env python try: import time, serial except ImportError, err: print ''.join (["Couldn't load module. ", err]) exit (1) PORT = '/dev/ttyUSB0' BAUD = 9600 TOUT = 3 if __name__ == "__main__": ser = serial.Serial (PORT, BAUD, timeout = TOUT) while True: line = raw_input ("Infix Expression: ") if line: ser.write (line) for line in ser.readlines (): print line, else: break

### Recent Posts

- The ‘Refugee’ project.
- Creating a Sharded Cluster of Replica Sets in MongoDB.
- Arduino: A simple and lightweight library for managing the Arduino GSM shield.
- Neo4j code infrastructure for .NET enterprise applications.
- Arduino: Security Alarm System.
- A dynamic string data structure helper implementation.
- A useful function for getting the host name and service of a socket.

### Categories

- Articles (77)
- Compilers & Interpreters (15)
- Data Structures & Algorithms (26)
- Desktop Applications (4)
- Electronic Games (6)
- Embedded Systems (54)
- Events (19)
- Hobbies (4)
- Internet Applications (17)
- Libraries & Frameworks (13)
- Machine Learning (16)
- News (4)
- Numerical Methods (7)
- Operating Systems (10)
- Projects (78)
- Security Systems & Access Control (10)
- Tools & Filters (8)
- Writings (1)

### Archives

### Statistics

- 210,419 clicks

### FSF News

- Fifteen new devices from Technoethical now RYF-certified to respect your freedom
- SecureDrop and Alexandre Oliva are 2016 Free Software Awards winners
- LibrePlanet free software conference returns to MIT this weekend, March 25-26
- FSF Job Opportunity: Outreach & Communications Coordinator
- GNU Toolchain now accepting donations with the support of the Free Software Foundation
- Three devices from Vikings GmbH now FSF-certified to respect your freedom