BASIC programming on an Arduino

[Mike] sent in a project he’s been working on – a port of a BASIC interpreter that fits on an Arduino. The code is meant to be a faithful port of Tiny BASIC for the 68000, and true to Tiny BASIC form, it fits in the very limited RAM of the Arduino.

True to Tiny BASIC’s assembler roots, [Mike]’s C port makes extensive use of the “infinitely-abusable” goto statement. Kernighan and Ritchie said themselves, “code involving a goto can alway be written without one” but [Mike] found that using goto left a lot more room available for BASIC code. The BASIC interpreter eats up around 600 bytes in the Arduino RAM, leaving about 1.4 kB for BASIC code. Not much, but more than the lowest-end BASIC Stamp.

[Mike] says he started this project to see how ‘old bearded ones’ conjured up so many impressive programs with a few kB of RAM. Tiny BASIC was originally conceived for the Altair 8800 that shipped with 256 bytes of RAM stock, so it seemed like a perfect fit. Right now, all we know is we’ll be spending the weekend digging through our copies of Dr. Dobb’s Journal.

77 thoughts on “BASIC programming on an Arduino

  1. Nice effort, but I doubt it would be useful for anything semi-serious. The interpreter probably adds a very significant overhead mostly in CPU cycles, but also quite a lot in precious RAM and ROM space. It may leave 1.4KB of free ROM space, but “>30 T=T+A” takes 10 bytes of code space (11 if you use CR+LF), while the instructions would take half or less, depending on the context. It gets worse when you use proper variable names.

    Writing or porting a basic interpreter isn’t exactly easy, so it probably was a good exercise for the author, and hobby coding doesn’t have to be productive to be fun.

    1. Sure, it is hard to program anything useful with the remaining 1.4KB, but it would also be fairly trivial to add an external ram chip and have an instant MB or more to code away with.

      Most projects of this type are pretty worthless in actual utility, but as you said yourself, that is rarely the point.

    2. I don’t know how this implementation of Basic works but I am pretty sure that my first computer stored some opcodes instead of the textual representation of the code. That way it may consume less memory.

      I think that because it always listed the program pre-formatted not the way I wrote in.

    3. In a typical 8-bit interpreted BASIC from the day, the line number and initial space would be stored as a single 16-bit unsigned integer, so your example line would be 7 bytes. The variables would typically not be stored in registers on an 8-bit CPU (registers are precious, after all). And remember these are 16-bit variables, not 8.

      So let’s compare this with the equivalent native code for a 6502. To make the comparison fair, we’ll assume that the assembler programmer is clever enough that they’ve managed to store both variables in the zero page to avoid complex addressing, and that the carry bit is already clear.

      It would be something like this. Note that I’ve probably mis-remembered the syntax.

      LDA $T
      ADC $A
      STA $T
      LDA $T+1
      ADC $A+1
      STA $T+1

      I make it 12 bytes. Z80 would be a little shorter because it has more registers and can use double-byte instructions. I never used Z80 back in the day, but I would imagine something like this:

      LD HL,($T)
      LD BC,($A)
      ADD HL,BC
      LD ($T),HL

      That’s 10 bytes.

      1. A basic compiler for avr chips was written many years ago and works great if someone would fix it where it would port directly to the ard kits. As it is you can still write your program in basic and send to the atmel chip isp. It is called Bascom avr. If you can find a copy I could zip it up for you as I bought it many years ago. It still runs under windows 7, xp or 98.

    4. Even if the BASIC interpreter isn’t very useful in some ways, as an example of interpreter implementation it is a good first step for the budding language implementer. :-)

      Forth would make an excellent alternative for the Arduino.

  2. Neat idea! Questions/comments:

    1. What are you using for the input and output devices? Serial port to the PC?

    2. PEEK and POKE access memory, which on the 68000 meant access to everything (there were no I/O ports). Wouldn’t you want something equivalent to access the Arduino’s I/O ports?

    3. LOAD/SAVE seem like a good way to save a BASIC program, so it can run immediately the next time you power-up. Would allow a program to run without requiring any user inputs.

    1. 1. Input output is the serial port… should wire up an old vt100 terminal :-). I’ve also got a fresh unopened Freetronics EtherTen… maybe I should set it up to use port 23 as STDIN/STDOUT..

      2. As already mentioned PEEK and POKE could be used to access I/O ports, but I think that adding your own statement / function would be the way to go, to hide the internals of the Arduino from the user.

      3. Load & Save would be good, but usually EEPROM is a than RAM, so you can’t hold a large program in there. No reason why you couldn’t hold it on micro SD card…

    1. 600b RAM! Sorry, but that’s not impressive at all. And that’s 512b ram for the stupid arduino serial library, so it only uses about 100b of ram. Which is nice.

      It’s using a lot more flash. But the AVR chips used in arduino’s have a silly large amount of flash already (32Kb) I normally use ATMega8 chips, which only have 8kb of flash and 1kb ram. Which is more then enough in most cases, if you don’t use the arduino libraries.

      Also, AVR instructions are 2 bytes in size, so if you use 1k flash you have only 512 instructions. Getting anything down to less then 1k flash is quite impressive.

  3. the BASIC programming language is a step backwards. It encourages bad design and bad programming.

    it’s a bad idea. really really bad idea.

    Duino programming in C is brain dead easy. Let’s stick with that.

    1. Although you are right and there isn’t much to really like about basic, I think this falls in the “because you can” category.

      Nobody would never consider this as a solution for anything.

      It’s like running Linux on a hamster or FreeBSD on a stone chopper tool. Useless but… entertaining ?

    2. You guys kill me. I’ve programmed in Pascal, Fortran, Assembly, BASIC, and C++. BASIC was always my favorite language because it was easy, and could handle strings and math easily. Of course, computer science majors and professors hated it because “it wasn’t a structured language.” Big deal. What they really meant was that it was too easy to learn and apply, and threatened their status. There’s not much money in languages that are easy to learn, understand, and use. What I could do in two hours in Compiled BASIC, would take weeks in other languages. Give me a break.

        1. +1 from me too.. I program in a whole bunch of languages, but I tend to reach for the available tools to fix the problem, and that tends to include such much maligned things as BASIC, Bash scripts, VisualBasic on Windoze platforms, PHP and all the other Marmites of the programming world. If the project is written on jacquard loom cards and interpreted on a grandfather clock, it shouldn’t matter. What matters is that it does the job well, and is relatively easy to debug, and that in turn demands that the code be easy to follow. 10 print “Hello”; : goto 10… not much difficulty there…. 10 print chr$(205.5+rnd(1)); : goto 10 … well same thing really :¬)

  4. Thats not far off from the vic20 I learned on. Basic opened the world of programming to me. Better still, having so few resources taught/forced me to be clever.

    It still pays off today.

    Nice work!

  5. People just don’t get it… this is GREAT. We live in a poor country in a poor area so computers are very expensive. Now, imagine making a simple cheap board that would allow users to input things using a cheap keyboard + cheap 3″ mini-monitor. Yes, it sucks, but for people who doesn’t even own a computer, this would be great. ;-)

    1. The arduino platform is not the solution to the problem you are stating.
      You can find other dev-boards that could fill this gap several of which have been discusses on HaD.

      A more sensible solution would be refurnishing old office computers and bundling them with Linux. Second hand PC’s are dirt cheap.

      1. I know that most of you guys are “Top Cats” or whatever you call Hot Shots around here. ;-) But still, I learned BASIC and also LOGO when I was a kid, I’m 36 now and program in Assembly and C++ for a small-medium online company, and recently got into the Arduino world. ( I don’t agree with anything you guys say here, Basic is a great starting point, even if Goto is bad for you, its still a great learning tool. And no, we don’t have surplus or cheap old computers here to use, and it would be messy.

        Now, imagine a simple Arduino compatible board that has an ATmega8 chip, 32Kbyte external EEPROM, 4×20 LCD display and keyboard input. That’s easy to manage and super simple to handle. Now, if this board could also attach to a simple robotic chassis like the QMini from DFDrobot… :-)

        In any event, I see a lot of Basic-Bashing, a lot of “there are better ways to do things” but still, this is a great solution for a lot of people, even if you don’t like. ;-)

        1. I started out with P2000T, ZX spectrum and MSX so I stared out with basic just like you. But fondness of childhood memories does not mean that basic has a place in modern computing. It’s fun for the odd hack or a drive down memory lane, But that is as far as it goes. It is obsolete and not an education tool.

          There is a reason why education tools get rewritten every so often. That is because unlearning concepts now considered old is hard. Not that it can’t be done, but it is a waste of effort.

          So “Basic build bad programmers” maybe an over generalisation, but it still has a lot of truth to it. It is at least unnecessary.

          Logic can be taught within a OOP paradigm just as easily without having to introduce ancient limitations, behaviours and methods.

          There is also no reason to think that just because people are poor and can’t spend a lot on new big iron, they also need to be stuck with ancient software. You can do plenty of C or java (or whatever) on an old pentium II with modern software.

          The Arduino platform already is a cheap way of learning embedded dev. It already is a product for this audience. They gain nothing from basic, on any platform.

    2. As a real world solution I’d be more inclined towards the Raspberry Pi, or ideally just refurbishing older computers.

      Not to say that this is a bad idea – I’m trying to run composite video and PS/2 keyboard input concurrently on an Arduino to do something like this (granted, with some problems with interrupts), hoping that I can use it as a dumb terminal – or have it run CHIP 8 games :-P

  6. Some things have been lost in translation… :-)

    It seems that the standard libraries (and the stack space it needs to work) for an Arduino project requires about 550bytes of RAM, I use 7 more for the interpreter, everything else is free for your BASIC code.

    The sketch itself is 6,516 bytes, and an nearly empty sketch that echos characters on the serial port takes 1,662 bytes – so BASIC take 4,854 bytes. On a ATmega168 you have another 7K or so for implementing your own statements or functions

    I’ve adapted mine to work on my Pololu 3pi robot – a function to read the sensors and a few keywords to drive the motors and sleep a while.

    And as everybody says, it’s not much use for anything,…

    1. You can decrease RAM usage by switching your strings and lookup tables to use program memory. When you declare a string constant it is copied to RAM at startup time, although it doesn’t need to be. Program memory strings are declared with PSTR() and accessed with the appropriate routines with the _P suffix e.g. printf_P().

  7. One of the ways that þe olde schoole BASIC interpreters saved memory was by heavy tokenization of keywords and singly-linked lists for individual lines. For comparison’s sake: the Sinclair ZX80 had a 4KB ROM, although I don’t know how much of that was devoted to BASIC, and how much to graphics and whatnot.

  8. I guess with an external EEPROM chip it could load/save without much fuzz, or even a SD card.

    But I was wondering on a different approach, on having the whole program run from a SD card. I know, it would be slow, much slower, but still functional to teach kids things, specially on places that you can’t get your hands on computers.

    I guess I will use this as a starting point for my own version. ;-)

  9. Oh, where I think it might have a little value is in a classroom type environment. I wouldn’t be surprised if a room full of students could ‘brick’ Arduinos at an astonishing rate, esp if using an ISP cable rather than a bootloader.

    A knowledgeable tutor could extend the language a little for their environment (like I did on my 3pi) and upload it to the board. Then students would be able to just plug in the Serial or USB cable, open a terminal window and hack away.

    As the student’s code is in RAM, Just switch off they are ready for the next student…

  10. Don’t sell BASIC short. You really *can* teach it to kids and beginners in an hour or so (I’ve done it)! Such users often don’t have the logical thinking abilities needed to master more sophisticated languages.

    And, there are lots of problems so simple that BASIC is a perfectly reasonable “tool” for solving them.

    Ya gotta learn to crawl before you can walk. And walk before you can run.

    1. You could do that with any form of written algorithmic logic. Basic is fundamentally flawed especially for learning. Unlearning bad practice is much harder to do then learning it proper the first time.

      If you teach newbies to think with “goto”, that mechanism will remain with them for a long time and will inherently taint their thinking about logic. Basic underpinnings in coding skills are a handicap, not a springboard.

      Begin with pseudo-code and flowcharts, forget the computer first. Secondly introduce them to an environment that actually represents the computer they are supposed to program.

      1. Traditional flowcharts are the most “goto inducing” design method there is, and I have yet to see (common) CPU that doesn’t have a ‘goto’ or “jump” in it’s instruction set – even the humble “while” loop is actually hiding the real computer from you.

        I guess the point of it for me is that there is 1,200 lines of hopefully the worst C you will ever see, that builds to 2,030 machine instructions and it implements something approaching a program editor and a programming language.

        Sure, TinyBASIC is a crap language, but maybe it somebody will go “heck! I need some sort of scripting for my gardening watering system so I can update it using a wireless terminal connection from my Android phone”

        Welcome to TinyBasic for my Garden, 400 bytes free
        >10 REM My watering system
        >15 SLEEP 60
        >20 IF TEMP() 30 IF RAINING() = 1 GOTO 10
        >40 IF HOUR() = 17 SPRINKLER 1 ON
        >50 IF HOUR() 17 SPRINKLER 1 OFF
        >60 IF HOUR() = 18 SPRINKLER 2 ON
        >70 IF HOUR() 18 SPRINKLER 2 OFF
        >80 IF HOUR() = 18 SPRINKLER 3 ON
        >90 IF HOUR() 18 SPRINKLER 3 OFF
        >SETTIME 2011 08 29 15 00

        Don’t you agree that would be an enjoyable hack, and maybe 400 bytes of RAM is enough for a useful program?

        1. You are right about flowcharts traditionally doing “goto” like jumps, but the point I was trying to make was that learning elementary logic is better done away from the computer and especially away from basic/bad languages.

          Of course on a CPU level almost every invocation of a method calls for a “jump”. This does not mean implementing a “goto” statement in high level language is a good idea. Goto by far isn’t the only reason to shun basic for learning coding.

          But goto in functions and loops !.. *Brrrrrr*

          I can easily pick out function by people who still think a bit “basic”. Usually found after a nice memory-leak or heavy performance loss.

          Of course, messing around with good old basic still is fun. In another post I defended this hack for being a proper case of “Because you can”. Which I am all for.
          Not all that long ago I still enjoyed GWbasic and even Qbasic trying to make it do stuff it normally couldn’t.

          1. Just about every program language has implied “goto” in terms of following a sequence of steps.
            That is, perform step 1 and then “goto” step 2 and perform that, then “goto” step 3 and perform that.
            Repeat-Until, Do-While, For-Next, these are all implied “goto” loops.
            Machine code 6502 is based on JMP and JSR, it’s based on the CPU following a simple sequence of instructions.
            Ever since day 1 people have had some kind of arrogant attitude about Basic. I was certainly glad that Microsoft embraced it with their VB and VBA platforms.

  11. For reference: Tom Pittman wrote Tiny BASICs for the 6800, 6502, and 1802 micros. They were all about 2k bytes *total* for the interpreter and its console input and output routines, and needed about 256 bytes minimum of RAM to run.

    I would hope that if Tiny BASIC were written in assembler instead of C, it should be of similar size.

    1. The reason I started on this was because I was in awe of the original code, and wanted to truly understand it.

      It does lots of cunning things like changing the return address on the stack allowing function parameters into the ROM, and storing GOSUB and FOR/NEXT frames directly in the stack. A whole lot of stuff that you can’t do in C.

      The slightly disappointing thing is the size of the standard libraries used by Arduino. All I use is Serial.begin(), Serial.available() Serial.Read() and Serial.Write() and 1,600 bytes of Flash and few hundred of RAM are gone.

      When getchar()/putchar() is used in AVR Studio I get “Program: 5218 bytes, Data: 186 bytes”, (exclude the space in ‘Data’ reserved for holding the BASIC program.

    2. It would most probably be bigger, maybe 4K, as the ATmega opcodes are either 16 or 32 bits, where early 8 bits CPUs had quite a few 8 bit opcodes – so my 6516 bytes is at most 3258 instructions,

      Phew! I don’t feel so bad now :-)

  12. Long live Basic. Clearly understandable keywords, no semicolons at the end of lines, no megabytes needed for compiler, excellent for first-time users. Great project.

    (my 2 cents)
    As for the C folks, you are aware of the fact that your “beautiful” C code gets converted into a bunch of machine code jumps (GOTOs), near and far? And try getting out of double or triple loop in C without using GOTO. Fun times… And memory leaks, and lack of hardware I/O statements … it is a nightmare compared to any Basic.
    (/my 2 cents)

    It is not my intention to start a flamewar, but there is nothing wrong with Basic. Most often, problem is between the chair and the computer, not in the language used. Enjoy your day.

    1. The language paradigm that is basic is not a solution for the problems you listed, but possibly part of the cause.

      Your odd comparison of jump instruction in machine code and a high-level goto statement show this. it is “Basic” thinking. Basic does not equate at all to newer language paradigms and lower level languages, only somebody stuck in basic world would think that (yes also VB, which is horror incarnate).

      C can be a pain because it’s powerful. Basic lacks some of these pains because it is limited on top of obsolete and flawed. That is not a solution.

      It had it’s purpose… in the 80’s. Now move on.

      1. I’m not defending VB, although it is better than Visual C. People nowadays have no easy way to work close to “the metal”, like they did in the 80’s when machine language, assembly and BASIC programs could be found in any magazine. And working on the metal is the real way to learn, not on top of 5-th abstraction level.

        For initial learning, it is better to use plain English keywords than ({,},;,!=,&&,||,++) monstrosities. I suspect Arduino would have more followers with Basic compiler on PC side, than with current stuff.

        Modern OS’s treat users as morons who cannot execute hardware I/O. Lack of hardware access, and overall slowness of the systems is appalling.

        Just recently HaD had a project where a guy made a computer out of TTL chips (in MHz) and it worked faster than Win/Lin (in GHz) command line. Some questions raises this (Yoda).

        1. Comparing VB and VC is like asking which is better, Dysentery or Cholera.

          In learning reading, writing and speaking it is equally counter productive with starting with the syntax and grammar used a few centuries ago. Although studies in these fields exist that require you to know old , they are not meant for current day usages. Words, structures, concepts and such are missing or radically different.

          I agree that starting with a higher level language is the best place to start, but I also think that real world applications and examples are equally important.

          Basic is a programming language equivalent of cuneiform and not suitable for teaching coding in 2011.

      2. Oh dear lord. This is a great ‘hack’. I have adapted the code to the XGS PIC gamestation. Working, but have a couple of issues to fix.

        As for BASIC, it’s a great tool. I’ve made a living for the last 20 plus years coding in VB DOS, VB, and LotusScript for Lotus Notes. I also write code in C, C# and a host of other tools but always find that I can do anything in VB or even VBScript that I need. And Tiny Basic is a great teaching tool. This whole argument about Basic not being proper is elitist. It’s like comparing a BMW to a Chevy.

        And modern VB is just as good for teach as C. “Basic is a programming language equivalent of cuneiform and not suitable for teaching coding in 2011” Huh. You obviously have not seen

        1. I think the problem when people try and create “advanced” versions of BASIC, is that they end up implementing a crippled C. Maybe because that’s the mindset of the programmers, and modern BASIC interpreters / compilers are written in C.

          BASIC was written without the idea of doubles, ints (you just have numbers, and strings), structures, and parameter passing in mind. In BASIC, all variables are global. It’s meant to be a simple language to get the basic ideas of programming across to beginners, get them acquainted with variables, program flow, etc.

          So when people try to advance it, they end up in no-mans-land. Adding functions to make it powerful or more systematic end up having to re-code the wheel. You’re in a place BASIC was never imagined for, so everybody implements it ad-hoc in the way that fits their own ideas.

          You can’t say that about C. If you know C on one machine, you can write it on any machine and 90% of the code will be the same. Well, if it’s a Von Neumann machine at least. Some of the Harvard arch chips need a few tweaks and considerations.

          BASIC is great to learn from, because it’s simple, gives quick results, and is pretty crashproof. C is powerful, logical, and systematic. You can’t have both! Adding the power throws away the simplicity. If you must, use Pascal. That’s about as close to a C that looks like BASIC as you could hope for.

      3. Well, sure there have been evolvement in programming languages.But sometimes you need a quick’n’dirty solution and you do not want to think about compiler setting and other stuff.Nor do you want to reuse all and everything. Remember serial interface on old simple basic line line of open statement an a couple lines of code to have a simpel tool to test devices etc. Done. Now on the modern programming languages if supported at all its NOT fun. Also, the old computers were limited and forced people to program efficiently.E.g. a game like Elite in 88kb… those kinds of programmers are rare. To slow? Get a faster processor.To big? Get more memory. That is the modern spirit.And that’s way more bad than using a goto once in a while ;)

  13. Sometimes, “Because you can” is reason enough. Sure it’s easy to be sloppy in BASIC, but you can build bad habits in any language. Look at it from the other side, if your BASIC is bullet-proof, then perhaps you can be trusted to use another less forgiving language.

    True, I don’t know anyone who wrote “mission critical” applications in BASIC, but then how many times did an Arduino go up space? Probably zero.

    I would however trust an Arduino to run a sprinkler system, perhaps the single traffic-light in a small town. But I wouldn’t bet my life on either BASIC or an Arduino.

    All tools have a “Best Use” and “Also can be used for” uses, even a rock can be used as a paperweight.

    1. Actually, Arduino’s have been to space apparently.

      The problem with bad habits is that, in basic, you never realize that they are actually bad.

      In several posts I have declared this hack amazing in the “because you can” category. Whilst this is true, I find the idea of reusing basic as an educational tool revolting and insane. That is a clear case of “because we can’t”.

      I started out with basic as well, But I got better.

      1. >>”Basic is a programming language equivalent of cuneiform and not suitable for teaching coding in 2011. – retepvosnul”<<

        He, he … You mixed up this ( with Basic. Basic is great, and not only for introductory computing. You shouldn't thumb your nose at it only because it is called Basic, and not Python or Perl or C or whatever. Structured Basic's with compilers exist since the 80's.

        "In the hands of Vuk Mandusic, every rifle is deadly".

        @retepvosnul: I'm still waiting for your "break out of triple loop in C" code. No GOTOs allowed. If you have time of course. :)

        1. I don’t shrug my noise at it because it is called basic. I don’t even do that because it is basic. What I do find highly destructing is anybody considering it useful for any real world application.

          As far for the rest of your scruffy remark, I’m not even going to grace that with any form of retort apart from your crazy concept of needing to break out several nested loops. Don’t get into them in the first place. This even is true for basic itself. You are one loopy person.

      2. I disagree. There are plenty of times when you absolutely must have nested loops. Examples are given in (shock, horror) C programming books themselves.

        You can also look it up in any complex C program.

        Break statements are one answer, but then you are just replacing your single BASIC/assembly goto/jump with several jumps (one for each break) once your C code gets compiled. Not an improvement at all.

        Structured Basic would have the same problem, but not earlier types with GOTOs everywhere.

  14. wow, who would have thought? basic ON an arduino, not “TO” an ard. but ON.

    no installation of software, no dependencies, no port95nt, no adminrights, JUST PROGRAMMING!

    … this will allow you to do manual commands without erasing/wearing-out your flash every 10 seconds… ie you dont hav to write a program, just to debug your electrical connections/circuits!

    PS: here is SOME missing code from the .pde IF your using it in Arduino enviornment AND your a noob at programming in general:

    ***** code clips start *****


    #define KW_DELAY 18
    #define KW_OUT 19
    #define KW_IODIR 20

    case KW_DELAY:
    goto mydelay;
    case KW_OUT:
    goto out;
    case KW_IODIR:
    goto iodir;

    short int value;
    short int udv;
    unsigned char *address;
    // Now get the value to assign
    expression_error = 0;
    value = expression();
    goto invalidexpr;
    udv = value;
    // check for a comma
    if (*txtpos != ‘,’)
    goto syntaxerror;
    // Work out where to put it
    expression_error = 0;
    value = expression();
    goto invalidexpr;
    address = (unsigned char *)value;
    // printf(“Poke %p value %i\n”,address, (unsigned char)value);
    if (value == 0)
    delay(udv * 1000);
    if (value == 1)
    if (value == 2)
    // Check that we are at the end of the statement
    goto syntaxerror;
    goto run_next_statement;
    short int value;
    short int udv;
    //unsigned char *address;
    // Now get the value to assign
    expression_error = 0;
    value = expression();
    goto invalidexpr;
    udv = value;
    // check for a comma
    if (*txtpos != ‘,’)
    goto syntaxerror;
    // Work out where to put it
    expression_error = 0;
    value = expression();
    goto invalidexpr;
    //address = (unsigned char *)value;
    // printf(“Poke %p value %i\n”,address, (unsigned char)value);
    if (value == 10)
    delay(udv * 1000);
    if (value == 1)
    if (value > 1)
    goto syntaxerror;
    if (udv 1)
    goto syntaxerror;
    if (udv < 2)
    goto invalidexpr;
    pinMode(udv, value);
    // Check that we are at the end of the statement
    goto syntaxerror;
    goto run_next_statement;

    ***** code clips end *****

    PPS: i will still be using my arduino and bare AVRs as usual, its just useful for testing transistor or display ect

    PPPS: i hav yet to do a simple INP statement but similar to OUT

      1. This is an experimental project aimed to learn how to implement an Interpreter for AVR Atmega microprocessors.

        BASIC was choosen because of ease implementation and learning.

        It is based on Micro-Basic from Dave Dunfield:
        * Copyright 1982-2000 Dave Dunfield
        * All rights reserved.
        * Permission granted for personal (non-commercial) use only.

        MICRO-C code has been ported to WinAVR and it still an alpha version. Primary target would be Atmega16/32/64/128. Tested on Atmega128 OLIMEX board.

        Currently the BASIC source code must be typed on a VT100 Terminal program via serial (RS232) connection. So it is not possible to save the code, only interpret and run.

        Current Status:
        – Not all functions are implemented or tested.
        – Most functions that relates to file operation won’t work for obvious reasons.
        – Functions to access PORTS, PINS and DDR are not fully implemented.

        Future plans:
        – implement i2c routines to save BASIC code on external serial eeprom
        – implement I/O functions to access PORTS, PINS and DDRS
        – implement ADC functions
        – implement Timers functions
        – implement Interrupt functions

        – Atmega16/32/64/128 with RS232 port. This version was tested with OLIMEX MT-128 board. Should work on other 16/32/64 boards.
        – Using UART1 for serial connection.
        – PC terminal with local ECHO enabled.
        – Free RS232 port 9600/8/N/1
        – WinAVR 3.4.6 and Procyon AVRlib Version 20051006

        How to build:
        – Unzip the file to a folder
        – Edit the Makefile for the appropiate AtmegaXXX
        – From command prompt type: “make”
        – If ok generates .HEX .COF and other files

        Archive contents:
        – BASIC.COM = compiled PC BASIC interpreter
        – BASIC.C = original Mikro-C source code
        – MBASIC.C = AVR source code
        – MBASIC.HEX = compiled source code for ATMEGA128
        – README.TXT = this file
        – BLKJACK.BAS = example does work
        – HILOW.BAS = example works ok
        – global.h = global definitions
        – Makefile = Makefile
        – RENUMBER.C = RENUMBER source code
        – RENUMBER.COM = compiled PC RENUMBER tool

        – Version 0.3a Fixes and updates [50 KB] (Sep 25, 2006):
        – Now while running a script CTRL+C will stop execution
        – New ADCSET and ADCREAD functions not tested but should work
        – New CLS functions to clear screen requires VT100 terminal
        – Fixed bug with functions such as IN(, ADCREAD(, etc
        – Planning to implement SAVE and OPEN functions with simple file system

        – AVR BASIC Interpreter [47.22 KB] (Sep 22, 2006), some fixes:
        – inclusion of PORTG, DDRG, PING
        – inclusion of PINS definition variable
        – updated IN(PINX) function
        – updated OUT and DDRSET functions to reflect PORTG

        – AVR BASIC Interpreter [32.22 KB] (Sep 22, 2006), original post

        Have fun ! And remember that this is still an ALPHA version !

        PS: This is my first WinAVR (AVR-GCC) project. So many things are new for me. Code is actually very lazzy and buggy. I’m still trying to remember/learn how to edit Makefile’s.

  15. I just googled Arduino Basic Interpreter and found this.
    I bought a Sparkfun HUGE LCD with serial back pack.
    I already have a keyboard from a Spectrum.

    OK, I also have a few ASUS eee’, but a little ArduinoBook, with a GPS, temperature, humidity, pressure sensors, digital compass, seems afine idea!

  16. I love BASIC and I use it all the time in test and control systems I design for. I find development time is 1/3 what it would be on the Arduino (for a quick and dirty solution). Not to say that I do not love the Arduino and C.

    BASIC is a clear language that had highly readable code. Other engineers can easily follow it and make additions. It lacks the walled mentality that other languages have and most,if not all, of the innovators of the last 30 years learned to ‘gram on it.

    Fact of the matter is that many people who deride BASIC have no clue what options exist today and what people are doing with it. It may not be making a comeback but it is certainly not dead.

    Take a look at Thinbasic for example.

  17. I just ordered an arduino 2560 please do BASIC for it. I love BASIC back in the DOS days I used to use ASIC to compile DOS programs. It was writen in x86 assembler its still about a quick google search will fine it. As well BASIC you could also call interuptes with it. I wrote a full graphic SVGA paint program that was controled by the mouse. ASIC is shareware and as well as compiler it had its own IDE but i preferd to use MS edit. Please do a BASIC with simerlar syntax or clasic syntax like Atari BASIC ie

    10 PRINT “hello world”
    20 GOTO 10

    Propper BASIC is a wonderfull language it used to come as standard on the IBM PC and all their mainframes before the 90s. Many PLC’s use it because like LOGO its perfect for process control. These modern languages are so silly bracket this bracket that in a scrolling mess all over the page.

    1. I had no trouble to getting the Hamster version to work on TI Stellaris launchpad with Energia. I also have a Mega 2560 and the BlueLama’s TinyBASic plus worked for it.
      Eventually got plus partially working on Stellaris too, but had to fix a ton of AVR refs.

      My 2 cents on BASIC is that we need to ditch the evil GOSUB and Strings!
      You can keep FOR/NEXT if willing to store a return address with loop variables.
      NEXT X should know right where to look FOR X, to test if X loop should continue.
      There should be no stack and no strings and no garbage to ever need collecting.
      THEN ELSE GOTO work beautifully for everything.

      Structure is fine, but relies heavily on a self cleaning stack, and any spaghett
      ruins it. Spaghetti can be very elegant too, if you don’t try to maintain a stack.
      It is only the mix of spaghetti and meatballs that goes to hell in a handbasket.

  18. I´ll say go for the BASIC, if there is someone who can´t know where the goto goes that´s their problem, time will tell who wins a dificult language like lua, c, arduino sketch or Basic, arduiino is the first eazy plataform for electronics but is tied-up with a C-like programing, now if we change that to an easy one like Basic it´s going to grow Viral

  19. First of all, BASIC is FUN. If you don’t feel that way, why are you here?

    The Arduino is itself an example of minimalization – a tiny computer on a chip – how cool is that? Let’s see what we can make it do.

    It’s not Windows, or MAC OS. It is what it is. We don’t really want to use it as our primary computer – it’s a HOBBY for most of us, and a throwback to the ’80s – an Apple II, only faster.

    The thing about BASIC was/is how quickly and easily you can get something done. I can have answers while others are still setting up their C++ project files. (Use GOTOs – or don’t, I don’t care).

    The reason for having a BASIC (or any other) interpreter on the Arduino is so that you don’t have to compile a sketch and upload it every time you want to make a change, and you would not always have to be tethered to a PC to get anything done.

    BASIC is still a very useful tool for everyday programming tasks. I wrote my own, called QUICKCALC BASIC, that runs under Windows. It’s free and powerful. Check it out at (Enjoy, but watch out for those evil GOTOs.)

  20. There is an alternative 8-bit BASIC interpreter for the AVR, which supports has full support for the ATmega88, 168, 328, AT90USB1286, ATmega2560, ATmega32U4 and host of other peripherals as “language extensions”, such as DHT22, nRF24L01, 1-wire, I2C, SPI, DDS, PWM, ADC and input capture. There is an unreleased version that supports the ATtiny85 as well. It has pre-compiled HEX files for all those AVR’s at different clock speeds and can be programmed into any ARDUINO that sports those AVR’s using either AVRDUDE or the ARDUINO IDE. The web site is at:

    There are some earlier versions that support the AT90S2313/tiny2313, AT90S8515/mega8515 and the ATmega163 but do not support any language extensions for the peripheral modules.


    Peace and blessings,
    Johnny Quest

    1. Forgot to mention. There is support for the analog comparator, and of course, bit and byte I/O on all versions.

      The earlier AT90S2313/tiny2313, AT90S8515/mega8515 and the ATmega163 versions only support ADC, PWM and bit.byte I/O.

      Peace and Blessings,
      Johnny Quest

    1. Moisés:
      Thank you for those links. No debate intended here, just clarification as to what the differences between AttoBASIC and the other BASICs are..

      All the links provided are BASIC compilers, meaning write your program, compile, upload, test and start again if you find bugs. As with the Arduino and using C/C++, the debug cycle does diminish the FLASH memory’s life. Albeit, 10K erase/write cycles is a lot. The BASIC compilers are *not free*. Although at US$249, the mikrobasic is a good price. From what I saw, ZBASIC gives not pricing on their products, even after one adds a product to the shopping card and begins to “checkout”,

      AttoBASIC on the other hand is an interpreter that is written to FLASH once. The programs are stored in RAM (and saved in EEPROM). AttoBASIC is also *free*.

      Now, there are definitely huge differences between a BASIC compiler and a BASIC interpreter and each has its place. With the compiler versions, like with C/C++, larger programs can be written with more global and local variables available, etc.

      Personally, for me, if I was going to choose a BASIC compiler (with a $$$ cost) then I would simply use the GNU C/C++ that is already available and has user-supported libraries for just about everything at this time.

      Thanks again for the links.

      Peace and blessings,
      Johnny Quest

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s