Showing posts with label Scratch. Show all posts
Showing posts with label Scratch. Show all posts

Scratch your Arduino?

Why, yes you can. There are several projects I've played with that let you use the graphical Scratch-style programming to talk to your Arduino, which is excellent news for younger kids who are not ready for much typing or the "curly-bracket/semicolon" lifestyle just yet.

There are two different approaches to graphically programming an Arduino. The first is to run a sketch on the Arduino which talks to the Scratch program, passing commands and data over the serial port. The sketch is called Firmata, and requires the Arduino be attached to a computer running a server program to link Firmata with Scratch. Both Scratch for Arduino (S4A) and the newer Scratch to Arduino (S2A) use this approach. S2A seems a bit harder to set up initially, but works with the newer Scratch 2 Offline Editor.




The other approach is to translate the block structure into Arduino C-code for upload using the IDE. This might be a better option for older kids who are ready to make the transition from blocks because they can see the direct C-code equivalent. Both Blockly Arduino and ArduBlock projects take this approach, with ArduBlock actually integrating into the Arduino IDE making the transition from blocks to C-code at the press of a button. Blockly Arduino has the advantage of being web-based, so no installation is required, and the base project, Blockly, has some fun, non-Arduino, online programming tutorials.




I showed ArduBlock to one of the younger Teen Makers at the library program and he quickly programmed an LED to turn on or off at the push of a button. That may sound trivial on paper, but in practice, it is not. He had used Scratch before, and integrated some sophisticate techniques such as using flags to track state and a while loop to debounce the button.

Here is the equivalent C-code:

All of these tools make programming the Arduino a bit easier for younger programmers. They each have their strengths, but if you had to pick one, I'd go with ArduBlock because it is open source and integrates with the Arduino IDE. This makes it both easy to set up, and easy to use.

Makersbox Boot Disk

For the Corvallis Teen Maker program, I'm using a number of hand-me-down laptops. I wanted to install a common environment on them so that no matter who got the laptop, they would be able to program an Arduino and have all the sample code available in the same place. It makes life easy on both the teens and the mentors.
I'm a big fan of Open Source Software, and my current favorite version of Linux is Mint, which is based on Ubuntu.  I created an image on a host computer using VirtualBox and installed all the things I thought a budding hacker learner might need. I used Remastersys to create a bootable Live DVD, which not only lets me install the OS on the laptops, but provides a disk the kids can take home! Booting on the Live DVD gives them the same layout and tools they see at Teen Makers without making a change to their hard-drive or original OS. Just remove the disk and reboot, and you are back where you started.

Scary Startup Screen!

Here are the highlight of what comes on a Makerbox Boot Disk:
  • Arduino, the software and libraries we need to program the microcontroller and example code from the Sparkfun Inventor Kit.
  • Processing, which is an Arduino-like programming environment more suited to making visual graphics.
  • Fritzing, software that lets you design electronic projects and layouts.
  • Python, my favorite easy-to-learn software.
  • Scratch, a graphical programming environment great for younger learners.
  • Stellarium, an awesome planetarium program that will let you figure out if that bright star at sunset is Arcturus or Jupiter!
  • Inkscape, my favorite scalable vector graphics editor.
  • GIMP, my favorite image editor.
  • Reeborg, a fun way to learn programming in either Python or JavaScript.
  • LibreOffice, an open-source replacement for the Microsoft Office suite in case you need to make a presentation for school.
  • Tux Typing and Klavaro so you can get your keyboarding chops up to snuff.
  • Firefox web browsers with links to all my favorite websites like www.themagpi.com and learn.adafruit.com.
Hopefully after reading this, parents will be convinced to let their kids try it at home. A user would need a password, internet access, and some Linux skills to be able overwrite the original OS, which after seeing how cool Linux is, they might ask me to help them to do anyway!

If you want to see what using Live CD is like, head on over to linuxmint.com/download.php and download yourself a disk! Its free.

Maker Festival Project Details

For the Maker Festival, I wanted to introduce people to both Arduino and Raspberry Pi and show how they can be programmed to interact with the physical world. In order to reach as young an audience as possible, wanted to use MIT's Scratch programming language as well as the native methods for both board (C & Python).

For the Arduino, Scratch for Arduino (S4A) allows interfacing the projects together.  A dedicated sketch is loaded on the Arduino which broadcasts and receives the necessary Scratch hooks over the serial port. This is a bit limited in that all the ports are hard-coded, but for a small project like three LEDs, it is fine.
For the Raspberry, there is a python library written by Simplesi which allows communication between the Scratch hooks and the GPIO pins. Like S4A, the input and output ports are hard coded, but again, this is minor for a small project. Python is also easy enough to read to modify the library if needed.

Scratch
Python IDLE
Arduino IDE
For all the various methods of getting LEDs to blink, I had basic programs set up to blink a single LED that I could load between each new student. After walking them through the basics, I would challenge them to go farther, with the stoplight behavior as a suggestion.
A young man named Kai took my basic stoplight demo well beyond my expectations while I wasn't looking. He drew in a road, added a car, and tied it to the stoplight broadcast such that when the light turned green, the car took off! It actually took me a minute to figure out what was going on.

Here are links to the three "Intro" sheets I had available depending on which board or language was used:

Overall, I thought this exhibit went well and met my goals of introducing a wide range of ages to the available methods of both popular boards. There was a great deal of interest from both the children and adults.

I wrote more about my overall experience at the Maker Festival on another post.