Post Reply 
Scientific RPN Calculator (with ATTINY85)
03-22-2018, 02:20 PM (This post was last modified: 03-22-2018 05:42 PM by Maximilian Hohmann.)
Post: #41
RE: Scientific RPN Calculator (with ATTINY85)
Hello!

Incredible what can be got from am ATTINY85 if one is patient enough to fine-tune the code :-)

Yesterday my package with display/keyboard modules arrived from China. Of course I instantly wanted to try out to run your calculator. But without success, my Macintosh still runs OS X 10.6.8 and the latest supported Arduino IDE is 1.6.0 which does not yet have the put() and get() methods of the EEPROM class yet.

So I decided to do something different instead and join two such boards to get a 32-key 16 digit calculator.

Looking at the boards one can see that there are very few traces close to the border which will be destroyed by cutting away 5 millimeters from either side.
Left side of the board:
[Image: IMG13405_1024px.jpg]

Right side of the board:
[Image: IMG13404_1024px.jpg]

So I went in the garage digging for my jigsaw (which actually required the most time in this project) and cut away pieces of two boards - my jigsaw skills are a bit rusty I'm afraid:
[Image: IMG13402_1024px.jpg]

In the last step I soldered the boards together to join them into one mechanical unit (using the original connector pins for strength), replaced the sawn-off PCB traces with wires and wired the connection lines across the boards. They only require an individual strobe signal each, Vcc, GND, data and clock can be shared - so a total of four Arduino pins will be required minimally:
[Image: IMG13408_1024px.jpg]

And this shows the "calculator" with everything else needed for it's operation. LiPo battery, battery holder, switch, voltage booster and an Arduino nano board. I am lazy and want my USB connector, therefore I did not use an Arduino mini or similar. We are still below 10 Euros for the combined cost of all these components. Incredible... The GPS module in the lower right corner is an option for later.
[Image: IMG13407_1024px.jpg]

And here is an image for size comparison: The dimensions of this calculator are almost identical to an HP-15C. Only that I will be able to read the display at night :-)
[Image: IMG13406_1024px.jpg]

And now some programming is left to be done.


EDIT: For some reason the shared data and clock signals did not work with my boards, so I had to split them and now require six Arduino pins.
Find all posts by this user
Quote this message in a reply
03-23-2018, 05:50 AM
Post: #42
RE: Scientific RPN Calculator (with ATTINY85)
Wow I like the idea and the ease you are experimenting.

While optimizing the code for scary I tested the replacement of the "hungry" EEPROM.put and EEPROM.get commands with a 4-byte-solution using EEPROM.write and EEPROM.read:

Code:
static void eepromput(unsigned int addr, double x) { // Put float to EEPROM bytewise
  byte n = sizeof(double);  
  union {
    double f;
    byte b[n];
  } u;
  u.f = x;

  memmove(&u.b[0], &u.f, n);
  while (n--) EEPROM.write(addr++, u.b[n - 1]);
}

static double eepromget(unsigned int addr) { // Get float from EEPROM bytewise
  byte n = sizeof(double);
  union {
    double f;
    byte b[n];
  } u;
  
  while (n--) u.b[n - 1] = EEPROM.read(addr++);
  memmove(&u.f, &u.b[0], sizeof(double));
  return (u.f);
}

This should work (and surely can be optimized) - but unfortunately this solution was more "byte hungry" than using the functions of the library.
But maybe you can use this to avoid the lack of your compiler.

Regards
deetee
Find all posts by this user
Quote this message in a reply
03-23-2018, 07:30 AM
Post: #43
RE: Scientific RPN Calculator (with ATTINY85)
Drop the memmove, the union does this for you.

You might get away this this ugly:
Code:
byte n = sizeof(double); 
while (n--) EEPROM.write(addr++, ((byte *)&x)[n - 1]);

This should be equivalent:
Code:
byte n = sizeof(double); 
while (n) EEPROM.write(addr++, ((byte *)&x)[--n]);

Although, personally I'd do:
Code:
for (byte n=0; n<sizeof(double); n++) EEPROM.write(addr++, ((byte *)&x)[n]);

or even:
Code:

byte *p = (byte *)&x;
for (byte n=0; n<sizeof(double); n++) EEPROM.write(addr++, *p++);

A reasonable compiler would treat them all the same but not every compiler is reasonable.


Pauli
Find all posts by this user
Quote this message in a reply
03-23-2018, 03:22 PM (This post was last modified: 03-23-2018 03:43 PM by Maximilian Hohmann.)
Post: #44
RE: Scientific RPN Calculator (with ATTINY85)
Hello deetee and Paul,

thanks for the workaround solutions for the EEPROM.put&get. However I decided to go a different path and installed a later version of MAC OS on an external disk (can't upgrade my computer permanently because I will lose too much precious software like Photoshop and MS office in the progress and also my printer is no longer supported in newer OS versions. And I certainly won't fall into the trap and buy all that again - this money I rather invest in my calculator collection) so that I can now run the latest version of the Arduino software.

Scary 2.0 compiles now and I could install and run it on my DIY calculator. Of course it only uses 1/2 of the hardware... But after switching it off and on again it did not start any more. Who knows why - maybe the Arduino nano handles it's EEPROM differently from the ATTINY? Not even re-flashing the board brought the scary calculator back to life so I guess it must be EEPROM related. When I have the time I will maybe try to debug the problem, the Arduino nano leaves me with over 20k of memory for adding debug statements.

In the meantime I went ahead with my "double-sized cheap Chinese display keyboard RPN calculator". As DSCCDKRC is too long to remember I now call it RLC16 (for Rpn Led Calculator with 16 digits). This leaves room for future enhancements because I bought enough of these boards to one day make an RLC32 :-)

The main problem I identified so far is power consumption which is caused by the large and bright displays - which are of course the main feature of the calculator! With all 16 digits displaying "8"s at maximum brightness the current draw from the battery is in excess of 400mA, closer to 1/2A even. The step-up converter is certainly responsible for about 20% of that but the alternative of using two such batteries and a step-down converter is not appealing. After all it is supposed to be a small calculator about the size of an HP-15C. Minimum power drain with all segments off is already 70...80mA (which could be lowered somewhat by removing the LEDs from the Arduino board or using a simpler board like an Arduino mini - or even the naked ATMEGA328P chip in the final version). So top priority is now power management. For that I will add an LDR to automatically adjust the display brightness and some kind of sleep mode which turns the display off after a few seconds of inactivity. Still the Battery (whose printed-on capacity of 6800mAh I don't believe for a second, not even half of that seems realistic) will last only briefly if forgotten to switch off, so I have to add a flashing LED as a reminder to turn the calculator off when not in use.

And I also decided that with the luxury of 32kB of memory I want 64bit floats and added the Float64 and Math64 libraries to the project, after all I want to add a GPS module at some stage and may need some precision. These math libraries together with the standard library of the TM1638 board use over 20kBytes already, leaving not too much room for fancy extras...
Find all posts by this user
Quote this message in a reply
03-23-2018, 05:45 PM
Post: #45
RE: Scientific RPN Calculator (with ATTINY85)
Hi Maximilian!

Good to see how fast you go on.

I'd like to help with "starting scary after switching on":

So the first thing is to check the pins of the hardware and software:

Code:
#define DATA   2 // 5 green    // ATTINY85
#define CLOCK  1 // 6 yellow   // HW-pins: 8 7 6 5  SW-pins: 3 2 1 0
#define STROBE 0 // 7 orange   //          1 2 3 4           4 5 6 7

Second is the initializing software in the setup-area:

Code:
  //cmd(0x88); // Activate and brightness "1000 abbb" (a=1)
  cmd(0x88 | EEPROM.read(EEADDRBRIGHTNESS)); // Read brightness from EEPROM (saved with ff)
  for (byte i = 0; i < STACKSIZE; i++)       // Read stack from EEPROM (saved with ff)
    EEPROM.get(EEADDRSTACK + i * sizeof(double), stack[i]);

If you have deleted the load-stack-from-EEPROM-lines you should uncomment the first line to activate the display and set the brightness.

If you did not delete the EEPROM-loading you are reading garbage after flashing. Note the according instructions in the readme file for initializing the display (at least pressing CLX, than f-CLX and 3 times the f-key should help):

Code:
  FIRST LAUNCH AFTER FLASHUNG THE ATTINY85:
    As ScArY saves the state (stack and brightness values) when pressing the
    f-key twice (screensaver) it also loads the state after switching on.
    But flashing the ATTINY may clear the EEPROM. So the loaded state when
    switching on the first time after flashing gets undefined values
    (... and maybe a dark or nonsense display).
  So the following procedure may help to bring ScArY in a defined state:
    1 Press CLX (X=0) ... even if the display remains dark
    2 Set brightness (f-CLX) ... at least a nonsense display should be readable
    3 Press CLX (X=0) ... value of 0 should be readable
    4 Press ENTER 3 times to clear the stack (X=Y=Z=T=0)
    5 Press STO (f-1) to clear mem
    6 Press f twice (f-f) to save the state to the EEPROM (activates screensaver too)
    7 Press f to (re)activate the screen
    8 Done! (till you flash the ATTINY again)

Regards
deetee
Find all posts by this user
Quote this message in a reply
03-24-2018, 10:32 AM (This post was last modified: 03-24-2018 10:33 AM by Maximilian Hohmann.)
Post: #46
RE: Scientific RPN Calculator (with ATTINY85)
Hi deetee,

(03-23-2018 05:45 PM)deetee Wrote:  I'd like to help with "starting scary after switching on" ...

You certainly did! It now works as advertised... You really squeezed a lot of functions into those few bytes. Of course, if I had read the instructions ("reading instructions" is not something I usually do and I guess I'm not alone with that in our circles :-) ) I could have come to the solution myself.

The one time I have used EEPROM in one of my Arduino projects so far I had my software write a few unique characters into the first bytes of the EEPROM space (like it's name and version/build number). Before reading anything from EEPROM the software could check if the data was genuine and avoid working with garbage. Of course your shortness of bytes on the ATTINY85 will make it difficult to install such a feature.

One other thing: When researching double precision libraries I came across this 64bit FPU with I2C interface: http://www.micromegacorp.com/umfpu64.html Something like that would be a true revelation for every DIY calculator project. Unfortunately all distributors seem to be out of stock of even list the chip as "discontiniued". Does anybody have a source for these chips or knows of a similar replacement?

Regards
Max
Find all posts by this user
Quote this message in a reply
03-24-2018, 12:37 PM
Post: #47
RE: Scientific RPN Calculator (with ATTINY85)
(03-24-2018 10:32 AM)Maximilian Hohmann Wrote:  One other thing: When researching double precision libraries I came across this 64bit FPU with I2C interface: http://www.micromegacorp.com/umfpu64.html

I think I've seen these before and they are a preprogrammed microcontroller rather than a FPU.


Pauli
Find all posts by this user
Quote this message in a reply
04-17-2018, 03:02 PM (This post was last modified: 04-17-2018 03:04 PM by eried.)
Post: #48
RE: Scientific RPN Calculator (with ATTINY85)
Here is my ScArY:
[Image: 0wIVxjO.jpg]

It uses a 99 cents (shipped) usb powerbank for the charging/power management.

I am designing a 3d printable case to enclose everything (including some buttons and an a purple/brown acrylic window for the "screen")

Any suggestion for the design? Should I make it similar to the HP "classics"? I am thinking on having the numbers embossed on the buttons and the functions in a small strip over the buttons (printed in a typical office labeler)

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
07-17-2018, 08:45 AM
Post: #49
RE: Scientific RPN Calculator (with ATTINY85)
Hello all!

I finally spent my ScArY an aluminium case and bigger keys.
See also: https://github.com/zooxo/scary

With the latest software (version 3) it's very competitive.

Now it's my favorite calculator on my desk.

Regards
deetee


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 




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