Using the Maplin Robotic Arm with Scratch

robotarm-loadtest

Lifting some heavy weights

Maplin is currently selling a robotic arm for £29.99. The arm comes in a box and it needs to be assembled, something that takes approx 2.5 hours. The arm can then be connected to a computer using a USB cable (don’t forget that it also needs 4 D-batteries!). The arm is pretty basic: it has 4 joints and a clamp to hold up to 130 g, but there are no position sensors. This means that you can only move the arm by telling a specific joint to move in a certain direction for a certain amount of time. Nevertheless, I think it is an interesting learning experience and a starting point for other projects (see this video to add position sensors using potentiometers: https://www.youtube.com/watch?v=HDy9jEGMk_k)

In terms of software, in spite of what the box says, if you are happy to run a small Python program, the arm is (unofficially) compatible with more or less any operating system that can talk to a USB port, given that the protocol has been reverse engineered. There are examples online using an Xcode project on Mac and Python on a Raspberry Pi with Linux.

I thought that the arm could provide an interesting example for kids using the off-line version of Scratch 2.0 (and for me to learn a bit about writing Scratch extensions). The extension mechanism for the off-line version seems simple enough: you only need to build a basic HTTP server that acts and replies to messages sent by a Scratch sketch, as described in this document. Again, there are several examples online using a range of programming languages, including Python, as exemplified by this Scratch extension to control Arduino boards.

By taking inspiration (i.e., by reusing) parts of code from the links above I managed to put together the extension in an hour or so. The code is available here: https://github.com/fraimondi/pymarash

This is what you need to do to run the extension on Mac (but I suspect the steps are very similar in Linux. Let me know if you have it running on a Windows machine):

  • Download the off-line version of Scratch 2.0 (obviously…)
  • Make sure that you have Python on your machine (I’ve tested Python 2.7).
  • Make sure that you have pip (the package manager for Python). Then, execute pip install --pre pyusb to install pyUSB.
  • Make sure that libusb is installed. I’ve installed it using homebrew on Mac, on a Ubuntu machine you probably want to use apt-get.
  • Download the code from https://github.com/fraimondi/pymarash. You only need two files: pymarash_http_server.py and MaplinArm.json.
  • Connect the arm and make sure that it is turned on. Then, open a terminal and launch the server with python pymarash_http_server.py. You should get a message confirming that the server is running. Leave it there running.
  • Open Scratch and, while pressing down the SHIFT key, click on File. Select the last item “Import experimental HTTP extension” and select the file MaplinArm.json.

If everything went well, when you click on “More Blocks” you should see something like this:

Scratch-pymarashNotice that the dot next to “Maplin Arm” needs to be green: this means that Scratch can talk to the extension. As usual, the proof is in the pudding: https://www.youtube.com/watch?v=tbl3G_gvfjE

 

Leave a Reply

Your email address will not be published. Required fields are marked *


× 8 = eight

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>