2011 July 14

Scratch and the Arduino

Filed under: Scratch,Software — gasstationwithoutpumps @ 18:08
Tags: , ,

Small S4A (Scratch for Arduino) program that detects when a button is pressed. I used a pull-up resistor, so pressing the button pulled the signal low. Since that is a very standard circuit, I object somewhat to the "Sensor pressed" terminology. It should say either "Sensor Digital1" (since the value is Boolean) or "Sensor Digital1 high"—the "pressed" word is misleading.

There is a project now that combines two of my favorite tools for teaching about computers: Scratch for beginning programming and Arduino for beginning embedded systems and microcontrollers: Citilab – Projecte Scratch. The project appears to be from Spain, as the main page of the site is in Catalan, though the Arduino page is in English.

The idea is a simple one: the Arduino is loaded with a standard program that interchanges information with the Scratch program via USB every 75 msec. The I/O pins of the Arduino have a standard configuration:

The configuration offers 6 analog inputs (analog pins), 2 digital inputs (digital pins 2 and 3), 3 analog outputs (digital pins 5, 6 and 9), 3 digital outputs (pins 10, 11 and 13) and 4 special outputs to connect Parallax continuous rotation servomotors (digital pins 4, 7, 8 and 12).

They had to modify Scratch a little to add blocks for the I/O (similar to the official Scratch blocks for the “Scratchboard” which is not nearly as versatile as the Arduino). It would be nice if the S4A modifications made their way into the official version of Scratch, as the Arduino and Scratch communities are natural allies in making computer science and computer engineering more accessible to non-specialists.

There are some mistakes they made. For example, they put all the Arduino blocks with the “motion” blocks, though it would have made more sense to have a new page of blocks (or to have spread them between the motion and sensing pages).

They also refer to digital inputs pin 2 and 3 as Digital1 and Digital2, and to Analog pins 0 through 5 and Analog1 through Anlaog6. I think that they need to make their Scratch programs consistent with the labeling on the Arduino board! The digital outputs are correctly labeled 10, 11, and 13, but they have separate blocks for On and Off, which is not as nice as a single block that can set the digital output to a Boolean (though Scratch would have to have constants <True> and <False> for that to work well).

I’ll be sharing S4A with the robotics club, as it looks like a fun thing to play with, even if there are some minor design flaws.

Create a free website or blog at WordPress.com.