[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.
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.
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.
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.
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.
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. stx38834@gmail.com
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.
??He fit TinyBASIC in SIX HUNDRED BYTES!!/\!!??
OO
Moby *WOW* \/
From his submission to the tip line, 636 bytes (1,412 bytes free).
Yeah.
No. When compiled in the Arduino IDE the basic interpreter code takes up 6470 bytes in the flash memory space. Then at runtime it takes an additional ~600 bytes in ram.
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.
the IO ports on the avr are also mapped to bytes 0x0 thru 0xff in ram i believe, so poke/peek can be used for io aswell
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…
Longtime basic programmer here – huge wow on the 600b, and this is very cool! By now most of us have moved on for this ever to be publicly useful but very neat indeed.
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.
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.
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 ?
BASIC took us to the moon and back many times where have we been with all your fancy pants programing…right here on earth.
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
I also programmed in Delphi (Visual Pascal as some may call), dBase, Basic, Clipper, Logo, Visual Basic, C++, JavaApplet+Scripts and Assembly. Always loved Basic. ;-)
+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 :¬)
I couldn’t agree with you more! I grew up with BASIC (TRS-80, then Commodore). I actually fundamentally understood EVERYTHING I did in that language. I’ve been languishing since 2015, trying to make ANY semblance of something remotely resembling sense out of C… And still… All i can do is awkwardly tweak existing code examples and HOPE to get the code to change it’s function enough to do what I want.
I simply don’t GET C. I don’t get the how and the why behind most of it’s mysteries, and quite frankly, having been away from trying for over half a year… about all I remember is there were lots of “voids” in both my code AND my understanding.
I’d love a proper, fully featured and documented BASIC compiler for Arduino… I don’t know how _tiny_ TinyBASIC is, but I’m not gonna complain if it’s possibly something that might work for me. I still wanna learn C… But dang it, if it’s just NOT clicking for me!
I am so totally in this SAME CAMP! I was able to get a few sketches working in C++ on my Arduinos, but only with a LOT of help from some good people on the Arduino forums. I would ABSOLUTELY **LOVE** to be able to write code in BASIC on the Arduino! Sigh. I am considering switching to the PICaxe system, which DOES use BASIC. I did some projects with it at a former workplace, and loved it. Time to just “bite the bullet” and buy some PICaxe goodies. :)
Agree with you .
Just started with Arduino so you say to learn c so should I learn c or the arduino language and If c then which c ?
your comment is very neg and yu need to know if it was not for BASIC there would be no pc or arduino today…BASIC is what started the entire computer revolution…
nice, but 1.4k isnt much and for first timers basic stamp is cheaper. more of a novelty but still a cool hack :)
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!
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. ;-)
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.
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. (www.Beat707.com) 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. ;-)
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.
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
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,…
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().
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.
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. ;-)
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…
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.
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.
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
>SAVE
>SETTIME 2011 08 29 15 00
>RUN
Don’t you agree that would be an enjoyable hack, and maybe 400 bytes of RAM is enough for a useful program?
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.
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.
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.
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.
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 :-)
Very nicely done. I’ve just got to find out how easy it is to get it running on my Uno.
LogoWriter…I’ve never seen a better way for a kid to learn programming, I love that software when I was in elementary.
600b?! Are you a wizard?
Very impressive!
Awesome job!
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.
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).
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.
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, VB.net 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 VB.net.
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.
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 computer..one 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 ;)
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.
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.
>>”Basic is a programming language equivalent of cuneiform and not suitable for teaching coding in 2011. – retepvosnul”<<
He, he … You mixed up this (http://i54.tinypic.com/174w8l.jpg) 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. :)
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.
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.
Check out the Pololu 3pi robot. It is exactly what you are looking for – a beer coaster with 2 wheels and a ATmega328…
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 *****
‘D’,’E’,’L’,’A’,’Y’+0x80,
‘O’,’U’,’T’+0x80,
‘I’,’O’,’D’,’I’,’R’+0x80,
#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;
mydelay:
{
short int value;
short int udv;
unsigned char *address;
// Now get the value to assign
expression_error = 0;
value = expression();
if(expression_error)
goto invalidexpr;
udv = value;
// check for a comma
ignore_blanks();
if (*txtpos != ‘,’)
goto syntaxerror;
txtpos++;
ignore_blanks();
// Work out where to put it
expression_error = 0;
value = expression();
if(expression_error)
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)
{
delay(udv);
}
if (value == 2)
{
delayMicroseconds(udv);
}
// Check that we are at the end of the statement
if(!check_statement_end())
goto syntaxerror;
}
goto run_next_statement;
out:
{
short int value;
short int udv;
//unsigned char *address;
// Now get the value to assign
expression_error = 0;
value = expression();
if(expression_error)
goto invalidexpr;
udv = value;
// check for a comma
ignore_blanks();
if (*txtpos != ‘,’)
goto syntaxerror;
txtpos++;
ignore_blanks();
// Work out where to put it
expression_error = 0;
value = expression();
if(expression_error)
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)
{
delay(udv);
}
*/
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
if(!check_statement_end())
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
Thanks for the code!
Basic interpreter for AVR exists for a long time:
http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=688
It is based on Micro-Basic from Dave Dunfield.
“You must log in to access this area” :-\
AVR Freaks request to login. This project is so old that the original website does not work.
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
Requirements:
– 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
History:
– 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.
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!
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.
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.
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.
micro variable program sample
10 cls
20 for i= 1to 5
30 print “ali”
40 next i
50 end
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
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 http://www.quickcalcbasic.com. (Enjoy, but watch out for those evil GOTOs.)
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: http://cappels.org/dproj/AttoBasic_Home/AttoBasic_Home.html
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.
Enjoy!
Peace and blessings,
Johnny Quest
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
AttoBASIC has been updated to support the TINY84/85, MEGA16/32 and MEGA644/1284. Same link as above, which is http://cappels.org/dproj/AttoBasic_Home/AttoBasic_Home.html.
Personally, I program in ASM and “dabble” in “c” but when evaluating and testing hardware peripherals for embedded systems, I always use AttoBASIC since its very easy to use and does not require the continuous program, FLASH, debug, re-program, etc. cycles.
Peace and blessings.
Look this:
http://www.zbasic.net/
http://www.mcselec.com/index.php?option=com_content&task=view&id=14&Itemid=103
http://www.mikroe.com/mikrobasic/avr/
http://www.oshonsoftbasiccompilers.com/avrbasiccompiler.php
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
There is my version of Mike Fields’ tiny basic. It uses the TVOUT library and the PS/2 keyboard library to allow for programming in Tiny Basic directly on an Arduino or clone. It features Wii Nunchuck and DHTxx support; Poke works, full support for digital and analog pins. Serial I/O and special support serial out to support a second screen. Game related graphics and Pong style audio.
https://halfbyteblog.wordpress.com/tag/tiny-basic/
Oh, nicccccce.
Yer modern average 8 bit… just power on and make it do stuff. I wanna put one together, got a Pro-Mini, gotta find keyboard and RCA socket.
The PS/2 socket and keyboard were the hardest things to find. Pro-Mini is great for this…if you find a PS/2 keyboard, you can mount the pro-mini in the keyboard case, solder the keyboard cable to the Pro-Mini and add the power and video out jacks. Self contained, plug and play!
Hi all,
I made my own interpreter starting from uBasic, it has some interesting features and run from an sd card saving a lot of SRAM….hope you’ll have a look!
http://avil.altervista.org/
Explain more svp, Does the arduino contains everything (all the code needed) to start-up at its’s own? (Turnkey?)
Or is manual intervention (or use of a terminal or PC) needed, (After a user program is “inserted”)?
I know this is an old article, but is there any interest still out there for a BASIC compiler for Arduino?
YES!!!! i would absolutely **LOVE** to be able to program the Arduino in BASIC!! I really struggle to “re-format” my ideas that “run in BASIC” inside my brain, into C++ for the Arduino. There are SOME similarities, but not enough for these old gray matter cells to grasp! I started programming in BASIC in 1976… and it’s what I know. :)
Check out Bascom AVR (https://www.mcselec.com/index.php?option=com_docman&task=cat_view&gid=99&Itemid=54). Download the demo version (limited to 4K and limited support) and the PDF (caution – huge!) This will be enough to play with, and learn about the language, and then the registered version is only EUR 89.
This is a great (modern) implementation of BASIC for the AVR family; I used it in my textbook for Introduction to Microcontrollers (along with a tiny dev board for the Tiny2313. They have an entire forum for using their product on Arduino boards (https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewforum&f=21) It is designed for Windows, but I have not had any troubles with running it under wine.
this is very very interesting from a BASIC point of view, I never understood the reason for the jump from BASIC to C++ and after fighting to learn it for 6 years I can finally go back home to something that makes sense…THANKS VERY MUCH
As a follow-up, I did find something called “Great Cow BASIC” that will work with the AVR (Arduino UNO style chips) and the MicroChip versions. I installed it onto a Windows laptop, and it ALMOST works… it insists on trying to use COM4, which doesn’t exist. Sigh. The USB interface for the Arduino is COM5, and I can’t seem to get it to accept it and work, even tho the dialog box shows “COM5”. Sigh. So, immediately, I slammed into a stone wall! :( As for the other suggestion here… 89 Euro seems like a LOT of money! (About $100 US?) Great Cow is free. I’m still looking. I bought a number of Arduino “Pro Mini” boards for future projects ($5 each, nice price!) and wanted to try tinkering with them in BASIC instead of C++. I might just switch over to the PICaxe system, which DOES use BASIC, and is pretty powerful. I have used PICaxe before, and I like it… Decisions, decisions. ;)
Now that Microchip has bought AVR, one would think there would be a case to port “Picbasic Pro” to the AVR.
MElabs should seriously look into that.
I’ve been using Picbasic Pro for many years and it really is the bees knees for microcontroller programing.
Picbasic Pro is like C but with all the silly hieroglyphs taken out of it.
Funny how people come out of the woodwork with pitchforks and shovels to attack any instance of “BASIC is useful for x.” Bad habits? Really?
10 Does the language and code combination work using a reasonable amount of resources (people hours, RAM/ROM, CPU, etc.) for a given problem? If no goto 20 If yes goto 40
20 Try different language and code combination.
30 goto 10
40 Who gives a shit?
How’s that for functional?