Bitlash Commands from uMMC on Arduino

Bitlash, written by Bill Roy, is pretty nifty. It's essentially an interpreted language shell running on an Arduino.

It seems to me that Bitlash would benefit greatly from being able to read commands from an external memory card.

The uMMC connects to +5V and GND and pins 14 and 15 (analog 0 and 1 respectively). Here's how it looks:

uMMC on Arduino

An example input file (named “0.bls”):

0.bls
print "Hello, world!"
print 2+2
toggle13 := "d13 = !d13"
run toggle13,500

Here is the result:

> exec(0)
Hello, world!
4
saved
>

And the built-in LED on the Arduino (pin 13) is blinking.

In any case, here is my first stab at reading and running commands from an SD card in Bitlash.

BitLash_uMMC.pde
// User functions are:
//  "sdver" - returns the uMMC version number and CPU free memory
//  "dir" - lists all the files in the root directory of the SD card
//  "exec(n)" - runs all the commands found in the file named "n.bls" in the root directory
 
#include "WProgram.h"
#include "bitlash.h"
#include "NewSoftSerial.h"
#include "RogueSD.h"
 
NewSoftSerial ummc_s(14, 15);
RogueSD ummc(ummc_s);
 
// A test function to show the uMMC version and the free memory
// (using the internal print command)
numvar sdver(void)
{
  Serial.print("uMMC Version: ");
  Serial.println(ummc.version(), DEC);
  Serial.print("Free mem: ");
  doCommand("print free");
}
 
// This function lists all the files in the root directory
void sdls(void)
{
  char filename[80];
 
  if (ummc.status() == 0)
  {
    ummc.opendir("/");
    while(ummc.readdir(filename, "*") == 0)
    {
      Serial.println(filename);
    }
  }
  else
  {
    Serial.print("uMMC error code: ");
    Serial.println(ummc.LastErrorCode, HEX);
  }
}
 
// Called by: "exec(n)" where n is the script number (0 -> 9)
// The file is named "n.bls" in the root directory
// e.g. 0.bls
void sdexec(unumvar scriptnum)
{
  char strbuff[80];
  char filehandle;
  int len;
 
  if (scriptnum >= 0 && scriptnum <= 9)
  {
    if (ummc.status() == 0)
    {
      strbuff[0] = '0' + scriptnum;
      strbuff[1] = 0;
      strcat(strbuff, ".bls");
 
      filehandle = ummc.open(strbuff);
 
      if (filehandle > 0)
      {
        // read a line
        while ((len = ummc.readln(filehandle, 80, strbuff) > 0))
        {
          doCommand(strbuff);
        }
 
        ummc.close(filehandle);
      }
      else
      {
        Serial.print("error: script ");
        Serial.print(scriptnum, DEC);
        Serial.println(" does not exist");
      }
    }
    else
    {
      Serial.print("uMMC error code: ");
      Serial.println(ummc.LastErrorCode, HEX);
    }
  }
  else
  {
    Serial.println("error: script number must be between 0 and 9");
  }
}
 
void setup(void)
{
  ummc_s.begin(57600);
  ummc.sync();
  initBitlash(57600);		// must be first to initialize serial port
 
  addBitlashFunction("sdver", 0, (bitlash_function) sdver);
  addBitlashFunction("dir", 0, (bitlash_function) sdls);
  addBitlashFunction("exec", -1, (bitlash_function) sdexec);
}
 
void loop(void)
{
  runBitlash();
}

Here is the uMMC config file (if you need it). Set for 57600 bps, and new listing style.

UMMC.CFG
D3
L1

Discussion

fred, 2010/06/17 11:16

Hi… Just found your site and am excited about the prospect of getting bitlash to work with my arduino 328.

I'd like to run your demo but dont' have access to RogueSD.h..

But also, I don't know if this program still works or if you have made revisions, etc…

Let me know if you are around…

You could leave a comment if you were logged in.
  • Bookmark at
  • Bookmark "Bitlash Commands from uMMC on Arduino" at del.icio.us
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Digg
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Google
  • Bookmark "Bitlash Commands from uMMC on Arduino" at StumbleUpon
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Technorati
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Facebook
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Twitter
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Slashdot
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Yahoo! Bookmarks
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Furl
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Reddit
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Ask
  • Bookmark "Bitlash Commands from uMMC on Arduino" at BlinkList
  • Bookmark "Bitlash Commands from uMMC on Arduino" at blogmarks
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Ma.gnolia
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Netscape
  • Bookmark "Bitlash Commands from uMMC on Arduino" at ppnow
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Rojo
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Shadows
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Simpy
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Socializer
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Spurl
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Tailrank
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Live Bookmarks
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Wists
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Yahoo! Myweb
  • Bookmark "Bitlash Commands from uMMC on Arduino" at BobrDobr
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Memori
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Faves
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Favorites
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Newsvine
  • Bookmark "Bitlash Commands from uMMC on Arduino" at myAOL
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Fark
  • Bookmark "Bitlash Commands from uMMC on Arduino" at RawSugar
  • Bookmark "Bitlash Commands from uMMC on Arduino" at LinkaGoGo
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Mister Wong
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Wink
  • Bookmark "Bitlash Commands from uMMC on Arduino" at BackFlip
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Diigo
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Segnalo
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Netvouz
  • Bookmark "Bitlash Commands from uMMC on Arduino" at DropJack
  • Bookmark "Bitlash Commands from uMMC on Arduino" at Feed Me Links
  • Bookmark "Bitlash Commands from uMMC on Arduino" at funP
  • Bookmark "Bitlash Commands from uMMC on Arduino" at HEMiDEMi
code/bitlash_commands_from_ummc_on_arduino.txt · Last modified: 2010/03/28 01:49 by bhagman
Valid CSS Recent changes RSS feed Valid XHTML 1.0