Post Reply 
RPN-duino
11-18-2015, 05:14 PM (This post was last modified: 12-08-2015 06:22 PM by Chasfield.)
Post: #21
RE: RPN-duino
Attached is the Arduino Nano beta source code for the two line calculator at the top of this thread. It wouldn't upload with the .ino filename extension, hence .txt.

It has not been heavily tested but seems to function ok. Much tidying up to do yet.

The core of the calculator program is composed of four keyboard polling loops:

loop():
standard Arduino declaration - reads the keyboard and decides what to do next.

shifted_function():
called by loop() when the 2nd function key is pressed. Executes SIN, COS, SQR etc. following the next key press.

numeric_key():
Called by loop() when a numeric key or the decimal point key is pressed. Loops around accepting key presses until an X register value has been input.

ee_key():
Called by shifted_function() when exponent input is required. Loops around until an exponent value and sign have been input.


Key presses that implicitly terminate ee_key() and numeric_key() (eg. roll down or X<>Y) are buffered and passed back to loop() for processing as if they had come straight off the keyboard.

My first attempt at this program polled the keyboard in only one place and relied upon mode flags for differentiating between numeric input and 2nd function key processing. I abandoned this strategy after I had worked out how to display numbers in standard form. This called for another mode flag for processing exponent input. A flag too far!

As regards schematics: I haven't produced anything yet but you can work out the Arduino and LCD module pin connections from the LCD and Keyboard data declarations.

<<beta code attachment removed - update posted further down the thread with connections schematic>>
Find all posts by this user
Quote this message in a reply
11-18-2015, 07:25 PM (This post was last modified: 11-22-2015 10:31 AM by Chasfield.)
Post: #22
RE: RPN-duino
I just tweaked a couple of minor glitches in the original attached source code. There was no stack lift included in the processing of the PI or memory RCL keys. There is now. Just found a typo in my in-line comment - all fixed. If I find any more, I will repost the code with version numbering embedded in the file name.
Find all posts by this user
Quote this message in a reply
11-22-2015, 10:21 AM (This post was last modified: 11-22-2015 10:54 AM by Chasfield.)
Post: #23
RE: RPN-duino
Attached is a schematic for the two line RPN-duino calculator.

1602 LCD module
The version I used has a built-in 100 ohm current limiting resistor for the back-light. I added in a further 220 ohms to throttle it back a bit for the sake of battery life. I read that some similar modules don't have a built-in resistor and, in that case, the back-light LED will fry itself in short order if you don't fit one. The 1602 takes up six of the Arduino's digital I/O pins - two for control and four for data bits. The R/W pin on the module is grounded to configure its control registers for write only operation.

Arduino
The five keyboard row lines use pins A0-A4. These are analogue ports by default but are configured and referenced using their digital I/O aliases (D14-D18) by the Keypad library. Column lines use regular digital I/O ports.

I have attached the most up-to-date version of the source code, appropriately named, in case I find anymore glitches. I'll stop monkeying with that beta code file now.


Attached File(s) Thumbnail(s)
   

.txt  calculator_0-1.txt (Size: 15.87 KB / Downloads: 30)
Find all posts by this user
Quote this message in a reply
02-13-2016, 12:28 PM (This post was last modified: 02-13-2016 12:41 PM by Chasfield.)
Post: #24
RE: RPN-duino
I have just completed a third RPN-duino calculator design. This is implemented using a full sized Arduino Uno board with a SainSmart 1602 keypad/LCD shield installed on top. Another Rockwell 4-function calculator was plundered for its excellent modular keyboard (I keep getting these weird e-mails from the RUG, whoever they are, saying they know where I live). The case was hand-built around the Arduino stack and keyboard, from hardwood strip, sandwiched between a base and bezel of 2mm plastic sheet.

There are a couple of advantages to this approach. The unit is more compact, despite the full size Uno board being used, instead of the Nano of previous designs. Wiring the thing up was trivial by comparison, requiring only 9 keyboard lines, a battery clip and switch.

The main drawback is increased current consumption. The Uno/SainSmart combo needs around 65 mA, so ten hours of battery life is expected. My previous Arduino Nano based calculators only pulled half that.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
08-24-2016, 01:23 PM (This post was last modified: 10-02-2016 01:56 PM by Chasfield.)
Post: #25
RE: RPN-duino
I have been working with a 1.3 inch 128x64 OLED display - just right for displaying a 4 line RPN stack. This size is one up on the ubiquitous 0.96 inch units that are available and costs about twice as much (15 GBP). They have great readability and, being self-luminous, rather than back-lit, exhibit near perfect contrast. The I2C ones, with a 4 line connection, only use two data pins on the Arduino, which simplifies soldering.

My most recent Arduino calculator project uses one of these displays and a high quality slim project case (see attached pictures). The keyboard was scratch-built using a matrix of 12 mm tactile PCB switches, much epoxy resin and some tinned copper strip for the row bus lines. The column bus was formed by bending and daisy chaining the PCB switch legs. The calculator runs happily on 3 AAAs and the OLED unit is powered off the Arduino's 3.3 volt pin. It doesn't seem phased by 4.5 volt logic signals. If it dies young I will retract this observation.

The calculator code is the same as my earlier projects but tweaked to push out all four stack lines using U8glib library calls.

See if you can work out which household artefact I cut my display bezel sections from!


Attached File(s) Thumbnail(s)
       
Find all posts by this user
Quote this message in a reply
09-17-2016, 02:49 PM (This post was last modified: 09-17-2016 03:03 PM by Chasfield.)
Post: #26
RE: RPN-duino
I stumbled upon an old thread (which I can't now find) in which a forum member had reworked a Texas TI 1025/1050 four banger into a capable RPN programmable. These cheap units were produced in huge quantities and are great for hardware hackers. There is loads of space inside at the thick end, with moulded-in clips for a circuit board. The spacious metal face plate was just made to be re-legended and the keyboard module header lines are robust and accessible with a soldering iron.

Anyway, attached is a picture of my project based on a TI 1025, which now runs an Arduino Nano and 1.3 inch OLED display. This allows a full 4 line output. The original Texas unit featured software on/off switching so I wired a real power switch into the lower casing.

With 24 keys to play with, I was able to add a few extra stack orientated features:

S^2: square all stack registers
1/S: take reciprocal of all stack registers
SS: Sum stack
TVM: loan payment calculator where r=Z, N=Y, PV=X

The build went smoothly and the only problem is that the display is a bit dim for a sunny day thanks to the very heavy filter factor of the grey acrylic cover.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
09-17-2016, 03:33 PM
Post: #27
RE: RPN-duino
Outstanding job, congratulations!

Saludos Saluti Cordialement Cumprimentos MfG BR + + + + +
Luigi Vampa +
Free42 '<3' I + +
Find all posts by this user
Quote this message in a reply
09-17-2016, 06:57 PM
Post: #28
RE: RPN-duino
I agree. Magnificent! Shame that it doesn't quite have enough keys to be a WP-34s, but it looks so good.

Nigel (UK)
Find all posts by this user
Quote this message in a reply
09-18-2016, 01:52 PM (This post was last modified: 09-18-2016 02:49 PM by Chasfield.)
Post: #29
RE: RPN-duino
To step up the calculator's functionality while remaining inside the Arduino eco-system is problematic. The BigNumber library offers much more precision than the 6-7 digits of the standard 32 bit Math library currently in use but I don't think it can co-exist with the u8glib display library for want of space on the Arduino Nano. A lean display driver, or an equally lean 40 bit maths library would sort the problem.

I have solved the dim display problem. Apparently, the default display contrast is 50% percent of the max that can be set by writing a byte to the display contrast register on the SH1106 display chip. The code to support this is in u8glib v1.19.1 but this version seems problematic on my Xubuntu Arduino IDE. However, I was able to append the code to the appropriate source file in v1.18.1 so the contrast level can now be adjusted.
Find all posts by this user
Quote this message in a reply
09-18-2016, 06:50 PM
Post: #30
RE: RPN-duino
(10-29-2015 08:26 AM)ggauny@live.fr Wrote:  Super reply with this picture ! Yes sometimes we have to reinvent the wheal !

It's one of these simple pleasures in life...
Find all posts by this user
Quote this message in a reply
09-19-2016, 08:48 AM
Post: #31
RE: RPN-duino
(09-18-2016 01:52 PM)Chasfield Wrote:  To step up the calculator's functionality while remaining inside the Arduino eco-system is problematic. The BigNumber library offers much more precision than the 6-7 digits of the standard 32 bit Math library currently in use but I don't think it can co-exist with the u8glib display library for want of space on the Arduino Nano. A lean display driver, or an equally lean 40 bit maths library would sort the problem.

I have solved the dim display problem. Apparently, the default display contrast is 50% percent of the max that can be set by writing a byte to the display contrast register on the SH1106 display chip. The code to support this is in u8glib v1.19.1 but this version seems problematic on my Xubuntu Arduino IDE. However, I was able to append the code to the appropriate source file in v1.18.1 so the contrast level can now be adjusted.

How much space is there in the calculator case? Could you fit an Arduino Zero (68mm x 30mm) in?

Nigel (UK)
Find all posts by this user
Quote this message in a reply
09-19-2016, 09:44 AM
Post: #32
RE: RPN-duino
(09-19-2016 08:48 AM)Nigel (UK) Wrote:  How much space is there in the calculator case? Could you fit an Arduino Zero (68mm x 30mm) in?

There is also a nano-sized version of the Arduino Zero called "Neutrino" (http://rabidprototypes.com/product/neutrino/). I haven't tried that out yet because my current Arduino software on the Macintosh does not support the Zero.

An alternative would be a second nano board (you can buy 30 of them for the price of an original Zero...). One for the calculations, the other for I/O. Or leave it as it is: Simple and efficient!
Find all posts by this user
Quote this message in a reply
09-19-2016, 02:35 PM (This post was last modified: 09-19-2016 02:38 PM by Chasfield.)
Post: #33
RE: RPN-duino
The original TI1025 board is 60mm x38mm with a component depth of 10mm.

The problem with hotter micro-controllers is likely to be higher power consumption. The Nano/OLED combo pulls 32 mA, so 20 plus hours of operation from a PP3 alkaline is possible.

The Neutrino looks promising though.

At the moment I am playing around with directly programming the SH1106 controller on the OLED display using the Arduino Wire library. If I can remove the need for u8glib then I will have loads of space on the Nano for my Bignumber math based sketch.
Find all posts by this user
Quote this message in a reply
09-19-2016, 04:05 PM
Post: #34
RE: RPN-duino
(09-19-2016 02:35 PM)Chasfield Wrote:  At the moment I am playing around with directly programming the SH1106 controller on the OLED display using the Arduino Wire library. If I can remove the need for u8glib then I will have loads of space on the Nano for my Bignumber math based sketch.
... that would be a major step. I have an Arduino waiting for a cool project like this :) and some free time of his owner :!

Saludos Saluti Cordialement Cumprimentos MfG BR + + + + +
Luigi Vampa +
Free42 '<3' I + +
Find all posts by this user
Quote this message in a reply
09-19-2016, 07:08 PM
Post: #35
RE: RPN-duino
And what about a Teensyduino ?
Find all posts by this user
Quote this message in a reply
09-28-2016, 03:24 PM (This post was last modified: 09-28-2016 03:33 PM by Chasfield.)
Post: #36
RE: RPN-duino
I might buy one to play with. Could be the way forward.

After much head scratching, I have evolved a display driver routine that allows SH1106 and SSD1306 OLED displays to live side by side with the BigNumber library on an Arduino Nano.

Bugs from hell rained down on me as I integrated the routine with some of my existing calculator sketches. At one point, I discovered that a glitch that was stopping proper exponent display was nothing to do with the new code and should have caused previous LCD based sketches not to work also, but they work fine. This I call an anti-bug.

Anyway here is a demo sketch of the driver routine, attached as a .txt file. The forum software wouldn't accept .ino attachments last time I tried.

To say the least, the SSD1306 and SH1106 devices are not terrifically well documented, so the knowledge contained in the sketch could be useful to others wanting to build their own calculators with multi-line displays.


Attached File(s)
.txt  OLED demo.txt (Size: 13.21 KB / Downloads: 17)
Find all posts by this user
Quote this message in a reply
09-28-2016, 05:01 PM
Post: #37
RE: RPN-duino
The home grown display routine gives plenty of flexibility.

Here is the Texas RPN-duino wearing an alternative LED style font that I knocked up.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
09-28-2016, 07:23 PM
Post: #38
RE: RPN-duino
(09-28-2016 05:01 PM)Chasfield Wrote:  The home grown display routine gives plenty of flexibility
Superb, once again!
BTW, any prospect free room for the BigNumber lib?

Saludos Saluti Cordialement Cumprimentos MfG BR + + + + +
Luigi Vampa +
Free42 '<3' I + +
Find all posts by this user
Quote this message in a reply
09-29-2016, 06:51 AM (This post was last modified: 09-29-2016 06:52 AM by Chasfield.)
Post: #39
RE: RPN-duino
With my display driver routine and BigNumber included, the sketch for the 24 key Texas RPN-duino compiles to 29,108 kb. So it does all just fit on the Arduino Nano (30,720 k available). The previous sketch for this calculator compiled to 21,696 kb using ug8lib and the standard Math library.

For information, swapping the Math library for BigNumber and a set of home made scientific functions adds around 13 kb to a sketch, so you can see the problem. That said, ug8lib can be pared down by using a single numeric only font.

Of course none of this is a worry if an Arduino with more flash memory is being used, but they don't fit inside old calculators so well.
Find all posts by this user
Quote this message in a reply
09-30-2016, 06:50 PM
Post: #40
RE: RPN-duino
I will have to qualify my previous post regarding being able to fit BigNumber onto the Arduino Nano and drive an OLED display. Compiled sketch code size is fine but RAM usage becomes problematic when BigNumber precision is turned up. So far, with anything over 12 decimal places set, I start to run into stack/heap capacity issues. 12 decimal places is fine for displayed precision but my code relies on having so many digits available that I don't have to worry about storing exponents, only entering and rendering them. 20 digits was big enough for the real world but 12 is a bit pinched and not much use for very small values that are packed with leading zeros.

I have expunged as much static data as possible and am de-nesting procedure calls but so far, 12 digits is the stable limit.

2k ram is not what it used to be.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 9 Guest(s)