1

For beginners it is always a problem getting started with microcontrollers. The biggest problem is getting the whole system running and then programming it with C. C is a great language but it has its pitfalls.

A solution for this problem would be running an interpreter of a high-level language on the microcontroller. Another advantage for the user would be that he can directly see what a command did.

In detail we want to use the atsam4s16b controller from atmel. We developed a board and now want it for the users to be as easy programmable as possible.

At the moment we are thinking of implementing the lua interpreter or porting the elua interpreter.

But before we get started I want to ask if there could be other interesting solutions and what are the pros and cons.

For an embedded lua interpreter I would say you have of course some performance losses as for every other interpreter you run. But on the positive side lua is a simple language which can be learned quite easily and you can communicate in an easy way with c code.

So the features of the language must be:

  • Easy communication with C
  • interpreted
  • Easy to learn
  • modern concepts (object oriented, maybe functional)
  • fit in the ATSAM4S16B
  • widely used would be good
  • and the interpreter should not be in an experimental state
TM90
  • 455
  • 2
  • 11
  • Possible subjective answer alert. – Andy aka Sep 18 '14 at 22:59
  • That why I would like to get some pros and cons too ;) – TM90 Sep 18 '14 at 23:01
  • Just saying.... – Andy aka Sep 18 '14 at 23:05
  • 1
    This really depends quite heavily on the target audience for your board and the types of applications they will be wanting to code up. Also, do you expect the board to self-host its own development environment, or will it be tethered to a desktop PC of some sort? – Dave Tweed Sep 18 '14 at 23:21
  • 1
    PIC Basic has been around for a while. – copper.hat Sep 19 '14 at 00:01
  • 2
    I think it's important to learn C because in practice C is what is going to be used in a real microcontroller application. The C standard library is nearly useless now (I would go so far as to say it's actually detrimental to software progress in general). But C the *language* is very good and I think it would be wise to invest time to understanding it. The parts of the C language necessary to program a microcontroller are fairly easy. You only need to know a little bit manipulation and maybe something about pointers to do the basics. – squarewav Sep 19 '14 at 00:10
  • 1
    Isn't an Arduino sketch a scripty thing? – gbarry Sep 19 '14 at 00:48
  • 1
    @gbarry No. An Arduino sketch is actually a fragment of C. – squarewav Sep 19 '14 at 01:06
  • 1
    Actually I heard that in many modern embedded applications embeddes lua, c++ or an embedded linux is used. I have no problem with c and the possibility to program the board in c will always be there – TM90 Sep 19 '14 at 07:49
  • The interactivity of an interpreter on the micro itself drastically speeds up development -- there is no long "parse, compile everything, link everything, upload, reset, then run" to frustrate you. Long the strength of Forth, more recently MicroPython does this, as would a Lua. [This answer](https://electronics.stackexchange.com/a/302944/146624), while particular to ESP8266, is still relevant and gives a good perspective that should also apply to your board. – MicroservicesOnDDD Jul 31 '21 at 17:13

2 Answers2

4

The old school answer that I'm tempted to give is: FORTH.

It's very suitable for resource constrained systems, it's close to the hardware, and yet it allows building very powerful abstractions if desired.

I don't know about your specific microcontroller, but FORTH systems are available for almost any hardware.

microtherion
  • 1,571
  • 2
  • 11
  • 18
  • Actually I think a modern approach would be more suitable. The target group are users with great project ideas who want to get their things done fast. So they do not want to get in touch with the hardware too deeply – TM90 Sep 19 '14 at 07:54
  • @TM90 -- Try one of the existing Basic interpreters on top of a Forth. Hans Bezemer is still improving his Basic on his 4th, which is a C-Library. I have also seen a Lisp, a Pascal, a Scheme, and a meta-interpreter built on Forth, which is very elegant and powerful, is both low-level and high-level, and a DSL toolkit. Since it's space-delimited, the parser is very easy to build, and very fast for an interpreter. And just like Python or Lua, you compile (or assemble) the functions/modules as needed for speed, leaving the interpreters as the higest level for flexibility. – MicroservicesOnDDD Jul 31 '21 at 16:32
3

There are two implementations of Python for Microcontrollers which give an on-chip interpreter:

They fit on MCUs with less than 128kB, so they should be fine on an ATSAM4S16B.

Remember, UNIX Edition 7 ran on machines with 256kB. That provided multi-user, multi-process support for several users (over serial to dumb terminals). Also, many of the early home computers had significantly less resources and ran BASIC.

So software from the 70's would probably work. For example Poplog.

Edit: I am not recommending Poplog, it is only an example of software small enough to port.

Other systems, maybe worth considering:

  • SmallTalk looks feasible
  • XLisp I used that in 64kB code and 64kB data on a PC in the mid '80s.

If host compiled languages, which have advantages over C are to be included, then Microsoft's .NET Micro Framework would provide a safer language than C.

gbulmer
  • 10,040
  • 20
  • 29
  • Python on a microcontroller would be an awesome thing, but python on a chip does only support a part of the python syntax. MicroPython looks really good but it is in an experimental state and looks really young. – TM90 Sep 19 '14 at 07:59
  • @TM90 - AFAIK, the kickstarter boards have been shipped, and more boards are available for sale. So you might find feedback about its quality. People seemed impressed by the implementation early this year, but I haven't followed it. It would be harder to choose between a cut-down Python (PyMite) and lua. I believe it is pretty easy to find out what folks are doing with PyMite via it's forum. – gbulmer Sep 19 '14 at 08:32