Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I'm a newbie in electronics. I'm trying to build a calculator from scratch as a simple project and side hobby to keep me busy.

My goal is to build a simple calculator, not a scientific or graphing calculator, although I don't mind receiving information about how to do that either, just for kicks.

Is there a good tutorial for this? How should I start?

share|improve this question
1  
There is a kit to build a basic 4-function calculator here: spikenzielabs.com/Catalog/… –  jwygralak67 May 22 '13 at 13:47
add comment

12 Answers

Here is an example of a calculator that you can build without too much electronics knowledge. It's full featured, although addition is not included.

Yes I'm joking, don't take this too seriously

share|improve this answer
    
lol. What is that? I think I've seen it before, though I'm not sure. Very curious to see if I can get my hand on one of those. Do you have a name or a link to one of those? –  KerxPhilo Mar 10 '11 at 5:52
3  
en.wikipedia.org/wiki/Slide_rule –  AndreKR Mar 10 '11 at 6:03
    
this inspired my question: electronics.stackexchange.com/questions/11263 –  markrages Mar 10 '11 at 6:28
    
@KerxPhilo - Hahahahahahahahahahah...... oh how times change. –  Connor Wolf Mar 10 '11 at 6:30
    
@markrages, kudos to your question, very interesting :) –  KerxPhilo Mar 10 '11 at 9:32
show 1 more comment

That is not a trivial project. There are many educational sub projects to worry about. One is buttons and debouncing. Another is writing characters to a display. There is the decision of how you want to implement this are you interested in making it from a big box of nand gates or want to take a microcontroller or other processor and write software? Are you interested in using an fpga and doing all of the math in RTL? You need to break the problem down into those components and work/learn one component at a time and then join them together. For example if the core math engine is actually software on a microcontroller, one task would include writing some C functions on your desktop computer that you can feed keystrokes and output characters that will ultimately go to the display. A non-trivial task if you have never programmed before. If you are choosing to go with an fpga or possibly even discrete logic, you might want to use verilator or icarus verilog or ghdl to work on the core math and interface modules.

As an educational project what I would do is get a few msp430 launchapads, under 5 bucks each or The STM32 value line discovery (the stm32/arm based one not the other one) for around 12 bucks each. A number of folks will steer you toward the arduino, and that is a fine platform as well, it has its pros and cons, i wouldnt go with it as my first microcontroller. Buy a simple two line lcd panel, earth lcd used to be a good place, perhaps just go to sparkfun. Take one microcontroller board hook it up to the lcd panel and learn how to put characters on the display. I would then learn how to use the uart on the microcontroller which often starts with blasting bytes out, then later receiving and echoing. Use the uart receiver to receive things to put on the display then using a dumb terminal (putty, hyperterm, minicom) from a computer feed stuff in and make sure it works. Next take another microcontroller, use your uart in and out experience and work on the core math engine, from your computer feed it 0 - 9, +, -, = at first then add multiply and divide and then floating point if you are brave enough for that (or have a library that fits). Output from the math module would echo input numbers and print results when = is sent in, etc. Then figure out what to do with buttons, find an array of buttons, feed those into the third microcontroller somehow, debounce, and have that turn into uart out of 0 - 9, + , - , = to the math microcontroller. THEN, reduce all of this into a single microcontroller without the uart stuff in the middle.

Another alternative is to get one of the rs-232 fpga boards from knjn.com or the lattice brevia (is that big enough?) or a number of others, then work on each of the functional blocks using an RTL language. parts of it will be much easier than the equivalent software solution, some parts will be a bit harder than a software solution.

If you can provide more information as to what you are thinking, a box of nand gates or microcontroller based solution or were you thinking about something else?

share|improve this answer
add comment

The simplest electronic calculator your could build would be a four-function binary calculator. You could build it using switches to input binary numbers, and 7400 family basic logic elements could handle the adders that would handle the addition. You could use either individual LEDs to represent each binary number in the output, or you could use several seven-segment displays to display the number in hexadecimal. Building a binary calculator would allow you to avoid building a decimal-to-binary converter, and would help you familiarize yourself with how digital electronics work. If you plan to get into digital electronics as a hobby, you might want to consider getting Logisim, a free program that allows you to simulate your circuits before you build them.

share|improve this answer
2  
Wow. In the age of System-on-Chip, you want him to wire up twenty gates per digit just to add? Even the first handheld calculator didn't do that. Single chip calculators have been around for thirty years. –  Ron Mar 10 '11 at 13:40
    
Well, you could use a 74181 for a 4-bit slice. That would be easier, if nothing else. –  W5VO Mar 10 '11 at 17:23
1  
Yes, this could be done with one or two chips (using a microprocessor like this example), if he wants to create the calculator in software. Perhaps building the whole calculator using discrete components would take too much time, but if he wants to get into hardware, a binary calculator might be a good starting point. –  inventorM Mar 10 '11 at 22:28
    
This is actually a good idea, to get a proper understanding of binary bit math. I did a half-adder project with my 12-year old daughter, while we ran out of room on a breadboard - she went on to "build" it virtually in Minecraft. She "got" the concept of gates and adding bits, which was the whole point. –  Ron J. Jun 28 '13 at 13:14
    
For what it's worth, calculators (usually) don't work internally in binary and convert, they work directly in BCD. A four bit slice is enough of an ALU (in fact that was the original job of the Intel 4004). –  Spehro Pefhany Mar 15 at 18:06
add comment

Here is how I did it.

Choose components:

Input Device( 4x4 Keypad in my case. 10 keys for numerals, 4 for operators, one for '=', and one for 'reset/refresh')

Processor(8-bit AVR )

Output device(16x2 LCD)

Power supply(LM7805 regulator with 9volt battery)

BreadBoard( make PCB after it starts to works)

I chose to program in assembly(to learn), matter of personal choice. I used AVR Studio 4 as IDE and a home-baked lpt based 'ISP' programmer for flashing hex into AVR.

then I wrote drivers for LCD and keypad. When able to take input and produce output, started parsing in decimal numerals and operators, then i parsed expressions and read about Infix, Postfix and Prefix methods. I did my work in assembly so there was no 'FLOAT datatype support' and I ended up implementing my custom data-type (BCD based datatype for maintaining 15 digit decimal precision it was a huge waste on RAM though!).

All this done and Voila.. my calculator was ready(I named it BUB!).

Mine ran @ 1MHz and was able to beat casio_991MS(in terms of decimal precision and multiplication and division).

I hope this helps others.

share|improve this answer
add comment

You could use a development kit with everything already on the board to enable you to focus on the software. For example http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en024858&part=DM240001 this kit has PIC, LCD and few buttons. There are plenty of headers to add additional buttons. The one drawback is the LCD is bigger then you might want to use initially but it will certainly get you started.

If you search around you might be able to find smaller (and cheaper ones) that you can start of on.

Using a kit like this will make it easier to start of writing your code as they will be some examples, and removes the issue of hardware problems as it is all set up correctly. Another drawback is this kit uses the high end pics which is overkill for a calculator project, but it does give you room to grow and modifiy it in future to do other tasks. It will also give you schematics to use as starting point for making your own boards in the future.

share|improve this answer
add comment

On my shelf I have "Electronic Calculators" by H. Edward Roberts, edited by Forrest M. Mims III. 1974.

It's pretty educational about how people used to build calculators in 1974. Many photos are of the complete life cycle of a mass-produced MITS calculator -- photos of the prototyping (a big spaghetti mess of wires), the PCB design (laying Rubylith on a drafting table), individual parts, assembly line, wave solder machine, and troubleshooting.

Ah, many things have changed since then. Today's books usually avoid showing big spaghetti mess of wires. Today's calculators avoid applying mains voltage directly to the calculator PCB.

Many things are still the same. People still usually make a big spaghetti mess of wires while prototyping.

share|improve this answer
add comment

Well for starters, you should think about the major components that your going to need. You will probably need a microcontroller, a keypad, and an LCD screen. Once you pick out those components, it should be as simple as developing the firmware.

share|improve this answer
    
Any more details you could provide, remember I'm a total newbie when it comes to building electronics, and I want to take this challenge as my first. With the information you provided above, it's a great start, however I don't know what microcontroller I would need. Also, how to develop a firmware? Do you write the firmware in C and the upload it to the firmware, or do you have to write it in ASM? –  KerxPhilo Mar 9 '11 at 22:30
    
also could you provide a good website that sells electronics equipment at a very inexpensive rate for hobbyists? Appreciate your support! –  KerxPhilo Mar 9 '11 at 22:31
    
The two main hobbyist microcontrollers are the PIC, and the AVR. There are C compilers for both of these devices. A simple microcontroller will work for your project, as long as it has enough Input/Output pins to interface with your keypad and LCD. A good website for hobbyist electronics would be SparkFun –  Ryan Mar 9 '11 at 22:39
1  
@KerxPhilo: Yes, the majority of embedded system people write the firmware in C. Ladyada has good tutorials on how to write firmware in C and upload it to a microcontroller as well as tutorials on connecting a LCD and displaying stuff on it. –  davidcary Mar 10 '11 at 17:48
add comment

I believe this can be a good first learning project, but it is non-trivial, and you will have to learn quite a bit along the way, as well be patient as the project includes quite a number of sub-projects to tackle along the way.

The first design hurdle you need to decide is what technology level do you wish to do this at? With or without a microcontroller (a largely self-sufficient microprocessor), discrete logic (e.g. AND, OR, NOR gates and flip-flops) with/without arithmetic units (ALU), programmable logic (CPLD, FPGA), something else I haven't mentioned or considered. This should be first about the technology used to do the calculations, the input/output controls are secondary decisions (LED seven-segment displays, LCD panel) mostly influenced by aesthetics or cost.

One potentially useful starting places for learning about digital computation is the very accessible book, How Computers Do Math (ISBN: 0471732788) by the quirky Clive Maxfield. This is written at the "soft" - programming or logical level, which you will need to understand in order to actually do the calculations.

Someone else mentioned the uWatch (-- micro-Watch) project as an example, and there are references around the Internet to electrical engineers (or EE students) that built their own calculator in the 1970s. There are also some details on building a FPGA (programmable logic device) based calculator.

For a total novice to electronics (or digital electronics) I would suggest using a micrcontroller as a starting point in your design, look over the mentioned book's web site for a feel of the complexity in programming (not much if you have any programming experience) for the microcontroller and go from there.

share|improve this answer
add comment

VisualTFT designer has simple touch screen calculator as one of it's examples. That software generates code for Mikroelektronika Pascal, Basic and C compilers for AVR, PIC, ARM and 8051 microcontrollers.

share|improve this answer
add comment

Hardware Requirements

  • A keypad for user input
  • An LCD for displaying input and its result
    In a real calculator product, you need a custom LCD for displaying special characters like the =, - and M (for MC, MR and MS operations) signs. A custom LCD design costs up to 3000$, but then the customly designed LCDs become more economy then the other general purpose ones. Since your project is just for hobby, I suggest you use a general purpose LCD, with a KS0108 controller.
  • A very cheap and non-featured microcontroller
    You need a very basic controller since you will be doing very simple tasks. You can use a cheap PIC microcontroller.

Design Steps

  • Drive your LCD
    Manage driving your LCD. Write some digits on it. Write a software interface for it.
  • Test you keypad
    Do the same steps you did with the LCD. Make sure that you have software control on your key pad.
  • Write the algorithms that do the arithmetic operations
    If you use a microcontroller which can multiply and divide, you don't need to do that operations yourself; but you have to pay more for the microcontroller, on the other hand, you learn less and gain less experience during your project.

If you want to add more advanced arithmetic features, (like square rooting, sine/cosine calculating, etc) you need to implement relevant calculation algorithms using Newton's Method or Taylor Series Expansion.

Otherwise, it is to be a simple project. Your main challenge will be with driving your LCD and keypad, if you don't have much experience with before.

share|improve this answer
    
Depending upon one's level of ambition, one could use a few shift registers and a little discrete logic, along with a "ROM" (probably EPROM or parallel flash), to build a very crude microcontroller. A simple calculator might be possible using 20 chips or less, esp. if one uses a fairly big ROM. A typical instruction would be "output X on shift register 1, Y on shift register 2, set the output strobe to Z, and then fetch the next instruction from the address formed by concatenating the values of some registers onto the constant A". –  supercat Feb 7 '13 at 22:27
    
One wouldn't need to have any circuitry to perform BCD addition--that could all be handled within the code. If one has two separately-controllable shift registers, advance them as needed so the source and destination operands are lined up, and then use four instructions to put the CPU into one of 20 states based upon the values of four bits taken from each value; the next four instructions can take the next four bits from each shift register while overwriting one of them with the first four bits of the computed result. –  supercat Feb 7 '13 at 22:35
    
I'd dispute the "custom LCD" requirement. Calculator LCD's give every appearance of being commodity items with only a few variations - pad pitch, simple vs. scientific (which usually implies 8 vs 10 digit). Within a given selection of the above, there will be dozens if not hundreds of items which are functionally equivalent, even if they differ slightly in dimensions or font style. –  Chris Stratton May 8 '13 at 16:08
    
@ChrisStratton: If one wants an 8-digit display with no annunciators, off-the-shelf parts are available that would meet that description. I don't think I've seen any off-the-shelf displays which would be functionally equivalent to those in a typical calculator. Note that calculators are apt to use zebra-strip connections, which are cheaper than pins to manufacture, but harder to work with in a DIY project. –  supercat Jul 11 '13 at 15:19
    
@supercat - the LCDs used in cheap calculators tend to use a ribbon with heat activated adhesive, not a zebra strip. And they are largely standard off-the-shelf items which can be interchanged between manufacturing runs. –  Chris Stratton Jul 11 '13 at 15:51
show 2 more comments

The easiest way to implement a calculator would probably be to use a microcontroller. If you decide to go that route, the first step would be to find some code to actually do the calculation. You need a program that accepts the operands and operators and spits out the result. This relatively simple calculator module written in c should give you an idea of what is necessary. It can add, subtract, multiply and divide as well as some bitwise operations and, if you use Reverse Polish Notation like in scientific calculators, it can solve sub-expressions in parenthesis. So you would read what buttons were pressed, collect each "token" in a buffer converting any digits into actual numeric values and then when you get the "=" button, you feed the list of tokens to this eval code which reduces and solves the expression resulting in a single value.

share|improve this answer
add comment

Make good or excellent calculator you need the good quality of display and good quality of the microcontroller for make the calculator best performance. If want to code to make a calculator in the windows in c# language so you visit on the www.HHHProgram.com In this site you got code of the calculator in C#, java and c language.

share|improve this answer
    
Apart from the fact your code wouldn't be likely to work on any embedded platform I can think of it's poorly structured as well. I'd almost forgotten C has a goto statement. –  PeterJ Jul 11 '13 at 12:34
add comment

protected by Community Jul 24 '13 at 13:31

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.