Thursday, June 9, 2011

Arduino is Coming!

I ordered an Arduino last week, and it should come fairly soon. I finally committed to getting an Arduino when I was playing around with my friends Arduino and we implemented Pulse Width Modulation (which I learned about from him and his blog post: http://totherails.blogspot.com/2011/04/pulse-width-modulation.html) without using the built in PWM, but rather by turning on and off a port (which gives you more control than the built ability which is available on some of the ports).

One of my main interests in having an Arduino is actually making programming languages for it. I don't think it would be hard to implement a simple Forth (without a command line interpreter- I'm not really interested in tackling that right now), especially if it was just in C and maybe some assembly. I might do that, but I have another idea I'm looking at right now- I want to implement a concatenative language, like Forth, but with a strong, safe, static type system with polynomial types (ideally). My other main interest is giving it easy-to-use combinators, including anonymous ones. I may have to look over Factor, Cat, or Joy and see if there is some inspiration there.

I want to write a compiler in Haskell that outputs a C program (really in the C-like language provided with the Arduino). An example program might (I imagine) look like this:


: inc dup @ 1+ ! ;
: wait 50 ms delay ;
: blink 14 port dup on wait off wait ;
0 count =
[ blink count inc ] [ count @ 10 != ] while

Which would turn port 14 on and off 10 times, with a delay of 50 ms between each change in state. The stuff between the [] is an anonymous combinator. I would like the usual cast of higher order functions and the special ones for stack-based languages (I remember Factor having some very nice ones). The won't be as sophisticated a language as a real general purpose language, but if I could get it to run the sort of simple programs I imagine myself wanting to execute on the Arduino that would be great.

I will of course report my successes and failures here. I want to note here that the language may end up being less powerful than I would like as I would be willing to remove features to ensure correctness and beauty in this project. Good things come from formalism and from well understood and controlled programming languages.

2 comments:

  1. Sweet! Dude that is awesome. Where did you buy it from? Are you going to keep playing around with the functions before you start this programming language for it? JeremyBlum.com was the site I was looking at for those tutorials, but there are literally thousands of projects and sample code out there for Arduino.

    ReplyDelete
  2. I got it from nkcelectronics because it was $27 instead of like $30 some other places. I will definitely play around with it a lot- this whole language thing may end up being complex, and I don't know when I will even start writing the compiler, much less get something working.

    ReplyDelete