Catenary

From $1

image001.png  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.    

arduino.jpg 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.

image003.jpg

 3. Catenary Setup

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

image004.jpg

 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. 

image005.gif

 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).

image006.jpg

 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:

image007.png

 

^reset  

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

Example:

image009.png

 

^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:

image011.png

 

^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:

image013.png

 

^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:

image016.jpg

 

^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:

image017.png

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.

commands3.jpg

 

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 codeCatenary v1.zip

 

 

 

 

 

 

 

Tags:
FileSizeDateAttached by 
 Catenary_v1.zip
No description
2.95 MB22:12, 18 Sep 2008chalkmarrowActions
Images (21)
Viewing 1 - 6 of 21 images | View All
No description
arduino.jpg  Actions
No description
commands3...  Actions
No description
image018....  Actions
No description
image017....  Actions
No description
image016....  Actions
No description
image015....  Actions
Comments (9)
Viewing 9 of 9 comments: view all
Why there are no digitalRead command in this Catenary? Are the analogSample command is the command for analog sensor reading like resistance sensor in ScratchBoard?
Posted 09:30, 1 Jul 2009
iwansuryo: digitalRead is built in. Any pin that is designated as a digital input is updated as a sensor value automatically. I'm not sure I understand your second sentence, but the analogSample command just makes it so that there is some delay between reading fast-changing values (otherwise, catenary and scratch would get swamped by too many values).
Posted 07:11, 2 Jul 2009
Also, note that there is an analogWrite command (see above), which you had asked about in another post.
Posted 07:13, 2 Jul 2009
I am sorry chalkmarrow. I am a newbie in Arduino. But I still don't understand about how to read the value of sensor from pinMode input, especially for analog sensor. Because many kind of sensor is analog type, like resistance sensor and light sensor. So I think you should understand about how to read this sensor with any instruction like analogRead. Without this function, Scratch will not be able to control anything based on many physical input outside of the computer. Thank you very much for your answer.
Posted 16:44, 9 Jul 2009
Pins 14-19 are analog pins. If any of these pins are designated, using pinmode, as an "input," then that pin is automatically converted to a sensor-value (and sampled at the rate specified using ^analogSample). That is, an analogRead command is automatically generated for any analog pin that is specified as an input.
Posted 21:16, 13 Jul 2009
Hi,

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

Posted 07:47, 17 Oct 2009
Great program, chalkmarrow--thanks for posting it!

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
Posted 19:32, 11 Nov 2009
I still got an error running this program so I decided to run from Processing. I am very sure that the ArduinoPort 0 in my computer refer to COM6 which is connected to my Arduino. I have test this connection with other Arduino - Processing program and running very well. So my Standard Firmata works very well with Processing program. But with Catenary, I always got very strange error. It gives me an error message: Attempting connection to Scratch 127.0.0.1 Comm ports sensed by Arduino: Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 [0] "COM6" Beginning main draw loop Attempting connection to Arduino at Arduino.list()[0] gnu.io.PortInUseException: Unknown Application at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354) at processing.serial.Serial.(Serial.java:136) at processing.serial.Serial.(Serial.java:102) at cc.arduino.Arduino.(Arduino.java:149) at Catenary.draw(Catenary.java:203) at processing.core.PApplet.handleDraw(PApplet.java:1425) Connection to Arduino port failed at processing.core.PApplet.run(PApplet.java:1327) at java.lang.Thread.run(Thread.java:619) From Scratch: reset From Scratch: set mode of pin 13 to output Can someone help me please? I cannot resolve this problem. Thank you very much.
Posted 17:25, 2 Jan 2010
Now I success running your code but only with SimpleDigitalFirmata. I always got error messages with StandardFirmata or Standard_Firmata_334. Why it is not compatible with all Firmata?
Posted 06:29, 4 Jan 2010
Viewing 9 of 9 comments: view all
You must login to post a comment.

 
SourceForge.net