Institute for Personal Robots in Education Blog

Interactive Arduino Programming with Calico

In the Fall 2012 semester I'll be teaching a quarter course (1/2 semester) on Physical Computing at Bryn Mawr College. As an experiment, I thought I'd explore programming an Arduino, but I'd like to start out programming interactively rather than jumping straight into embedded systems using C.

Processing is the basis for the standard method of the Arduino programming environment, and also Processing can be used to talk to an Arduino board directly. I wondered if Calico could be used in the same way.

Calico (formerly called Pyjama) is a multi-language, multi-library framework and IDE. The idea is that if you have a library that can talk to, say, the Arduino, then you write it once, drop it in a folder, and it will instantly appear as native library to all of the Calico languages, including Python, Jigsaw (a visual language inspired by Scratch), and Scheme---on Mac, Windows, and Linux.

It turns out that there is a library built for communicating with the Arduino from .NET/Mono. So this was really easy!

Here are the steps to interact with an Arduino from Calico:

  1. Download Calico
  2. On Windows you'll need to install the Arduino Drivers (Control Panel, Devices, Install driver for your Arduino device)
  3. Download Rhyduino
  4. Place the Rhyduino .DLLs in the Calico/modules folder
  5. Interact with the Arduino!

A little experiment to turn an LED on/off

This experiment should work with any of the basic Arduino boards. You'll just need an LED, the USB cable, and the Arduino board.

First, put a LED into the GND and Digital 13 pin. The short wire of the LED is negative, and will go into the GND pin hole. The long wire of the LED will go into the 13 hole.

Once that is in, you can connect your Arduino to your computer via the USB plug. This should work on Windows, Mac, and Linux. You'll need to know the associated serial port name.

Then you can interact with your Arduino from any Calico language. Here is an example of turning on the LED in Calico Python:

import Myro
import Rhyduino

with Rhyduino.Arduino("COM5") as arduino:
    arduino.Connect()
    pin = arduino.DigitalPins[13]
    pin.SetPinMode(Rhyduino.PinMode.Output)

    count = 0
    for t in Myro.timer(10):
        if count % 2 == 0:
            pin.SetPinValue(Rhyduino.DigitalPinValue.Low)
        else:
            pin.SetPinValue(Rhyduino.DigitalPinValue.High)
        count += 1
        Myro.wait(1)

Now to try this from Linux and Mac... Enjoy!

UPDATE:

It did work fine in Linux, just like in Windows. I just plugged the USB cable in, and Ubuntu added it with a serial interface as /dev/ttyACM0:

Rhyduino.Arduino("/dev/ttyACM0")

Documentation on Rhyduino project:

http://rhyduino.codeplex.com/wikipage?title=Rhyduino%20Reference%20Documentation&referringTitle=Documentation

AttachmentSize
Arduino.PNG64.21 KB
IMGP2253.JPG108.6 KB
IMGP2252.JPG113.06 KB

The standard method for

Mon, 2012-03-19 17:31
Anonymous

The standard method for working with the Arduino is not Processing, it is the Arduino IDE. (http://arduino.cc/en/Main/Software) This is a fairly full featured IDE that uses a C like language derived from Wiring (which is modeled on Processing). It is actually uses the gnu C/C++ compiler and is basically C/C++ with some syntatic sugar and libraries.

If the arduino is to be used only in a PC connected environment and the author does not want to learn/teach the Arduino environment, then I can understand using Calico or Processing or whatever. However, if the goal is to teach Physical Computing, sooner or later they will need to do C. The arduino environment makes it pretty simple. I've taught high school and younger (4th grade even!).

There are thousands of libraries and projects built using straight arduino ide. Most are open source and easily adapted. The basic IDE and almost every library includes an Examples that is directly accessible from the File>Examples menu.

For example, here is the Blink sketch, which is roughly equivalent to the Calico example. It will blink the (usually built in) LED on pin 13 on/off.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {
  // initialize the digital pin as an output.
  // Pin 13: Arduino has an LED connected on pin 13
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}


Jerry, Thanks for your

Mon, 2012-03-19 18:33

Jerry,

Thanks for your comments! Some thoughts below.

Yes, everything that you say is true, or at least conventional wisdom. And, I'll probably end up on that path on the way to teaching Physical Computing. After all, what would a course on programming a microcontroller be without ending up in C, and the Arduino IDE does that well.

But I think one might take you to be dismissing a huge swath of unexplored territory with your statement that "If the arduino is to be used only in a PC connected environment ... then I can understand using Calico or Processing or whatever." There are two ideas here:

The first is that using Calico allows many different languages to connect to the Arduino. For example, by following along the blog, one could also program in Calico Jigsaw (a visual programming language), or Calico Scheme (a high-level functional language). More importantly, each of those languages opens up different audiences to the Arduino. On one end, Jigsaw might allow even younger than 4th graders to get some experience with embedded systems and computing. On the other, Scheme allows some possibly very interesting high-level code to be explored. And there are more languages in Calico that get this connection without additional work.

Second, there are many possible projects that exist before jumping to embedded only (many ideas that can be explored in Processing or whatever, too.) But before we completely move to C, let's play around a little to see what is possible in combining the power of the PC with the embedded system. I don't mind spending a little time in this space to play around.

So, in true DIY maker spirit, we're just hacking into unexplored territory.

-Doug

Post new comment

  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
More information about formatting options