Return to Basic

My first encounter with a real computer was an HP 9830 series desktop mini computer, sometimes round about 1978. It played a game called 23 matches (a variant of NIM) and it beat me. It beat me the 2nd time too, then I started to think… Then I beat it, then the teacher showed me the program. That looks easy, I thought…

So many (35+) years ago I learned to write computer programmes. I started in BASIC on that HP 9800 desktop machine, then via 110 baud dial-up on a thundering old Teletype ASR-33 to the local computing centre (Moray House, Edinburgh), then Apple ][, BBC Micro, etc., etc., etc....

However in a fit of nostalgia, I decided to resurrect some of my old BASIC programs of that era (late 1970s, early 80s) and so I bought an Apple ][ europlus for that authentic experience then decided to write a BASIC interpreter - (How hard can it be?), so I did, and it’s called Return to BASIC – or RTB.

At the time I really wasn’t thinking of what to do with it, then this Raspberry Pi thing started to gather interest, so I decided to order one and see if it would port to their Debian image running in QEMU. And it did. It was as simple as typing ‘make’. That’s the beauty of Linux (and Unix) code – with a few small limitations, everything “just works”.

So now what… I think BASIC is fun and quick – it’s not a “real-world” programming language, and I don’t intend it to be that either, but as something to get some nice graphics going, or as an easy way to interface to hardware like an Arduino, then it’s great!

RTB is a modern BASIC – it has while/until looping constructs and named functions and procedures which can have local variables and be called recursively. It has  simplified colour scheme (or you can use all 24-bits if you like), and the usual point, line and shape drawing primitives as well as some nice turtle graphics commands.

 

49 comments on “Return to Basic

  1. Dicky Dodds on said:

    I have finally got my PI ordered and would love to use a suitable BASIC with it – and yours will fit the bill with its graphics support. For me personally, I want to interface DS1631 I2C chips and speak over the serial port to my Atmel processors. If your code can allow one to use the GPIO, Serial port, I2C ports and to write console based apps – then its the BASIC for me! I will be happy to run a few tests of your software on mine if you need someone to test the software!
    Dicky

    • Gordon on said:

      There are currently 2 different I2C drivers (to my knowledge!) for the Pi – as soon as one of these proves the more popular, I’ll include uspport into my BASIC for it (or I may write my own, who knows!). General access to the GPIO is possible right now and you can fiddle with all 17 pins for general purpose input/output – one of them can be programmed for PWM too. The down-side right now is that BASIC needs to be run as root – hopefulyl soon a better driver will emerge (although I’m considering writing one).
      Keep an eye on this page as I hope to have a release, both source and binarys in the next week.
      As for the serial access to Atemel processors – I have a little remote control protocol that my BASIC can use to talk directly too them. See the DRC section of this site for more details, but in essence, a program running can access the Atmel IO pins using the Arduino “Wiring” style commands and those same commands will access the on-board GPIO pins too.
      -Gordon

  2. David Eagle on said:

    Gordon,

    I have a Pi and would enjoy testing/evaluating RTB.

    David

  3. Gregory Roberts on said:

    Gordon,
    You have some great stuff here on your projects page, thanks for sharing. I am already playing with wiringPI, and although I haven’t done anything serious yet I am having lots of fun.
    I’m looking around for the link to the RTB code but I am not seeing one. I would like to play with it and don’t mind a few bugs. I also have fond memories of simpler days programming in basic and would love to give your RTB a try.

    Thanks, Greg R

    • Gordon on said:

      Have a look at: http://unicorn.drogon.net/rtb/ you’ll find some executables and demo programs there. I’ve just not had enough time to fix a few remaining bugs and package it up though.
      If writing some program of your own, note that there is a bug in the parser in that it won’t interpret unary minuses correctly, so a = -b won’t work, but a = 0 – b will work, and make sure youe type a space before the minus sign.
      hoping to have time in the next few weeks to finally put a release together though
      -Gordon

  4. Very very interested in Basic !

    and on the Pi it would be fantastic especiallu if it had code to controll the GPIO !

    A very excited Tim !

    : )))))))))))

    Tim

  5. Antti Louko on said:

    Seems great work. Of course we have XBasic but RTB seems to be much more compact.

    As this is still developing program, would it be impossible to modify the syntax to be more like RMB (Rocky Mountain Basic)? After all, you used 9836 in the past. Old manuals which describe the syntax and semantics are available at the HP museum site so it should be doable.

    RMB had quite well thought IO so it should be especially suitable for Raspi. If implemented wisely, it would be possible an even practical to hide even remoted devices behind SPI or I2C in BASIC libraries.

    /alo

    • Gordon on said:

      I’ll have a look at the RMB stuff. Just been using SPI and I2C in the Pi too – not sure they can really map easilly to the constructs avalable from BASIC, but I’ll have a look.
      -Gordon

  6. John Baldock on said:

    I too am interested in running BASIC on my R-Pi. I have loaded bwbasic and it seems to be running OK so far. Like Tim I am mainly interested in using the GPIO. I have had a little advice from a couple of folks who are familiar with LINUX/UNIX and I am closing in on some simple UNIX commands to get the bwbasic to run in root and to access the GPIO pins so that I can read and write to them in BASIC. I will let you know as soon as I can get it working.

    • Gordon on said:

      I’m days or less away from having a nice Pi release of my BASIC – meanwhile, you can look in http://unicorn.drogon.net/rtb and find some executables and a reference manual…

      It fully supports the Pi’s GPIO… See the appendix in the manual for “Drc”…

      -Gordon

    • I’ve released it now – hope you pick it up!

      -Gordon

  7. I sure that your basic programming language is very good, but there are a lot others out there that will work fine on Raspberry Pi and some are easier to use.

    Put RISC OS on another SD card and you got BBC Basic on your Raspberry Pi
    there tons of information and examples on this basic on the internet
    because it been around for years and lots of people have programmed it before.

    • You’re right about there being many – even a version of BBC Basic for Linux called Brandy. No need to even think about RISCOS.

      But RTB is mine and I quite like it! I didn’t even write it with the Pi in-mind either – it just happens that the Pi is Linux and I oeiginally wrote it under Linux (although it works on a Mac too and will run under MS Win shortly).

      I don’t know what your point is though.

      I wrote RTB because it was something I wanted to do, and I’m happy to share it with you and everyone else too.

      Cheers,

      -Gordon

  8. Trevor on said:

    I am having a problem with the line
    arduino = SOPEN (“/dev/ttyACM0″, 115200)

    I get an error message Incorrect argument count for SOPEN (expected 1, got 2)

    Am I doing something wrong ?

    • Gordon on said:

      No, you’ve hit a bug, sorry.
      Long story short – I updated the mechanism I use to count built-in procesdure arguments and goofed for the serial functions.

      Did you build from source or download the binary?

      If source, I can give a patch, or if binary I can re-compile it for you…

      -Gordon

  9. Trevor on said:

    Thanks for the prompt reply. I downloaded the binary. If you can supply a re-compiled binary that would be great.

  10. Trevor on said:

    The supplied binary worked. SOPEN now works as described in the manual.
    I was able to read and write data to my usb to i2c interface which I was using to display time (hours and minutes) on a adafruit 7 segment LED and read a DS1621 thermometer and display it on a SAA1064 4 by 7 segment LED a very old Elektor magazine project.

    Adding I2C commands directly to RTB would be useful. I know the PI is very different from an arduino but could arduino type commands be added to RTB to access ports and hardware ?

    Thanks Trevor

    • Gordon on said:

      Shouldn’t be hard now that wiringPi supports both SPI and I2C. slight lack of proper binary operators though, so it’s never going to be as good as C though, but I’ll look into it.

      -Gordon

  11. Hi Gordon
    Enjoying RTB. Is there a way to alter the colour and font size in the edit screen of RTB?
    Best regards
    Mike

    • Gordon on said:

      colours can be set with the normal text colour commands, so for yellow text on a green background, then

      tcolour = yellow
      bcolour = green
      cls

      However if your program subsequently changes it then it will remain changed.

      Maybe I need a command-mode set of colours and a run-mode set…

      the font size can only be changed at launch time – and then only to double-size

      rtb -l

      will run it in double-size. (I did that mainly to make it readable on big screens, or on TVs when using composite)

      -Gordon

  12. Thanks Gordon.
    Just what the doctor ordered, or should I say optician!!!!
    Double size is OK but don’t get a lot of lines of code on the edit / run window. Is it possible to adjust the size of the run window while launching rtb?
    Many thanks for your speedy reply.
    Mike

    • Gordon on said:

      Are you running it inside X wondows? If so, then:

      rtb -l -x 1024 -y 768

      or whatever X & Y size you want.

      If you want it full-screen, then try this:

      rtb -l -f

      (it doesn’t always work and you might need to run it from the console though)

      -Gordon

  13. Hi Gordon

    Just got hold of a Raspberry Pi and been playing with RTBm it is very good,
    I started out learning to program on TRS80′s in the early 1980′s running level 2 basic I think it was!

    I was just wondering if you had any more thoughts on implementing i2c communication into RTB?
    I have had a play with the i2c stuff using python, but I am way to old to learn a new language.

    Thanks for RTB Gordon.

    • Apologies for the typo on the first line it should be RTB not RTBm

    • Hi,

      Glad you’re finding it ok!

      It’s not impossible to add I2C operations into RTB, (and possibly even SPI) so I might look at it. One issue though is lack of a proper integer data type in RTB but that’s not a big show stopper. I’ll give it some thought.

      -Gordon

      • Thanks Gordon, I hadn’t thought of SPI but I think that it could be useful to have too!.
        I will keep playing with RTB and keep and eye on your page for any updates regarding SPI or I2C.

        - Tony

  14. Walter Miraglia on said:

    wow first multiple lcd’s now basic for raspberry pi?
    very cool… I’m going to download this today and get started…
    I too started with basic way back when, infact I had an Acorn Atom.
    (in Britain that may not be such a big deal, but I am in Canada and there were not too many of them around… :) ) at any rate, basic here I come :)

    cheers!

  15. What a huge work ! Terribly impressed. I’ll try it asap. I worked with Basic decades ago. I still program in assembler on µControllers, it’s light, and long as well.
    Congratulations

  16. Bill S on said:

    Gordon,

    I couldn’t be more pleased. RTB allowed me to build a web server with the RPI. By using RTB to interrogate a serial device on a regular basis, I can provide real-time wind speed and temperature data via a web browser. For anyone that cares the very short RTB code is:

    4 CYCLE
    5 winds = OPENUP (“1record.txt”)
    10 breezeSP = SOPEN (“/dev/ttyAMA0″, 9600)
    20 SPUT$ (breezeSP, “t”)
    25 SPUT$ (breezeSP, CHR$ (13))
    26 junk$ = SGET$ (breezeSP)
    27 junk$ = SGET$ (breezeSP)
    28 junk$ = SGET$ (breezeSP)
    30 FOR i = 1 TO 37
    40 key$ = SGET$ (breezeSP)
    42 WAIT (.25)
    45 PRINT# winds, key$;
    60 NEXT i
    65 PRINT# winds, CHR$ (13);
    70 CLOSE (winds)
    75 SCLOSE (breezeSP)
    77 REPEAT
    1000 END

    The question I have is not exactly related to RTB. I am using a headless RPI, connecting to the RPI via WiFi with SSH. After login, I launch RTB, and run the code above. This prompts the wind and temperature data logger for a current reading and saves the text string to a file (1record.txt) in the directory /var/www. The php code reads this text file, and displays this via a browser. I need the RPI, on power up, with no intervention, to launch RTB and execute my code. Thanks for RTB, and thanks for your help.

    Bill

    • Gordon on said:

      To start RTB with a program, you can give it the name on the command-line, so for example at the end of /etc/rc.local:

      cd /var/www
      /usr/local/bin/rtb myprog.rtb

      another thing you might be interested in is the SAVENN command – saves a program without line numbers – then you can edit it outside the RTB environment. You can also save it (again with savenn), then edit it and add at the top:

      #!/usr/local/bin/rtb

      then make it executable: chmod +x myprog.rtb then just execute it like any other command.

      Remember to use full pathnames for programs you start at boot time though.

      -Gordon

  17. Bill S on said:

    Gordon,

    Thanks for the speedy reply. One thing I forgot to ask. I have been reluctant to stop my SSH session with the RPI. I have a sense that I would be unable to log in again. I have an Xwindow
    up, it’s currently blank, and there is no prompt in the terminal window. I can escape the CYCLE – REPEAT loop with the ESC key, now but… So if I shut down my terminal, am guseeing I would have to do a hard reset either with a power cycle or via the P6 jumpers. Am I missing something?

    Bill

    BTW, it will take me a while to come up to speed and digest your previous instructions.

    • Gordon on said:

      Are you using ssh -X ?

      If so then it will probably stop RTB when you disconnect.

      -Gordon

      • Bill S on said:

        My login looks like this (I’m on a Mac):

        macmini:~ wstein$ ssh 10.0.1.63 -l pi -Y

        If it does stop RTB, what do I need to do so that it does not stop?

        Thanks

  18. ciprian on said:

    Hello!

    Do you think it’s possible to implement in the future playing wav, mp3, ogg or others in RTB?
    What about implementing in RTB display picture files bmp, gif, jpg or others?
    Thank you in advance!

    Ciprian

    • Gordon on said:

      Playing simple tones is in the pipeline – not sure about tunes though. There is currently a screen-save function which saves it as a BMP file, but loading them in? Hm. You can load in BMP files as sprites though – with some checking I may be able to get it to load PNG, JPG, etc. too. I’ll put it on the wish-list!

      -Gordon

  19. Gordon,
    In a reply above you said that it would be possible to include SPI routines. This would greatly add to the RPi’s capability in being used as a controller.
    Is there any progress on this? I downloaded the January 2013 manual revision, but could find no mention of SPI.
    I would be happy to test such functions.
    Great piece of work, btw.
    Roger

    • Gordon on said:

      Currently looking at a (long!) featrure list of things to add into RTB and SPI & I2C is on the list, but it’s been a while to get round to it.

      -Gordon

  20. ciprian on said:

    Hi!

    I;m trying to use a DS 18B20 thermometer in RTB.
    I followed intructions from here:
    http://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor/
    and it;s working fine.
    But when I try to use the content of the w1_slave in the rtb it displays
    -1
    I;ve used the following code lines:
    10 myFile = OPENUP (“/sys/bus/w1/devices/10-000801a51b5f/w1_slave”)
    20 PRINT myFile
    30 STOP

    Where do I wrong?
    P.S. In the line code number 10 I wrote OPEN and it displays automatically OPENUP

    • Gordon on said:

      -1 is the generic error code.
      It’s probably permissions.
      So firstly try using openin – that’ll open it read only, it’s possible that trying to open it as openup (the default) gives you a permissions denied.

      If that still doesn’t work, then from the shell command, try ls -l /sys/bus/w1/devices/10-000801a51b5f/w1_slave and check the ownership and permissions. You need it to be at least world read access – 664, or rw-rw-r ie. at least 3 r’s. You may need to change the ownership or mode before running RTB. sudo chmod 644 ….

      -Gordon

  21. Hello Gordon.
    I’m running rtb (1.0.4) on my Pi and very good it is too. As also with WiringPi.
    One small prob: – when I renumber my rtb progs, restore statements with line numbers are not renumbered. Otherwise everything seems fine!

  22. Erik on said:

    Hi Gordon

    Thanks for a great job with the RTB :-)

    Why can I not get this exampel from the manual to work?

    100 myFile = OPEN (“testfile.dat”)
    110 WHILE NOT EOF (myFile)
    120 INPUT# myFile, line$
    130 PRINT line$
    140 CLOSE (myFile)

    I get this error:
    XXX Syntax error trying to parse: … $
    Program load aborted at line 120

    Best regards Erik

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.