A poket-to-laptop size microcomputer/programmable calculator, based on Arduino DUE and Terminal-BASIC
Current pin assignment for the device mockup.
plain - 923.00 bytes - 03/07/2020 at 07:45
External electrical interfaces for hardware keyboard.
plain - 347.00 bytes - 03/07/2020 at 07:45
Most current schematics for mockup hardware. Includes SD card reader, 128x64 montchrome LCD and Micro Pro as a keyboard injector. Refer to pin assignment file.
Adobe Portable Document Format - 48.81 kB - 03/07/2020 at 07:25
Hardware Keyboard. Refer to pin assignment file.
Adobe Portable Document Format - 148.43 kB - 10/11/2019 at 06:41
The final keyboard version has been completed. The only remaining task is to design and laser-cut the top cover.
Over 70 application functions have been implemented so far.
The full list is here.
For instance, if you want to compute an average, it is easier than on HP-35s!
Given: In the dance class of 10 students, the heights were measured at 147, 152, 165, 163, 168, 163, 175, 166, 170, and 167 cm.
Find: The mean height and its standard deviation in the class.
<Enter>(a shortcut is
<A>, which displays
After entering all 10 numbers, the display shows:
Answer: the average height of the class student is 164 cm (68% of samples are in the interval of 164±9 cm).
Given: In the dance class as above, assume normal distribution and fair representation of the school population.
Find: (1) Probability the next class participant is taller than 175 cm. (2) Interval of heights for 95% of the school population.
<->. The calculator displays: 8.48665622e-002.
Answer: (1) the probability to find a student taller than 175 cm is 8.5% . (2) In the school, 95% of the students are in the interval between 147.3 and 179.9 (or 163.6±16.3) cm in height.
In the calculator, variable names may start with a letter or an underscore (
_) and can further contain letters and numbers, such as:
As in the standard BASIC, the variable type is defined by name ending.
The_Ultimate_Answer = 42.
%is a 64-bit sighed Integer:
The_Ultimate_Answer% = 42.
$is a string:
The_Ultimate_Answer$ = "42".
a!designates a double-precision real. For the Calculator BASIC, these additional types are not yet implemented, and probably will not be - most of the time engineering calculations require double precision anyway.
BASIC supports 4 variable arrangements:
pi = 3.1415926.
Fibonacci% = 0 : Fibonacci% = 1 : Fibonacci% = 1.
ROT[0,0] = cos(a) : ROT[1,1] = cos(a) : ROT[1,0] = -sin(a) : ROT[0,1] = sin(a).
The_Ultimate_Answer$ != "42"evaluates to FALSE,
The_Ultimate_Answer$evaluates to "4".
The following variables are always available (in the final version will be more):
If the SD card is inserted, during a power-down all standard and user-defined variables are stored on the card in the file named /_RPN_SaveStatus.bin Upon the power-up, the calculator is automatically restored to the state just before the power-down. If the card is not present during power-down, all user-defined variables and other settings are lost. Upon the power-up, only the standard variables will be present and will be initialized with defaults.
This allows keeping separate working environments on different SD cards. Or, in some cases, it is important to have no stored environments on the calculator - for example, for math exams.
The current variable space is defined in Variables.hpp as VARIABLE_SPACE = 32000 bytes.
Variables are placed in the variable space as following:
Quick-and-dirty video for the current project status:
Finally the keyboard PCBs have arrived from China.
For the keyboard, it is the final design. The size is 60x100 mm, and the intended position is to the right from the screen:
(The screen itself is still in the mock up stage). The keyboard has 4 LEDs and 60 switches - the one on the bottom left is a hardware power switch. All LEDs and keys can be accessed independently - in theory all 59 switches can be closed at the same time and will register.
The keyboard driver board sits below. A header for Arduino Micro Pro is provided, in case the keyboard is used as a standalone unit for PC.
Currently the driver board and the keyboard are connected by a header; the production version will be soldered.
The RPN calc can now impersonate a keyboard and a 3-button mouse, injecting keystrokes into a PC. Mouse pointer movements and mouse wheel from the calculator to the PC are also supported. With a dumb terminal, the RPN understands both the RPN and an Algebraic inputs:
The documentation is started at the project Wiki: https://github.com/ptravnik/Retro_CALC/wiki
Next: programming a File Manager!
I have continued debugging the hardware mock-up. The fundamental target was to program a simple RPN calculator UI with 6 operations plus a number of scientific functions. The integration with BASIC will come later, after all the hardware components are finalized.
New Pro Micro clones with 3.3V processors have arrived, so the logic level conversion is no longer necessary. See the new wiring diagram in the file section.
Files are uploaded to https://github.com/ptravnik/Retro_CALC (its a proof-of-concept code, use with caution!)
Two problems have been hit so far. Firstly, the real-time clock of ESP32 is not very precise in the sleep mode; thus an external RT clock module is required in the future. Secondly, the sleep current of this particular Dev board is 15 mA, while in running (no WiFi) - 55 mA. Need to troubleshoot it a bit further.
Currently the mockup looks a bit neater and can run from standalone power. Can you take it to the math exam?
The current functionality fully operational and tested:
(1) Hardware keyboard (a mock-up so far), with CP1251 code page support;
(2) LCD power manager, with PWM control and sleep capability;
(3) LCD driver with fancy LCD font, resembling Electronika MK-90;
(4) Sleep mode and wake-up by a hardware button;
(5) RPN calculator UI.
The font looks like this:
Or in Russian:
The current functionality implemented, but not fully tested:
(6) Serial connectivity to Arduino Micro Pro;
(7) SD card reader.
The deferred / not yet implemented functionality:
(9) LiPo charger / battery;
(10) Independent RT clock.
The hardware is running a simple RPN calculator interface. The operation is as following:
o The calculator can be operated by either the hardware keyboard or a serial port terminal.
o The display is composed of 2 parts: the upper depicts the RPN stack, the lower is for entering commands.
o Enter numbers as normal, e.g. 123, 123.456, 123.456e89, 123.456e-89 etc. "E7" or "e7" stand for "10 power 7". Buttons <DEL>, <Backspace>, <Home>, <End>, <Left>, and <Right> should work as expected.
o Besides the entry as above, the following is allowed: 123k, 123M, 123c, etc. The letter is an "engineering multiplier": f="e-15", p="e-12", n="e-9", u="e-6", m="e-3", c="e-2", d="e-1", k="e+3", M="e+6", G="e+9", T="e+12", and P="e+15".
o Upon entering a number, press <Enter>. If the number in the entry line is valid, it is processed into the X-register, if not - ignored. Upon entering the number in stack, all the values shift by one position. The current stack is 20 numbers.
o Alternatively, press an operation button <+>, <->, <*>, </>, <^>, or <+/->. If the number in the entry line is valid, it is processed into the X-register, if not - ignored. Upon this, an RPN operation on stack is performed. Division by 0 causes an error, which can be cleared by pressing <ESC>.
o The available math functions: sin, cos, tan,
sqrt - square root,
sq - square,
exp - e power x
inv - computes 1/x
hex - converts x to hexadecimal (rounds to integer first)
o Stack manipulation functions:
prev - previous X (shortcut: PGUP),
swap (shortcut: DOWN),
roll (shortcut: PGDN)
previous entry (shortcut: UP)
#scr status - updates status label
#scr labelx - updates label X
#scr labely - updates label Y
#scr labelz - updates label Z
o Screen power and brightness:
#scr off - puts screen to sleep
#scr on - wakes up screen
#scr+ - increase brightness
#scr- - decrease brightness
Can your next DIY programmable calculator do the same? :) This is Arduino DUE, hope ESP32 and even ESP8266 will be ready soon.
Finally got the working mockup running. Currently the hardware includes:
The LCD part can be easily removed from the primary board - it is held attached by a header.
Power consumption in this configuration:
I have also compared this to the power consumption of Arduino Mega 2560 with a TFT 480x320 color screen and an SD card (see the video in the Project Log 01). Two different Mega we used: "Classic" and "OSEPP" (in brackets).
I could not find an elegant way of disconnecting/managing the TFT power and the TFT backlight as it is mounted on a shield.
Obviously, Mega with a BW LCD would make a decent calculator with about 30-50 mA consumption, which equates to one month of a continuous running! Unfortunately, this system has only 4-byte arithmetic, no real-time clock, no WiFi, etc.
The calculator connects to the PC in three ways:
The Terminal BASIC on ESP32 is working... kind of. I have replaced the capitalized keywords with a lower-case.
The SD card code is not compiling properly as the ESP32 and the Arduino libraries are different - still working on it. The hardware is fully operational, and I am able to run independent tests:
The Terminal BASIC is seemingly having a hard time working with double-precision numbers on ESP32. This program calculates a factorial in integers:
Now replacing r% with r - for 4-byte floats:
Finally, we replace "r" with "r!" ("!" stands for long reals) results in busted stack!
Next: debugging Terminal BASIC on ESP32!
Overall design notes.
The main processor is ESP32 WROOM 32U. For the final version can possibly source a board with an in-built LiPo charger, such as GeeekNet https://www.seeedstudio.com/GeeekNET-ESP32-Development-Board-p-2945.html For now, the testing board is more conventional DevKitC.
ESP32 has been selected for two reasons. Firstly, it has excellent low-power features, allowing to save the battery. Secondly, the processor provides double-precision FP computations, which is essential for an engineering calculator. ESP32 can communicate to the PC via its USB port, WiFi and Bluetooth, so BASIC can be used from a PC terminal emulator - for, example, the user may want to enter and debug a complex routine by using the conventional keyboard and the big screen. The same USB port is connected to the LiPo charger / power supply (or will be using different ESP32 boards in the future - have not decided yet).
The main processor is connected to 4 peripheral devices via its primary SPI bus: the SD card reader, the 128x64 LCD display (may consider a different display although), the keyboard and the power controller. The latter allows the ESP32 to manipulate the LCD back-light, thus reducing the power consumption. It also controls the power supplied to the Arduino Micro Pro. The keyboard provides a hardware Reset button, which is needed to load programs into the ESP32.
The primary use of the Arduino Micro Pro is to impersonate a conventional keyboard/mouse for a PC (for example, for a text injection). The processor is connected to the ESP32 via Software Serial. Via the same interface, the ESP32 can send commands for a single-tone sound generation, such as beeps and simple melodies. As an alternative design, the LCD display back-light LED may be driven via the Arduino Micro Pro PWM output.
1. BCL interface. In true tradition of retro calculators, this should be a comprehensive BASIC-system. All file system manipulations and other functions should be accessible from the BASIC command line (BCL). For example, to change the calculator mode from Radians to Degrees, the user switches into the BCL and types something like SET ANMODE DEGREES. To change the calculator precision and output pattern to scientific with 4 decimal places, one types, for example, SET NUMODE SCI4 The arithmetic expressions can be evaluated directly from the BCL, for example, ? 1e13/SIN(45) immediately evaluates into 1.175e+13. PRINT HUMODE returns the numeric code for the SCI4 constant: 14 (or rather 1.4e+01 as we requested a scientific format). Naturally, all standard BASIC commands should work in BCL as expected, e.g. 10 PRINT 1e13/SIN(45) returns OK and inputs the program line into the memory. The user should be able to use arrows to scroll the screen up and down beyond the 8-line boundary. At least 40 lines should be supported. Text selection and Copy/Paste function should be supported.
To make the system more practical, several additions to BCL are essential.
2. RPN interface. The screen displays three positions of stack: X, Y, Z. The total stack capacity should be about 20, plus an additional slot for the previous X value. The buttons should work as expected for an RPN calculator, e.g. pressing <1>, <9>, <.>, <7> results in X displaying "19.7". Then, pressing <Enter>, <2>, results in X displaying "1.970e+01" (remember, we are in sci-4 mode) and Y displaying "2". Pressing </> results in X displaying "9.850e+00". The previous X slot contains 2.000e+00. The RPN interface should be accessible from the BASIC programs. For example, the user wants to implement a program for calculating roots of a quadratic equation:
010 SET RPNLABELS "C (input)", "B (input)", "A (input)" 020 HALT RPN 030 A = RPNSTACK(2) 040 B = RPNSTACK(1) 050 C = RPNSTACK(0) 060 D = B*B - 4*A*C 070 SET RPNSTACK 2, D 080 IF D < 0 GOTO 130 090 SET RPNSTACK 0, -(B+SQRT(D))/A/2 100 SET RPNSTACK 1, -(B-SQRT(D))/A/2 110 SET RPNLABELS "Root 1", "Root 2", "Discriminant" ...Read more »
Full hardware mock-up is now operational (yes, it is damn ugly).
The current mock-up version is based upon:
(1) Arduino MEGA 2560
(2) Arduino MEGA SRAM shield (my PCB is modified for 56k RAM instead of 32 in the original version) https://hackaday.io/project/21561-arduino-mega-2560-32kb-ram-shield
(3) Arduino SD card reader; this version is for Uno, but runs on Mega with pins 10-13 using Soft SPI (library mods by David Mellis). Note that the standard SD library will not work if the classic Uno shield is transplanted to MEGA:
(4) Piezo speaker on line 9
(5) Hardware keyboard on lines A0-A4. The driver is here (check the Morse code example!):
(6) LCD screen 128x64 pixels on SPI. The driver is U8g2 from Oli Kraus (it writes Cyrillic and other character sets):