MAS.863: How To Make (almost) Anything
Kreg Hanning
Lifelong Kindergarten Group
Fall 2016
Week 12: Interfaces and application programming

This week in HTMaA we were tasked with writing an application to interface with a device that we made in a previous week. My plan during week 9 was to connect my step response controller to Scratch but unfortunately I ran out of time. I thought that this week would be a good opportunity to finish up the project.

The first task was to make sure that the serial data being sent from the controller could be easily interpreted by my application. Each sense pin will need to send 4 bytes to communicate the high and low values so I will need to send 4 x 8 = 32 bytes for each reading.

This is the C, header, and Makefile for the controller board.

Once I had the firmware done, the next step was to start receiving and interpreting the data in Scratch. Fortunately, Scratch has a browser plugin for communicating between Scratch and a serial device. I wrote a Scratch extension that received and parsed the serial data and then converted it into blocks that could be used in Scratch projects.

Unfortunately, the extension proved to be rather slow (I think due to the 8 inputs) and the Scratch device plugin does not support Linux. Because of this, I decided to write a Python application that would receive the serial data, parse it, and send it along to Scratch via a websocket. To accomplish this task, I used Python 3's websockets package.

Here is the Python script and Scratch JavaScript extension.

Scratch character responding to the controller button being touched.