Catenary is a small, easy-to-use program that allows a project written in Scratch (http://scratch.mit.edu)
to communicate with an Arduino board (http://www.arduino.cc). Catenary is
written in Processing (http://processing.org), and runs as a Java application.
It takes advantage of Scratch v1.3’s ability to send and receive broadcasts and
global variable messages. Catenary acts as a middleman, shuttling certain
messages back and forth between the Arduino board and Scratch.
GETTING STARTED
1. Set up your
Arduino board
Note: If you do not
have an Arduino board, and you just want to play with the Catenary program with
Scratch, you can ignore this section.
Connect your Arduino board as
specified in its documentation, then download and install the Firmatafirmware, which effectively turns
your Arduino into a general purpose I/Oboard that you can control via a serial connection. The release used
here was Standard_Firmata_334, but
newer versions might also work. Note which COM port is used by the Arduino
board.
2. Scratch Setup
Start Scratch V1.3 and open up an
example Catenary project. For this example we use the
simple “Blink” program available at http://scratch.mit.edu/projects/CatenaryProjects/257547
Don’t run the project just yet.
Instead, enable remote sensor connections by select the blue Sensing tab and
Shift+Right-clicking one of the sensor value blocks as shown.


3. Catenary Setup
Start
the Catenary executable file (or run the .pde file via Processing).You should see a window like this:

If Scratch can’t connect, it will
give you an error message. Usually this is because you skipped step 2. Note
that Catenary still does not know which port your Arduino board is connected
to; this is something you need to specify in the Scratch project, as described below.
4. Run Scratch
Going back to the Blink project
in Scratch, the third block down specifies which index of the Com port is used
for the Arduino board. So, you might have three Com ports active: com1, com3,
com7, corresponding to indices 0, 1, and 2, respectively. If your Arduino is
using com3 in this example, then you would change the broadcast to read ^arduinoPort 1. If you
are just playing around with Catenary and don’t have an Arduino board, just
remove this broadcast block.

The rest of the blocks in the example are pretty straightforward. Every command to Arduino is done via
a broadcast that starts with a caret (^) character (see details below). Here, after a reset command, the pin mode of
pin 13 is set to “output”, then the value of the pin is repeatedly changed from
high to low. It’s as simple as that.
When you now run the Scratch
project, you will see something like this in Catenary (with the square
representing pin 13 blinking), and an LED attached to pin 13 of your Arduino
board should do likewise (pin 13 usually has a built-in LED).

Note that the leftmost blue
square represents pin 2, and the rightmost blue square represents pin 13. (Pins
0 and 1 are used for serial communication.) The gray squares represent analog
pins 0-5, referred to as pins 14-19 within Scratch. Triangles appear above or
below the squares to indicate whether it is an output or an input.
It’s important to note that
Catenary displays what it thinks the
Arduino is doing, not necessarily what it is actually doing
SCRATCH-TO-CATANARY
COMMANDS
There are just six broadcasts you
need to know to control the Arduino board via Scratch. Each starts with a caret
(“^”) and uses space characters asdelimiters.
^arduinoPort port
Tells Catenary
which COM port to use to establish a serial connection with your Arduino board.
port is an integer corresponding to
the index of the COM port. This should always be the first block in your
Scratch project.
Example:


^reset
Tells Catenary
to reset all the Arduino pins. This should always be the second block in your
Scratch project.
Example:


^pinMode pin value
Tells Catenary
to sets the pin mode of pin. pin is an integer (0 – 19). value is a
case-insensitive string: “input” or “output”. When a pin is set as an input, a
sensor watcher will appear in the sensor blocks having a name such as “Pin2”,
etc. Its value will be an integer corresponding to the result of a
digital-to-analog conversion (0-1024).
Example:


^digitalWrite pin value
Sets the
output of a pin to a digital value, where pin is an integer (0-13). Value is a
case-insensitive string: “high” or “low”.
Example:


^analogWrite pin value
Sets the output
of a pin to an analog value. pin is an integer (0-13). value is an integer (0-255).
This is used for PWM output. Check your Arduino to see which pins can be used
for analog output.
Example:


^analogSample value
Tells Catenary
to sample the analog inputs only every value
time. This number is displayed in the Catenary window as a fraction, and is
used to prevent Catenary from spamming Scratch with fast-changing analog inputs
when a high sampling rate isn’t necessary. So if the Processing frame rate is
70, and value is 10, then Processing
would only sample the analog inputs 7 times per second.
Example:


In addition, within the Scratch
environment, when you want pin or value to be variables within Scratch, you can
use the broadcasts in the Scratch Catenary sample files. Each of these uses the
global variables pin and value and builds a broadcast message to Catenary using
a list.

About the Caret “^”
Since all broadcasts and global variable changes are sent as messages by
Scratch (through a TCP socket stream) -- not just those related to Arduino
inputs and outputs-- there are a lot of
things Catenary wants to ignore. It is difficult to parse every broadcast and
variable change (sensor-update) while still interfacing with the Arduino and Scratch
in near real time.To solve this
problem, Catenary just ignores everything in the socket stream until it sees a
caret (“^”) symbol, then parses what comes next to see what it should do. Specifically,
it reads the input until it gets to the next double quote character, then
parses that string using the space character as a delimiter. Not surprisingly,
then, you should avoid using any broadcasts or global variables that include a
caret character (unless you want your own custom commands to be built into your
own modified Catenary program).
Speed
If sampling or execution speed is
an issue: (a) use non-global variables and lists as much as possible, as they
are not sent out by Scratch as messages; and (b) avoid over-use of broadcasts.
Zipped file with application and source code: Catenary v1.zip
I so sorry that Cantenary does not work for me.
I installed Scratch 1.4 and your Cantenary. I enabled the remote sensor connections in Scratch. Scratch and Cantenary are communicating ... I can see the high and low bits in the Cantenary window. The communication from Scratch to Cantenary is working.
The problem is that Cantenary does not communicate with my Arduino. Could it be that there is a new version of Arduino with an ATmega328 that does not work with the current software? Yes, Cantenary shows the correct port in its message box and the rx tx lights are blinking when I send a command from Scratch.
Is it possible for someone in this forum to tell me what I should try to do? I want to get the Arduino with Scratch and I also want to try the ScratchBoard emulation.
http://scratch.mit.edu/forums/viewtopic.php?id=9458
http://scratchconnections.wik.is/User:Sburlappp/Emulating_a_ScratchBoard_with_an_Arduino
I am using Mac OS X 10.6.1 and Arduino 0017. In this software everything seems to be okay ... lights are blinking and sensors are read. I uploaded StandardFirmata from Arduino 0017.
Best regards, Ralf edited 08:02, 17 Oct 2009
Paulpanther, I'm on a windows machine, but the StandardFirmata library that came with Arduino didn't work for me. I also saw that Scratch and the Arduino were communicating, but my commands weren't working. What finally worked was to use Standard_Firmata_334 from here: http://firmata.org/wiki/Download
Hope that helps!
Teresa edited 19:37, 11 Nov 2009