Dartino - Getting Started

How small a device can run Dart? Raspberry Pi may be physically small and the Raspberry Pi Zero even smaller, but the Pi is a full microprocessor and runs a full Linux or Windows stack. What about microcontrollers? Running on the bare metal with limited resources?

Enter Dartino. I've been playing around with the little brother of Dart named Dartino. It's targeted at microcontrollers with limited resources. Small devices with a single purpose. Thermostat. Hydroponics monitor. Weather station. While it's really great having all the capabilities of a full OS stack on the RPI, there's something really cool about plugging in a microcontroller based device and having the application running in under a second. Small. Dedicated devices. Fewer things to fail.

I started playing around with Dartino and it is still definitely in its infancy, but it recently crossed a milestone when I found I could create simple interactive apps. With the 0.4.0 release of the Dartino SDK, I built some touch based apps on the STM32746 Discovery board and interact with sensors via the GPIO  API. To test the LCD and touch input, I created a simple lights out game (see the code on github). There is a drawing library for lines and text and a touch library for detecting user interaction. The library handles all of the low level details so that I could quickly build and test the application.


Next I created a simple 4 button "Simon" game (see the code on github) to test the GPIO input and output capabilities. Again there is a GPIO library for interacting with the pins so that I didn't have to worry about it. Nice to be working in a high level language on a low level device.


Dartino provides high level libraries, making it easy to interact with the LCD and the GPIO pins.
For example...

Initializing the GPIO pins...

List<Pin> leds = [STM32Pin.PC7, STM32Pin.PC6, STM32Pin.PG6, STM32Pin.PB4];
List<GpioOutputPin> outputPins = [];

for (Pin led in leds) {
outputPins.add(gpio.initOutput(led));
}

Turning on one LED and turning off the others...

void setLeds(int ledToEnable) {
for (int index = 0; index < outputPins.length; index++) {
outputPins[index].state = (index == ledToEnable);
}
}

There are several other languages / frameworks that I considered...

* Implementing these samples using Dart on the Raspberry Pi is a definite possibility, but I wanted something that runs on a microcontroller.

* I also considered Johnny Five, but it does not run on a microcontroller either. Instead, Johnny Five runs on a microprocessor with full OS (e.g. BeagleBone Black) or on a host machine (e.g. laptop) with the microcontroller acting as a thin client and permanently tethered to the host. I want something that runs on a microcontroller by itself.

* These samples definitely could have been written in C, but I wanted to use a higher level language.

I built all this using Atom IDE with the Dartino plugin. I find it exciting to use Dart first on servers, in the browser, on mobile devices, and now on microcontrollers. Fun!

Comments

  1. Interresting! You can also play with Java on your board thanks to MicroEJ: http://developer.microej.com/getting-started.html

    Take a look at this video: https://www.youtube.com/watch?v=nAvMepvyTW8

    ReplyDelete

Post a Comment

Popular posts from this blog

Dart on Pi - Getting Started

Dart on Pi - Tracking Changes