How Mixing GUI and Spin Code Works

The S2 GUI software provides an easy way to program the S2 using graphical tiles. However, there are some limitations that come with the software. For example, you cannot directly control the I/O pins connected to the S2 Hacker Port using the GUI software.

In these cases, we need to use the programming language native to the S2 Robot’s Propeller microcontroller, Spin. A nice feature of the S2 GUI software is that you can easily translate the GUI worksheet to Spin code and add to it using the Propeller Tool.

In the case of the S2 Caroling Robot, the navigation and music code was written using the S2 GUI Software. When done, the worksheet looks like so:


Did you know? The Help Section of the S2 GUI software provides a wealth of information on the function and capabilities of each worksheet tile. You can access it by clicking the question mark button at the top of the screen.

While this worksheet covers the majority of the code for the caroling robot, we need to modify the Spin program in order to control the LEDs on the hacked Christmas tree. Do so by clicking the ‘View the Propeller program’ button in the top navigation bar.

This opens the Propeller Tool. The code translated from the S2 worksheet is found in the PUB Green and PUB Yellow sections, which correspond to the gear colors in the GUI worksheet

The PUB sections are known as methods in Spin. We won’t go into the specifics of the Spin programming language here, but if you want to learn more there are great tutorials available on

Adding the following code under the PUB Yellow method will blink the LED strands, alternating on and off between the strands connected to pins 5 & 3 and to pins 4 & 2.

The Blink method will then need to be called from our main program. We’ll want the LEDs to blink when the music plays so the code will be added after the robot is stopped, but before the music begins.

Since the Propeller is a multicore microcontroller, executing multiple tasks simultaneously is a breeze. The command cognew launches a new processor (or cog as they’re referred to in Spin), where Blink calls the Blink method and @ledstack sets aside program space for the processor to run.

@ledstack is then a variable declared in the VAR block at the top of the program.

You can follow this same process to customize the tune in your own Caroling Scribbler.