Difference between revisions of "Project:Nanode/Tiny Basic"

From London Hackspace Wiki
Jump to navigation Jump to search
(Created page with "==Tiny Basic running on Nanode== This is something I have wanted to do for some time - run an interpreted Tiny Basic on the Nanode - so that newcomers can program it quickly and...")
 
Line 1: Line 1:
 
==Tiny Basic running on Nanode==
 
==Tiny Basic running on Nanode==
 +
 +
We are all familiar with the process of editing code for the Arduino or Nanode, recompiling the code and then uploading the new hex code image up to the target board. Whilst this might be the way most applications for embedded microntrollers are developed these days - there is another way - and for some people it might just be what they need to get started.
 +
 +
Tiny Basic is an interpreted language which runs on most microcontrollers.  It needs few resources apart from a serial terminal interface and is an ideal alternative language for the Arduino or Nanode.
 +
 +
The simplest of programs can be entered from a serial terminal window - and can be executed immediately using the RUN command - for example:
 +
 +
10 PRINT "London Hackspace is fab!"
 +
20 GOTO 10
 +
 +
Most programmers aged 30 or over were introduced to programming with a similar first program - it is the "Hello World" of  BASIC programming.  30 years ago - almost every home computer you could buy had some sort of Basic interpreter running in the background. 
 +
 +
[http://en.wikipedia.org/wiki/Tiny_BASIC Tiny Basic] hails from 1976, when members of the Homebrew Computer Club of Menlo Park - in Northern California's Silicon Valley were looking around for a simple and compact interpreted language that would run on their homemade Altair 8800 machines - and did not want to pay the young entrepreneur William Gates $150 for his version of 8080 Basic. So a challenge went out to the members to write their own - and several did, the most notable was Tom Pittman.
 +
 +
http://www.ittybittycomputers.com/IttyBitty/TinyBasic/index.htm .
 +
 +
Tom's original code has been adapted for many different platforms over the years - some written in native assembly language and some ported to C - so that it might be platform independent.
  
 
This is something I have wanted to do for some time - run an interpreted Tiny Basic on the Nanode - so that newcomers can program it quickly and easily.
 
This is something I have wanted to do for some time - run an interpreted Tiny Basic on the Nanode - so that newcomers can program it quickly and easily.
Line 11: Line 28:
 
The first task was to find a program which can be used like an operating system - in order to tie all the various hardware functions and libraries together.
 
The first task was to find a program which can be used like an operating system - in order to tie all the various hardware functions and libraries together.
  
Tiny Basic hails from 1976, when the Homebrew Computer Club of Menlo Park - in Silicon Valley were looking around for a simple and compact interpreted language that would run on their homemade Altair 8800 machines - and did not want to pay the young entrepreneur William Gates $150 for his version of basic. So a challenge went out to the members to write their own - and several did, the most notable was Tom Pittman.
 
 
http://www.ittybittycomputers.com/IttyBitty/TinyBasic/index.htm .
 
  
Tom's original code has been adapted for many different platforms over the years - some written in native assembly language and some ported to C - so that it might be platform independent.
 
  
 
I recently was made aware of an assembly language version that compiled on an AVR (eg ATmega328) into under 4K - but modifying this code was going to be a little to intense for most people - so I was delighted to see that Mike Field had taken the generic C version and updated it so that it can run on an Arduino - or Nanode - without modification. Mike's working port of Tiny Basic - written in C, compiles into just under 7.8K on a standard Arduino. If you crank the baudrate up to 115200 - it is surprisingly quick at executing.
 
I recently was made aware of an assembly language version that compiled on an AVR (eg ATmega328) into under 4K - but modifying this code was going to be a little to intense for most people - so I was delighted to see that Mike Field had taken the generic C version and updated it so that it can run on an Arduino - or Nanode - without modification. Mike's working port of Tiny Basic - written in C, compiles into just under 7.8K on a standard Arduino. If you crank the baudrate up to 115200 - it is surprisingly quick at executing.

Revision as of 16:15, 26 December 2011

Tiny Basic running on Nanode

We are all familiar with the process of editing code for the Arduino or Nanode, recompiling the code and then uploading the new hex code image up to the target board. Whilst this might be the way most applications for embedded microntrollers are developed these days - there is another way - and for some people it might just be what they need to get started.

Tiny Basic is an interpreted language which runs on most microcontrollers. It needs few resources apart from a serial terminal interface and is an ideal alternative language for the Arduino or Nanode.

The simplest of programs can be entered from a serial terminal window - and can be executed immediately using the RUN command - for example:

10 PRINT "London Hackspace is fab!" 20 GOTO 10

Most programmers aged 30 or over were introduced to programming with a similar first program - it is the "Hello World" of BASIC programming. 30 years ago - almost every home computer you could buy had some sort of Basic interpreter running in the background.

Tiny Basic hails from 1976, when members of the Homebrew Computer Club of Menlo Park - in Northern California's Silicon Valley were looking around for a simple and compact interpreted language that would run on their homemade Altair 8800 machines - and did not want to pay the young entrepreneur William Gates $150 for his version of 8080 Basic. So a challenge went out to the members to write their own - and several did, the most notable was Tom Pittman.

http://www.ittybittycomputers.com/IttyBitty/TinyBasic/index.htm .

Tom's original code has been adapted for many different platforms over the years - some written in native assembly language and some ported to C - so that it might be platform independent.

This is something I have wanted to do for some time - run an interpreted Tiny Basic on the Nanode - so that newcomers can program it quickly and easily.

This would make Nanode a lot more accessible to novice programmers - and could have an important role to play in helping to teach kids the basics of programming and computer science - just like we learned 30 years ago - on simple 8 bit machines running basic.

A Nanode as a web connected platform sells for just £25, or fully built, tested and expanded to include micro SD card, Realtime Clock and wireless transceiver for just £40. (That happens to be what I paid for a ZX81 kit in 1983).

The latest Nanode really is evolving into a small computer system, with it's 32K SRAM and the micro SD card. There should be the means to run programs out of these memory devices, and use the SD card like a hard disk for file storage and retrieval - and tasks such as datalogging.

The first task was to find a program which can be used like an operating system - in order to tie all the various hardware functions and libraries together.


I recently was made aware of an assembly language version that compiled on an AVR (eg ATmega328) into under 4K - but modifying this code was going to be a little to intense for most people - so I was delighted to see that Mike Field had taken the generic C version and updated it so that it can run on an Arduino - or Nanode - without modification. Mike's working port of Tiny Basic - written in C, compiles into just under 7.8K on a standard Arduino. If you crank the baudrate up to 115200 - it is surprisingly quick at executing.

http://ec2-122-248-210-243.ap-southeast-1.compute.amazonaws.com/mediawiki/index.php/Arduino_Basic

As it's written in C, and uses simple tables of tokens or keywords, it is easily extendable to write new keywords and functions which exercise the Nanode hardware. Additionally there is plenty program space left - about 22K, into which the various library functions for ethernet, SD card, RTC, MAC and SRAM may be added.

Whilst it currently executes code from internal RAM, this could probably be redirected to the external 32K SRAM - into which we can TFTP a simple basic program listing - or access the SD card - which we can use as a local repository or "juke box" of our favourite sketches.

Extending this Tiny Basic and including the common Arduino libraries to form an Nanode operating system (NanOS ?)will be an interesting but achievable task.

The Tiny Basic plus all the nex=cessary hardware libraries fit into just 13K of program space leaving 17K for language extensions and application code. The breakthrough will be to get the SRAM and the SD working as a program application memory and solid state disk.

With the Tiny Basic is a means to list the program, so that lines of code can easily be edited with a terminal program. - or probably a whole file loaded using a file transfer program such as Hyperterminal or whatever.

A simple text editor could also be used to edit and manipulate html text, stored on SD or SRAM - so that web pages could be locally edited and then displayed on a browser.

The Tiny Basic is certainly fast enough to be usable, especially with the baudrate at 57600 - I did 10,000 iteration loops of

10 For A = 0 to 9999 20 Print "My Name is Joe" 30 Next A

In just 30 seconds - anyone who remembers the early 1980s machines like the Spectrum will appreciate this is several times quicker.

It should be straight forward to get the Nanode (Arduino) I/O pins accessible from basic keywords - perhaps something like defining each pin as a keyword to set Digital 4 High. As there are only 20 I/O pins on a ATmega - it's not going to take much program space to code them up. eg

10 Let D4 = 1 // Set Dig 4 High 20 Let A = AN1 // Get input from Analogue 1