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.

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