1. Introduction

“scratch-sherpa” implements the protocol of the Scratch Sensor Board (also known as Picoboard), as supported by the educational Scratch programming environment. The original sensor board, e. g. as offered by SparcFun, provides 8 sensors: a slider, a light sensor, a sound sensor, a push-button and 4 general purpose ADC inputs available to the user.

The protocol used is very simple (much simpler then the uSherpa protocol). Scratch polls the board regularly by sending one byte containing 0×01. The board then sends back 9 words (18 bytes). The first word is the header, the next 8 represent the sensor readings for each channel (including the channel ID from 0..7). Scratch expects the values to be 10bits wide (since the original board, as well as the MSP430 do have 10bit ADCs). Scratch then converts the raw 10bit values (ranging from 0 to 1023) to a range between 0 and 100 for readings from an ADC, or to TRUE/FALSE for readings from an digital input.

Sensor Board, Scratch

Sensor Board, Scratch

The baud-rate used in Scratch to communicate with the board is hard coded to 38400 Bauds within Scratch. Since the build in serial to USB converter of a Launchpad is only able to provide a maximum of 9600 Bauds, an external serial to USB converter needs to be connected to P1.1/P1.2 of the Launchpad. Every FTDI or Prolific will do the job. If you use the Raspberry Pi (which comes with a pre-installed Scratch version), you could directly wire the RX/TX pins from the Launchpad (P1.1 and P1.2) to the Pis expansion header.

The sensor mapping chosen on the Launchpad differs slightly from what you get on the original board. This is mostly because the ADC channels of the Launchpad are located on port 1 (P1.0 to P1.7). Also the RX/TX (P1.1 and P1.2) and the build in user button (P1.3) as well as the build in LEDs (P1.0 and P1.6) are located on port 1. Thus, when using P1.3 as the sensor board button, P1.0 as status LED and using P1.1/P1.2 for serial communication, only four ADC channels are left. This channels (P1.4..7) are mapped to the user ADCs named RESA..D. As mentioned before, the build in button on P1.3 is mapped to button. The slider is emulated through two digital buttons on P2.0 and P2.1. One button increases the current slider value, the other decreases it. Since I did not have light nor sound sensors at hand, I mapped the LIGHT input to an user definable digital input (with internal PULL-UP enabled), and the SOUND input to an ultrasonic range finder which could be read out digitally.

The complete mapping as done in “main.c” is like so:

	#define BUTTON					PIN_1_3		// Launchpad build in button
	#define RESA					PIN_1_4		// MSP430 ADC CH4
	#define RESB					PIN_1_5		// MSP430 ADC CH5
	#define RESC					PIN_1_6     // MSP430 ADC CH6
	#define RESD					PIN_1_7     // MSP430 ADC CH7

	// simulate slider with two buttons (soft-slider)
	#define SLIDER_UP				PIN_2_0		// DIGITAL in w. internal PULL-UP
	#define SLIDER_DWN				PIN_2_1		// DIGITAL in w. internal PULL-UP

	#define LIGHT					PIN_2_2		// DIGITAL in w. internal PULL-DOWN
	#define SOUND					PIN_2_3		// DIGITAL in, floating, 
									// drive high before read (ultrasonnic sensor SRF05)

Note: Two more ADC channels could be easily freed, by not using P1.3 for the button (but e. g. 2.4), and not using P1.0 for the status LED (but e.g. 2.5). The pin assignments and functions could be easily changed in the file “src/main.c”.

2. Hardware

Schematic of Sensor Board

Schematic of Sensor Board

The parts used are:

Sensor Board, Launchpad

Sensor Board, Launchpad

3. Project Directory Layout

4. Prerequisites

Also make sure “libserial” and “libsherpacore” libraries are already successfully compiled.

5. Getting the Sources

The sources are available on github:

git clone

6. Getting a P recompiled Firmware Binary

The latest firmware binary for scratch-sherpa in various formats could be downloaded here.

7. Compilation

To compile this firmware issue:


This will produce the firmware “firmware.*” in various formats under the “bin” sub-directory.

8. Flashing

	make flash-target

For the MSP430 target on a Launchpad, the “mspdebug” tool is used for flashing.

9. Basic Usage

Connect the Launchpad with the uploaded firmware to the USB port by using an external USB to serial converter. To acquire the sensor values from within Scratch, see the Picoboard getting started guide.

On github you also will find some Scratch Examples:

Scratch, cat-walk example

Scratch, cat-walk example

Scratch, fliwatuet example

Scratch, fliwatuet example

Scratch, one-player-tennis example

Scratch, one-player-tennis example

Scratch, two-player-tennis example

Scratch, two-player-tennis example

Leave a Reply

You must be logged in to post a comment.