Programming a TI-85 Graphing Calculator – Revisting the 1990’s TI-BASIC

In my previous post, I discussed how I cleaned out and restored my old TI-85 Graphing Calculator after finding corroded batteries inside.

After finally getting it to turn on, I immediately started reliving my high school experience. It was honestly kind of surprising how quickly my memories came back to me. Despite not using the calculator for almost two decades, I was able to remember and use many of the functions and my fingers seemed to instinctively know where each letter was on the keyboard. Maybe it shouldn’t have been surprising though, that thing was an extension of my arm during many classes in high school and college and I spent a lot of free time reading the manual and learning the simple programming language that came pre-installed. (ProTip: This is not how you become popular in 1995.)

I had gotten the calculator out of storage to see if any of my old high school programs were still installed. Unfortunately, the TI-85 did not come equipped with permanent storage so programs needed power to survive in RAM. Mine were all lost.

I was probably feeling overly nostalgic because I started working on a new program for the calculator. Appropriately enough for a calculator, my program is called Simple Math. It takes two numbers and then adds, subtracts, multiplies, or divides them. Obviously, this is a bit redundant to the calculator’s basic functions. I was more interested in working with the TI-BASIC programming language than I was with creating something useful.

The TI-85 was limited to just 8 characters for the names of variables, functions, and files (as were most of computers of that era). So the program is actually called SMPLMTH. When loading it up from the Programs menu, this is what you see.

The Simple Math input screen

The program has a greeting and then asks for two numbers. The TI-85 has two methods of asking for user input. The first (and the one I’ve used here) is the Input command. It simply displays a question mark and then waits for the user to type in a value.

An example of the code for Simple Math

The second method is using a Prompt command. This is very similar except that the name of the variable being loaded is displayed for the user.

Using the Prompt function in a simple program on a TI-85

After the user enters the numbers, the program displays the chosen numbers and then asks which mathematical function should be applied.

Imagine a calculator program that can do all of this?

The TI-85 cannot concatenate strings and numbers so the line displaying the chosen numbers was fairly difficult to figure out. To be used in a sentence, the variables containing numbers had to be cast as strings. In modern programming languages, there are simple commands that can easily cast values to other data types, but not so on the TI-85. For example, in Excel, you would use the TEXT function to convert numbers to strings. (Although many can do it implicitly, including Excel. The TEXT function in the example below is not necessary to get the same result.)

Casting number values as text in Microsoft Excel.

To accomplish it on the TI-85, I needed to use a special function called St⯈Eq (String to Equation). It wasn’t as simple as just dropping the variable into the function. I ended up needing to do a Linear Regression on the variable and then substring the result into a new string variable. (I can’t take credit for the idea, I found the code on Technicalc.org.) That’s obviously needlessly complex but I think it was the only solution available.

It also highlights one of the major difficulties of writing TI-BASIC – the use of non standard characters. Converting strings required the Eq⯈St command. Storing a value to a variable requires another arrow character. For example, 60 → VarName. This is significantly different from other version of BASIC which used the LET command (ie. LET VarX=95). The arrow assigning values reminded me a little of the R syntax, although that can easily be typed with a keyboard (i.e. VarX <- 60).

A few of the special arrow characters on the TI-85

I’m using a unicode arrow characters (U+2bc8 and U+2192) to replicate the look of these characters, but I have no idea what the characters actually are. They definitely make programs harder to write since you can’t use a regular text editor. As I recall, to write programs for a TI-85, you needed to use their TI-GRAPH LINK software. It was a very proprietary model.

Once you entered your numbers and made your calculation choice, the Simple Math program used an IF statement to determine which function to perform and output the result.

The final output of the Simple Math program

Despite the program being pretty useless, it was interesting to work in such an old environment and think about what has changed and what has remained the same in the years since I last used it.

Some functions like IF statements are very similar to their modern equivalents (although I needed to nest the IF statement to have multiple conditionals). Other things, like the lack of local variables were surprisingly different. (The variables that I used in the program were automatically global and accessible by any other program or calculation.) Even in this little program I was able to find several examples of increased efficiency and simplified syntax in modern programming languages.

Using the NUMA global variable outside of the Simple Math program.

It was also interesting to think about the possibility that I might be one of the only people in the world to write a program for this particular piece of hardware in 2019. Although that might not be true because the internet still has a surprising amount of resources of programming older TI graphing calculators. Perhaps there are more hobbyists out there than I realize.
ticalc.org has a ton of programs, examples, and guides for the TI-85
TI-Freakware has a guide to TI-BASIC for the TI-85.
TI-Basic Developer has a ton of guides and programs available (although apparently for later TI versions)
Wikibooks has a TI-Basic manual, but once again it seems more focused on later calculators. (I found a few commands that are not compatible with the TI-85.)
The University of Arizona maintains a website of TI-85 lessons.

The TI-85 is a bit of a relic now. Between the monochrome screen, tiny amount of memory, difficulty of transferring data and programs, and non-standard characters, it is hard to think of a compelling reason to use it today. Making kids learn coding on this in the age of languages like Scratch and Python would be needlessly difficult. However, playing around with it for an evening reminded me of what a remarkable piece of technology this was. Decades before anyone had conceived of a smartphone, millions of high school kids carried a programmable computer in their backpacks that wasn’t that much bigger than a modern larger smartphone (at least in length and height, not so much in terms of width).

Size comparison of a TI-85 and a Google Pixel 2 XL

Unfortunately I am not able extract my example program off of the calculator. I’ve long ago lost my graph-link cable and even if I had it, my computer doesn’t have a DE-9 connector. Also, the Graph-Link software for the TI-85 doesn’t support versions more recent than Windows 95.

If you’d like to see the program, I’ve typed up the code below. The variables NUMA and NUMB hold the numerical values (REAL type in TI-BASIC) and NUMAS and NUMBS are the String versions. It is released under the MIT License.

PROGRAM:SMPLMTH
:ClLCD
:Disp "WELCOME TO"
:Disp "SIMPLE MATH!"
:Disp "ENTER A NUMBER"
:Input NUMA
:Disp "ENTER ANOTHER NUMBER"
:Input NUMB
:Linr {0,1},{NUMA,NUMA
:Eq⯈St(RedEq,X
:sub(X,1,lngth X-3 → NUMAS
:Linr {0,1},{NUMB,NUMB
:Eq⯈St(RedEq,X
:sub(X,1,lngth X-3 → NUMBS
:ClLCD
:Disp "YOU CHOSE "+NUMAS+" AND "+NUMBS+"."
:Disp "WOULD YOU LIKE TO:"
:Disp "1. ADD"
:Disp "2. SUBTRACT"
:Disp "3. MULTIPLY"
:Disp "4. DIVIDE"
:Input ANS1
:If ANS1 == 1
:Then
:Disp NUMA+NUMB
:Else
:If ANS1 == 2
:Then
:Disp NUMA-NUMB
:Else
:If ANS1 == 3
:Then
:Disp NUMA*NUMB
:Else
If ANS1 == 4
:Then
:Disp round(NUMA/NUMB,2)
:Else
:Disp "THAT WASN'T A CHOICE!"
:End:End:End:End

TI-85 vs Potassium Carbonate: A Cautionary Tale

This year at the R Studio conference, I heard an excellent presentation from Mary Rudis on teaching statistics with R at community colleges. (I don’t teach at that level, but enjoy learning more about education techniques.) She mentioned in her talk that many students get their start in stats programming using graphing calculators.

This comment was just an aside, but it got me thinking about my own programming history and some of the early programs I wrote on my TI-85 graphing calculator when I was in high school and college to help calculate equations in my science and math classes. For example, I remember writing a simple program where you could enter the mass and distance of two objects and it would calculate the gravitational force.

I came home from the conference feeling nostalgic about my early programming work. I wanted to see if any of my old programs were still saved on my calculator. I dug it out of a storage bin and opened up the back panel to put in some batteries. Unfortunately, there were already batteries in there…

Potassium Hydroxide forming a Potassium Carbonate salt around the seal of the battery. (Note, be smarter than me and don’t handle them without gloves.)

I don’t remember what year those batteries were installed, but they expired 16 years ago. At some point, they leaked their internal potassium hydroxide, which forms a salty crystal called potassium carbonate once outside of the battery. The inside of the battery compartment and several of the springs were caked in the stuff. (This is a skin irritant, a fact I discovered when I picked up the batteries. You should wear gloves when handling leaky batteries.)

Potassium Carbonate salt around the springs in the TI-85 battery holder.

Using a Q-Tip dipped in white vinegar, I was able clean out the area. Vinegar is a mild acid so it neutralizes the strong base of the potassium carbonate. I tried hard to avoid leaking any liquid inside of the calculator.

After giving the calculator some time to dry out, I loaded it up with fresh batteries and crossed my fingers.

The TI-85 graphing capabilities.

It powered right up! All the buttons and the screen seem to work fine. Thankfully, I haven’t noticed any adverse performance effect at all.

I was sad to realize that the TI-85 did not have any form of permanent storage. (It was created in the days of the 3.5 inch floppy disk, after all.) All the variables, programs, and custom functions are stored in memory – which required power to maintain. The calculator had a backup coin cell battery (to preserve power when changing the AAA batteries) but that had long since expired as well. Whatever programs I had written had long ago been erased when the calculator ran out of power.

Despite losing all that early work, it’s been surprisingly fun to have this piece of my teenage life back. I’ve done some simple graphing and even written a small program. (More on that later.)

It was a good reminder to always remove the batteries from electronics that are not going to used for awhile. I was lucky that the leaked batteries didn’t cause any damage to the calculator. The TI-85 may have escaped this battle unscathed, but leaking batteries can cause irreparable damage to electronics. Don’t do what I did and let them sit for over a decade in storage.

Edit: I’ve added a new post about programming the TI-85.

Introduction to Paper Circuits with an LED Valentine’s Card

Creating a paper circuit in a card is a very fun project that teaches kids some basics about electronics and makes a fun gift. I have designed a Valentine card with a simple circuit design that you can download and craft.

The completed paper circuit valentine card all lit up

To create the card, you’ll need an LED light, conductive copper tape (the guideline is sized for quarter inch tape but other sizes should work), and a 3V coin cell battery. I’m using a CR1620 battery in this example but other 3V sizes work just as well. I also recommend that you print the card on a heavier stock paper so that it can hold the weight of the battery and light.
Here are the links to download the card in PDF format.
Valentine Card PDF (US Letter)
Valentine Card PDF (A4)

I’ve learned the hard way that before applying any tape, you should always make sure the LED works. You can easily test this by placing the legs of the LED directly on the battery. Make sure that you put the longer leg on the positive side of the battery.

Testing an LED bulb

The card is marked on the front and back with some guides to help you prepare it. On the front side there is a dark square indicating where the light bulb will pop out. I cut out this out with an X-Acto Knife but you could also use a hole punch if you have one long enough.

The inside of the card has guidelines showing where the copper tape, LED, and battery should be applied.

Apply the copper tape to the card following the guidelines. Try to keep the tape as continuous as you can by folding over the corners instead of breaking the tape. This creates a stronger circuit by having a continuous line for the electrons to follow. (You can also overlap the corners if the tape is broken but that risks a weaker or broken connection.)

Making a corner from copper tape

To put on the battery, create a tape roll so that it is sticky all around. Place the roll on the battery spot and firmly press down to create a good connection with the tape underneath. Then stick the battery on top of the roll with the negative side down. (The negative side of a coin cell battery is usually textured.)

A roll of copper tape to attach the battery to the circuit

Finally, bend the legs of the LED out so that they point in opposite directions. Make sure you keep track of which one is the long leg. Place the LED on the spot indicated with the legs overlapping the tape on either side. Make sure that the longer leg is on the positive side or the circuit will not work. Secure the legs with two more small pieces of tape. This will complete the circuit across the broken spot in the tape.

Securing the LED with copper tape above and below the LED legs.

When the card is folded on the score line, the copper tape will touch both sides of the battery and allow the electrons to flow through the circuit – lighting the LED in the middle.

Inside of completed Valentine Card

The card was created in Inkscape. It uses the font Destructo Beam by Blambot Comic Fonts.
The card is available under an International Creative Commons 4.0 by-nc-sa license so you are free to modify the card if you’d like. (Let me know if you do, I’d love to see what others do with it).
Valentine Card SVG format (both US letter and A4 included).

Additional Examples of Nested If Statements

In my previous post, I discussed an issue in Scratch relating to Nested If statements. I think that by limiting the If statement to only one conditional (an If condition or an Else condition), the concept of multi-conditional statements has been made more difficult that it should be. I believe that Nested If statements are more complicated for a beginning programmer to understand than Else If statements.

I thought I’d take a look at how a few other programming languages have handled multi-conditional statements.

There’s an alternative to Scratch called Snap! designed by UC Berkeley. (It’s actually based on Scratch and looks very similar.) The language has less focus on being immediately intuitive and extends Scratch with blocks that handle several advanced programming concepts.

I used Snap! to write the same basic emoji program that I created in Scratch. Using the basic available blocks, it looks very similar. To use multiple If statements, I had to nest them inside the previous Else statement.

I did like one difference that stood out from Scratch. The nested Ifs were automatically set in alternating shades to make them stand out. This increased the readability and made it a little easier to understand what was going on.

Snap! is designed both to teach younger children and adults programming concepts. There are a few additional blocks in the base version of Snap! that you won’t see in Scratch, but it also comes with several libraries that add even more complexity and advanced techniques. The library “Multi-branch conditional (switch)” allows (as the name implies) multiple conditionals in an IF statement. It adds several new commands to the Control blocks. One of them is a cases block that allows for multiple else if statements to be added.

Else If built in Berkeley’s Snap language

The black arrows in the bottom right add or subtract spaces to insert more Else If statements. The final statement can be used for an Else block that runs if none of the other Else If blocks run. The syntax and visual layout takes a little getting used to, but I do like this better than nesting all the If statements inside of each other.

Another language that people encounter early in their programming careers is the cell formulas in Microsoft Excel. Up until recently, multiple If statements needed to be nested within each other, similar to Scratch. I’ve spent many years in my career writing overly complicated formulas like this.

Nested If Statements in Excel

The commas dividing the IFs and the stack of closing parentheses at the end make the typo potential high and the readability low. Thankfully, in newer versions of Excel (and Google Sheets), there is a function called IFS which handles multiple conditionals much more smoothly.

The IFS method of handling multiple if statements.

The format of this is IFS(Condition 1, Result 1, Condition 2, Result 2, Condition 3, Result 3 and so on. The result for the first condition that is true will execute. There isn’t a default ELSE, so to replicate that functionality you can just add the word TRUE as the final condition check. If none of the previous conditions were met, that one one will always execute.

Finally, it worth mentioning that many other programming languages have a command called Switch or Case. (You may have noticed that the multi-conditional block in Snap! is called cases.) Functionally, this behaves much the same as an ELSE IF. A series of cases are evaluated and only the one that matches a condition is executed. Here is an example of the emoji program written in JavaScript with a Switch.

JavaScript Switch Example

The syntax here shows a key difference from the ELSE IF logic. 1.) There is no comparison operator (===, >=, etc) required – it is assumed by default. The switch statement takes a variable or value and then compares it with each of the cases. 2.) Unlike an IF statement, the program will evaluate all cases even after finding a match. To prevent this, the break keyword is included in each case result. When encountering a break, the program will move on to whatever follows the switches final curly bracket. 3.) The default keyword functions in the same way as the terminating ELSE in and IF statement. This will run if none of the other cases were met.

Some programmers prefer to use IF statements for comparison operators such as equality or greater than or equal to. Switch is often used for checking the value of strings, as in the emoji code above. For example:

if(Variable1 >= Variable2) {
  console.log("The first number is higher");
} else {
  console.log("The second number is higher";)
}

switch(Variable1) {
  case "Breakfast":
    console.log("Good morning!")
    break;
  case "Lunch":
    console.log("Good afternoon!")
    break;
  case "Dinner":
    console.log("Good evening!")
    break;
  default:
    console.log("Good day!");
}

Honestly, the choice of using an IF THEN ELSE or a SWITCH comes down at least partially to programmer preference. There is some speed variability between the two methods that can be analyzed if optimization is needed, but generally speaking, either method can be used for both of the above situations.

Regardless of which methodology is used, the multi-branched conditional statement is an important concept for new programmers to learn. The nested if statements in Scratch can work for simple projects, but for more advanced work, programmers will need to learn improved techniques.

Nested If and Variable If Statements in Scratch

I love using Scratch to teach children and others about coding. By using blocks instead of syntax, it has simplified coding to make it accessible even for very young children. I love that it has eliminated the need to learn some of the more difficult aspects of coding such as where curly brackets and parenthesis go when a person is first learning about things such as variables, control flow, and loops.

There are a few areas where I wish Scratch hadn’t simplified quite so much. I understand the need to keep things simple for young learners, but in some cases, over simplification inadvertently leads to more complex situations. The primary example of this is the limitation of the IF THEN ELSE to only one ELSE statement.

For those not familiar, the IF THEN ELSE statement is used to control which parts of the code run based on variable conditions – often times input from the program’s user. (This is called a conditional logic or control flow.) The programmer can put in several alternate pieces of code – which one runs depends on the values currently in the program. For example, if a number is greater than 50, then the program will say it is a big number. Else, the program will say it is a little number.

Example of an IF statement in Scratch

The problem is that programs often have more than two alternatives that might need to run. There could be three, ten, or even a hundred alternatives. In most programming languages this is handled with an ELSE IF statement (or alternatively a SWITCH statement). If the first condition is not met, the program will check the next one. If that one is not met, it will continue checking down the list until a condition is met or it reaches the end of the list.

To illustrate this, I’ve written a simple program that has four conditions. The user is asked to enter a letter. A different emoji is returned for each letter – including a sad face in case none of the requested letters was used.

Here is the program in a language called JavaScript. The variable emoji contains the user input. The first IF is just written with “if” but each subsequent one is written as “else if”. Finally, an “else” catches anything that didn’t match earlier.

Here is the same example in a language called Python. This one uses the slightly more hard to read syntax of “elif” which is short for “else if”.

This syntax is clean and easy to read. You can follow the logic easily and determine what will happen based on the value of the variable.

Unfortunately, Scratch lacks the ability to have multiple conditionals in a single IF statement. There is a workaround called the Nested If statement. Essentially, this is just a regular IF THEN ELSE statement, however, instead of putting something like a message to be displayed to the screen in the ELSE, you put another IF statement. This can be repeated over and over again until you have all your conditionals. This can get very complicated very quickly.

Here is the same program written in Scratch. Notice how each ELSE statement has another IF THEN ELSE statement inside.

Scratch Nested If Example

What if you want to add more letters and emojis to the code? To add another condition into the logic flow, you drag a new IF statement into the ELSE statement of the last IF statement. This can be repeated as often as needed.

While not problematic at first, it can become overwhelming in short order. In this example, we display a separate emoji for letters A through H. (Also out sad face is displayed if none of those letters were used.)

Look at the bottom of this code block – there are 8 block closures all in a row. Imagine if we had an emoji for all 26 letters!

This can be very confusing, especially for younger children learning to code. It’s also a fairly archaic way to code – more reminiscent of programming languages from the 80s then those of today.

This has been discussed in Scratch forums in the past but does not seem to have generated much interest.

Other block languages have added this functionality in a very eloquent way. Here’s an example from Microsoft’s MakeCode. The user simple clicks the plus sign at the bottom of the block to add a new else if statement.

To keep things a little easier to read (like the MakeCode example), I like to use an alternative method for keeping track of multiple IF statements. I use a variable to track if an IF Statement has been used, which allows me to keep the various IF statements separate. This is quite a bit easier to read.

Here is the original program again, but now using a variable (emojiCheck) instead of multiple nested IF statements.

The emojiCheck variable is initially set to zero but if any of the IF conditions are met, it is changed to one.

The final IF statement checks for the value of emojiCheck. If it’s zero, that means that none of the previous IF conditions were met and the sad emoji face is displayed. If any of the previous IF statements were met, this block does not execute.

It is not perfect, but I think this Variable If method may help new users learn the code without the confusing aesthetics of a nested if statement.

All of the code in this example is available to those interested.
Emoji Code Examples
The Scratch programs are also shared with additional comments included in the code.
Nested If example in Scratch
Variable If example in Scratch

Edit: I added a few more examples from other programming languages in another post: Additional Examples of Nested If Statements.