Page 1 of 1

Graphing Calculator

Posted: Sat Dec 12, 2015 12:46 am
by Mr_Cookie
Okay, I am really new to all of this but I do have some background in coding in C#, C++ and a bit of Java. Anyways I have no idea how to complete my goal and I may or may not need help on every step of the way. Basically I'm just trying to create my own DIY graphing calculator, and yes I already have seen Ben Heck's DIY graphing calculator video thingy. But to be honest I'm trying to aim for a touchscreen for this calculator, so basically I can buy any component I need to and for the case I can just 3D print at school. Anyways thanks for the future help guys, I'll be looking forward to it!

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 8:10 am
by pauli
You are in for a world of hurt. Quality calculator firmware is difficult and time consuming.

- Pauli

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 10:25 am
by Mr_Cookie
Is there no pre packaged software?

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 10:58 am
by karrika
What about using Mathematica? It can do graphs. It also has a simple syntax for basic calculations. You could create your own keyboard or add an USB numeric keypad. Perhaps there is some way to add multiple functions to keys by pressing some modifiers. Using a touch screen takes away screen area. You cannot see the math and plots if the screen is cluttered with GUI buttons. Your choice.

Sounds like a cool project to me.

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 11:00 am
by Mr_Cookie
Hmm, problem is I don't know where to start. I was hoping that the community could help me start.

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 11:05 am
by karrika
I doubt that this has been done before. There will not be clear tutorials for creating a graphing calulator from a Pi. This is the problem of being creative.

But mathematica is included in the raspbian image. And there are tutorials of how to use it at Perhaps you could start by learning to use Mathematica.

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 11:52 am
by pauli
I have written calculator firmware, although not on the Pi. It took seven to eight years to get to the current level working evenings and weekends, although it was workable after three to four years. About a third of the effort was the mathematics, another third was the user interface and the final third the hardware support. On the Pi, you'll get the hardware support for less effort and Mathematica could provide the bulk of the mathematics if you can interface to it.

The user interface will still be a fair amount of work. Probably the most important thing is to make everything the user sees and does completely consistent. After that try to arrange all the functions logically and in a well grouped manner.

To further confound things, calculators usually operate with decimal arithmetic, not binary. This means you can't just use the existing floating point libraries. Why? Because numbers like 0.1 cannot be represented exactly in binary but can in decimal and people expect basic arithmetic to be exact -- I've lost track of the number of times I've seen questions about (1/3)*3 not being exactly 1 -- it shouldn't be on any calculator decimal or binary. Anyway, an example 0.1 + 0.1 on my Intel laptop gives 0.200000000000000011102230246251565404236316680908203125 in binary. It is only a small error but it is not what is expected and will cause problems.

- Pauli

Re: Graphing Calculator

Posted: Wed Dec 30, 2015 12:47 pm
by rurwin
With projects of this sort, it is best to do what you can and hang the difficult bits. If you wanted to sell it then it would be different but I don't get the impression that is what you want to do.

pauli has described the individual parts well: GUI, Maths, hardware. They will all cause you problems of one sort or another but, so long as you are not looking for perfection, there should be nothing you cannot handle.

Try to put each of those parts into separate source-code files with well-defined and minimal interfaces between them. Then you can improve one without having to trawl through all your code looking for bits you need to change.

For example, you might have one bit of code that puts a button on the screen and detects when it is pressed. That might call a function with an ID code of the button. Some other bit of code is responsible for putting the buttons on the screen that make the calculator user interface. When the function is called with the ID of the multiply button, that might then call a function called "multiply_pressed". That function is in another part of the code which doesn't care about the GUI but only with how the buttons do their work. It might then call a function called "multiply_xy" that implements the maths on the calculator's registers.

So you can start out using floating point numbers. Then when you want to use a more accurate method, you only need to rewrite "multiply_xy" and everything else stays the same. Similarly if you want to change the button layout, only the code that does that needs changing.

Re: Graphing Calculator

Posted: Thu Feb 23, 2017 10:50 pm
by nastybuttler322
Use the Structure Theorem. Get quality math books from arithmetic, through to calculus 3 (and beyond if they use additional tools that haven't been covered to that point). You can see what books are being used for the more-advanced-than-calculus 3 by viewing MIT PhD mathematic programs and looking at their courses.

I know programming languages have some very basic math capabilities built in, so those are the only ones you don't need to program, but they can be used to build more complex operations. Those new operations can be used to build even more complex operations, and so on.

You pretty much may need two programs for the calculator. You need a program to that actually calculates, and you need another program to take the results and plots the graphs.

The calculation program would take the longest I think. Go through the math books and underline the nouns of the instructions of a task in one color, and the verbs in another color. Nouns are inputs and outputs, verbs are processes. Figure out which is which and put them in a chart or table. To get from the inputs to the outputs, use the processes.

Now that you know what needs to be done for a task, write the code in a chosen language to be able to produce the output. How would the computer do it? As you progress, you can use structures of the stuff you built to integrate into new processes. It could take a while.

Test inputs on the program and program a keyboard. You may even have to design some characters that will display. But it can all be done. Then make the graphing program send the inputs to the calculating program, make the calculating program output to the graphing program, and make the graphing program take those inputs and plot the graghs that will be displayed for the user.

Re: Graphing Calculator

Posted: Fri Feb 24, 2017 1:48 am
by Gavinmc42
How much time do you want to spend doing this?

I did a calculator program back in the 1980's.
Standard coding methods on cpu's are not accurate enough.
Floating point errors multiply especially when doing recursion like calculating the tides for best time to plan a fishing holiday.
Don't think because you have a 32bit cpu, 32 or 64bit floating point is accurate.

I wrote it using BCD, Binary Code Decimals on a 6805.
Did the maths the same way they teach at school, carry the 1 etc.
Calculators only need to be 4bit cpu's because you only use the numbers 0-9.
It is more tricky when you get to sin/cos stuff but lookups tables help.
But you probably won't need that as the Pi ARM cpu is much faster than a 4MHz 6805.

Plotting is different as you don't need so much accuracy.

It would make an interesting project for Ultibo, there is a graphing unit in this example. ... c3000/RPi2
Ultibo can have multiple console windows, one can be used for GUI buttons, one for plotting and another for the digit display.
Done some of my own plotting stuff and it turned out to be easier than I thought ... tting#p792

The 7" Pi display works fine and touch works. ... t=plotting

It looks like DPI displays might have a chance of working too.
No one has tested this with Ultibo yet ... ah-ttl-tft
DPI uses most/nearly all the GPIO.

Smaller SPI display also work.

Using Ultibo also gets you 2 second boots.

The GUI stuff is early days, but drawing blocks is easy and pik33 has even used DMA which makes it fast.
Fonts are easy with a font tool in the github.

If you want to make a portable battery powered calc then an eInk display with a Zero?
Anyone make ~5" touch mono eInk display?

You could start with Processing 3.0 on PC and port to Pi, but Processing uses Java and only runs at a decent speed on a Pi 3
Oh, and Processing can port to Android.

You can use Python and pygame and
Netbeans on PC then port to Pi, also Java but uses JavaFX for display speed and you don't need a X window.

Many, many more ways to do it.
Ascii plot in terminal screen?