A Programming Language for a Portable Development System

Prototyping with Arduino and compatibles is fairly easy, especially when it comes to the hardware.  A breadboard simplifies things quite a bit.  A few months ago, I realized that I did not have any, so I purchased one, in a kit, on Amazon from a company called Elagoo. The kit, for about sixteen dollars (US) contained a lot of parts and the breadboard. Well, the board is fairly small, so I decided to create a portable workspace and mount the breadboard, an Arduino UNO R3 clone, a 2 x 16 LCD and some cord organizers.  It works great, and I can take my project around. Nice.  Problem, though, is that I still need to be tethered to the computer in order to write code.

WP_20161001_18_38_08_Pro_LI (2)This got me thinking…could I come up with a small but easy to use interface language that could be coded with nothing more than a 12 key keypad?

The answer is yes.  So, I have come up with an initial set of opcodes for programming with nothing more than what is on my workspace. 

This language would more resemble CHIP-8 than, say, the Arduino language.  Commands, statements and functions all use a single byte but can have one or more subsequent values for parameters.

The tables below outline the main features. The keypad I am using (because it was less than a buck) does not have enough keys for full hexadecimal, so I had to improvise. Still working on a scheme to allow alphanumeric entry without connecting a full ASCII keyboard.  For now, the language will be limited to reading sensors, accepting decimal (though integer only) numbers. No video, serial out to the 2×16 LCD or a Bluetooth module.

For the tables, the first column is the opcode, second is what the opcode does, third is any parameter( s ) necessary and the last is a description.

Assignment:

01

Let

Var (00-0F)

Value (00-FF)

Conditionals:

02

IF

Var (00-0F)

01 is equal, 02 is <, 03 is >, 04 is <>

03

Jump if true

Addr (00-FF)

 

Program Flow:

04

Goto

Addr (00-FF)

Transfer control to address

05

Call

Addr (00-FF)

Call a subroutine

06

Return

   

07

End

 

Ends program

Input/Output

10

Inkey

Var (00-0F)

Gets input from the keyboard

11

Out

Var (00-0F)

Outputs a value

12

Temp

Var (00-0F)

Gets a reading from the temperature sensor

13

Pinset

00-FF

Send a value to pin

14

Pinread

00-FF

Get a value from pin

15

Xfer Pin

Var (00-0F)

Transfers value from read pin to variable

I would envision the interpreter being fairly small, so it may be possible to integrate several libraries for the more popular sensors, like DHT-11 temp sensor and others.

So, what do you think?  Is this something of interest? Please post your thoughts in the comments below.

Advertisements

Tiny Basic Programming Lesson: talking to the real world

12419231_974683622601393_320731550894605287_oUsing HalfByte Tiny Basic to interface with the external world is pretty easy to do. There are already built in interfaces for temperature and humidity, but, using AREAD, AWRITE, DREAD and DWRITE, we can access a variety of sensors and modules that do not need specialized libraries in order to talk to them.  Sensors such as the touch sensor, IR reader and the light sensor I talked about in previous posts can easily be used by HB Tiny Basic.  The key to using them is to know the range of values they return.  Since documentation for them can be difficult to obtain, the best way to figure it out is to connect them and experiment.  Once you get a feel for the range of values and what they mean, you can easily incorporate them into a project.

Lets consider the following code:

100 CLS
110 A=AREAD(0)
120 CURSOR 0,2
130 PRINT “Light level: “;
140 IF A=0 PRINT”Pitch Dark”:GOTO 500
150 IF A>0 IF A<100 PRINT “Dark    “:GOTO 500
160 IF A>100 IF A<300 PRINT “Low     “:GOTO 500
170 IF A>300 IF A<600 PRINT “Moderate”:GOTO 500
180 IF A>500 PRINT “Bright”:GOTO 500
500 GOTO 110

All this code does is read the sensor, determine a range for light level and output the results.  300 and above is about what you have in a living room in the even with one or two lamps turned on.  Over 500 and you are talking some bright light.  The higher the value, the brighter the light.  Zero, of course, is a total lack of light.

Looking at the code, you will notice that we are reading the A0 analog pin.  That’s the pin the light sensor is connected to. In HB Tiny Basic, A0 to A7 is represented by the integer portion-0,1,2 and so on.  To designate that you want to use the Analog pin, use AREAD.  The same rules apply for the Digital pins…use DREAD and 0 to 13 for the pins.  Line 110 above, A=AREAD( 0 ) to read A0 into the variable ‘A’.  That value, in variable A, becomes static until the pin is read again. This allows us to use the value, as captured at that moment, to do what ever we want.  In this case, we use it to determine if the light level is pitch dark to bright. 

Because HB Tiny Basic lacks such operators as ‘and’ and ‘or’, we have to use multiple IF statements. So, for line 150, instead of something like:

150 IF A>0 AND A<100 PRINT “Dark    “:GOTO 500

we have to use:

150 IF A>0 IF A<100 PRINT “Dark    “:GOTO 500

All it is saying is ‘if the value in A is greater than zero AND less than 100, then print the Dark to the output device and skip to line 500’.

Once we are done  evaluating the light level, we just go back and do it again.  A real world use of this could be like ‘if the light level goes below 300, set pin 10 to high so it turns on a light; if the level goes above 600, set the pin to low to turn off the light’.

There are maximum and minimum values and they are determined by both Tiny Basic, which allows for –32767 to 32767, and the sensor itself.  Some will return a non zero value to indicate an ‘on’ value and a zero for ‘off’.  Or, as in the case of the touch sensor, the values switch between 22 and 1023.  Your mileage may vary.

I wrote a short little game, loosely based on Flappy Bird, that uses the light sensor as the controller. The code is posted here and shows a real world use for using AREAD to retrieve data from an external source.  You could take the code and fancy and add code to trigger a buzzer when the bit hits a pipe (using either AWRITE or DWRITE.) 

There all kinds of things you can do with these four simple functions and statements.  A future modification to the language might be the ability to auto run code from eeprom, which would allow HB Tiny Basic to then be used as a control language.  You can do a lot with few resources.

From patch cords and punch cards to GUI’s and Mice: how programming evolved

Software development has come a very long way since the early days of 1946 when Eniac was programmed via patch cords.  When more modern computers, such as Univac, hit the market, programming them was better, but still required skills that were just impossible to come by. The problem was so bad, that it nearly derailed the whole industry before it really got going.

IBM704That changed, though, in 1954 when John Backus of IBM developed the FORTRAN language.  Considered the first successful high level language, FORTRAN, short for FORmula TRANslator, was, initially, greeted with a bit of skepticism, but that was satiated with the optimizing compiler. There was a fear that the code it generated would not be as tight as the previously hand assembled code, so the optimizing compiler was developed to quell those fears.

The first FORTRAN was released in 1957, followed up the next year with FORTRAN II, which contained enhancements including the addition of procedural programming. Functions and subroutines allow the developer to create their own functions for the first time.

FORTRAN was a big step forward, but it had its limitations. Primarily, it was not very good with business uses. The solution would come from a committee that formed in 1959.  The committee was formed by people from the government and private industry.

FLOW-MATIC, a language developed by Grace Hopper, was used as the foundation for COBOL, or COmmon Business Oriented Language. FLOW-MATIC was drawn from more than other language specs mainly because it was the only one that had actually been deployed and used. COBOL gained wide acceptance in business and enjoyed a run that continues today, though it use has dramatically declined over the last couple of decades. 

Both FORTRAN and COBOL served both the science, research and business communities, but they were not all that easy to master. FORTRAN more than COBOL, but were still out of reach for many.  In 1962, John Kemeny and Thomas Kurtz developed the Beginners All-purpose Symbolic Instruction Code, or BASIC.  Panned by most ‘professional’ programmers and purists, BASIC, nonetheless, gained wide acceptance in the 1970’s with the advent of the microcomputer.

Initially, BASIC was both the operating system and language of many homebrew and early retail microcomputers. However, those machines were very limited in memory and power. The version of BASIC that was generally in use was called Tiny BASIC. These ‘tiny’ languages truly were tiny: most took only 2.5 to 4K of memory. They generally only handled integer numbers, limited or no string handling and only the ‘basic’ of statements (like IF-THEN, GOTO, PRINT, INPUT, etc.) were included. 

Things looked up, however, when the ALTAIR computer was introduced. Two kids decided they would supply a BASIC language for the computer. Paul Allen and Bill Gates set up shop in New Mexico and began Micro-Soft. Gates delivered the final bits of code the day they were supposed to meet with Ed Roberts, the owner of the MITS company, the producer of the Altair.  Micro-Soft Basic became the defacto ‘standard’ for microcomputer Basic for years to come. It was also one of the most pirated pieces of software.

Micro-soft, later changed to Microsoft, continually enhanced the language, adding low-res, monochrome graphics statements, then hi-res color, disk file handling and more. In 1991, the company introduced Visual Basic, a Windows based development environment. For the first time, Windows applications could be developed, quickly and without having to know ‘C’ or how the innards of Windows worked. It enabled companies, large and small, to embrace Windows without having spend lots of money developing or purchasing specialty applications. The company also continued to develop its DOS versions with the Professional Development System and a DOS version of Visual Basic called Visual Basic for DOS or VBDOS for short. I, personally, developed several applications with VBDOS and it was, by far, my favorite text based version other than NI/BL, a variation of Tiny Basic for the National Semiconductor SC/MP in the ‘70s.

Microsoft held VB in such high regard, that it became the built in scripting language of its Office Suite, a second scripting language in its browsers, and for Windows itself. VBScript, while it no longer is being developed by the company, is a highly versatile language and is under appreciated.

No discussion of programming languages would be complete without talking about C.

C was developed between 1969 and 1973 by Dennis Ritchie at Bell Labs. C is probably the most widely used language. It is used to develop everything from games to operating systems (such as Unix and Windows.) While it generally is considered a high level language, C more closely resembles cross between BASIC and Assembler. It requires knowledge of how the CPU works, things like pointers and other lower level objects than, say a BASIC or even COBOL.  It does, however, generate smaller and more efficient code.

C gained popularity in the 1980’s but it, too, had ‘Tiny’’ versions, but they did not catch on quite like Tiny Basic did. However, it did spawn a more powerful version called C++. C++ is an object oriented language that did catch on…like wildfire. C++ is a true modern language and was the inspiration for other modern languages like JAVA and C Sharp (C#).

Gone are the days of punch cards, magnetic tape and printouts. With our graphical development environments, mice, touch screens and languages like C Sharp, VB and web development technologies, programming has definitely come a long way. And, that shortage of programmers? Gone.

I must say, those days in the 1970’s and 80’s, and the underpowered computers, were a blast. For geeks like me, Tiny Basic was a godsend. I was able to learn something that, later, would provide a career. I got to experience, first hand, the birth of the modern computer era. I can remember, eagerly, getting a computer magazine and tediously entering BASIC code and then having to ‘fix’ it to work with my particular flavor of BASIC. But, I did. I got just about everything I entered to work. Yeah, I missed things like Prom and high school football, but I would not trade it for anything. I think the way I felt was pretty close to those early pioneers in the early ‘50s.  Amazing, that sums it up.