karplus4arduino

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.

Advertisements

7 Comments »

  1. One person asked by e-mail, “Quick question for you, if you know: do the S4A modules perform debouncing?”

    Since the digital inputs are only sampled about once every 70 msec, and the longest contact bounce I’ve ever seen was under 10msec, there is no need for debouncing.

    I did notice that they read each analog input 5 times and report the median of the 5 values as the result. The 5 reads are in very quick succession for one input before going on to the next, so I’m not sure that this median-of-five filter really cleans up the signal much.

    Comment by karplus — 2011 July 15 @ 03:37 | Reply

  2. I may have gotten excited about S4A a little too soon. S4A seems to run ok for a while, then it says “Board disconnected of the battery is running out Searching board…” for no reason and gets into an infinite loop. It has to be killed and restarted. Once it even crashed my Mac with a kernel panic (I’ve no idea how it managed to do that).

    I think the developers have a little debugging still to do.

    Comment by karplus — 2011 July 15 @ 04:32 | Reply

  3. I believe they are technically supposed to make the source available, according tho the Arduino license terms, but I do not see it on their site. I have been looking at doing scratch/arduino myself as Scratch is GREAT for teaching kids programing basics. Combined with arduino based robots- even better!

    Comment by me — 2011 August 31 @ 12:39 | Reply

  4. I meant according to the Scratch terms…..

    Comment by me — 2011 August 31 @ 12:40 | Reply

  5. Hi karplus,

    First of all we would thank you that you have spoke of S4A in your blog. Of course we also thank you for your suggestions to that two points, which I would not call them mistakes. If you want I’ll explain them:

    1. About putting all Arduino blocks inside the “Motion” category, we did it this way because that’s which first appears when you select an object, even if it’s a “normal” (Scratch) object or Arduino one. This way you can see the difference at first look (Arduino blocks are unavailable at normal Scratch objects). But we will consider spreading them between Motion and Sensors, as you said.

    2. Regarding to the enumeration of sensor board, at the beginning we thought that was a good idea make these watchers starting with “1” to make it prettier, but we recently realized that would be better to change the numbers to the corresponding board pins, mainly to avoid mistakes to beginners. Next version this will be fixed.

    Finally, if your board is disconnected continuosly, check the USB cable. If that’s not the problem, try on another Mac or PC… it’s the first time I hear (or read) that Scratch triggers a kernel panic on MacOs, so I think is not normal :S

    To “me”: you can access to the source code of S4A shift-clicking on File and selecting “Exit User Mode”. Tada!

    Comment by Victor Casado — 2011 September 23 @ 02:01 | Reply

    • Thanks for responding to my comments. Currently, I’m not doing much with Scratch and so will probably not have time to play more with S4A. I like the idea, even if the implementation is still a bit rough.

      Comment by karplus — 2011 September 23 @ 05:15 | Reply

  6. Regarding the ‘searching board…’ error, I too found that at first S4A worked, and then next time I ran it, it came up with a message box reporting this, which never clears. However, the Arduino software itself can communicate with the board just fine, accepting uploads, operating devices, etc., so I do not think it can be either the USB cable, the board, or the PC. Restarting the PC and re-installing the driver have made no difference.

    Comment by Kirstin Darke — 2012 March 15 @ 08:10 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: