Tuesday, July 28, 2015

How To Get From Blocks to Text With Robotics Coding

So many rich block-based programming environments have become available during the last several years. The release of Scratch into the world by MIT Media Lab's Lifelong Kindergarten Group catalyzed the invention of similar block-based environments for all sorts of purposes and a revolution in novice learners' ability to use the building blocks of computer science to imagine and make things. Block-based environments provide the important affordance of building programs without making
syntax errors. They enable people to play with code with a degree of freedom text-based languages can't offer.
An important question educators are looking for answers to is how learners can make the successful transition from blocks to text. It's a question with an ironic twist given that Scratch is a visual representation of the Logo language, itself a text language with the intention of providing opportunities for play and exploration with computers.


I came across an illustration of that difficulty recently as I worked with a group of teachers as a participant at Constructing Modern Knowledge '15. We were using a Lilypad Arduino to make a system of LED indicators that would light up depending on light levels detected by a light sensor. We started with Scratch 4 Arduino (S4A) to get the LEDs to light and gather sensor readings, because the other teachers had little programming experience and this would allow them to understand how the program worked.
Scratch 4 Arduino
We got as far as making two LEDs light up at different light levels. But S4A had a couple of deal breaker limitations for our project, one, that it must remain tethered for the program to run and the other that the digital out blocks can only be assigned to pins 10-13, while the Lilypad has 2, 3, 9, 10, and 11 available for digital out connections, giving us only 2 of the 4 LEDs we wanted.
We realized we would need to switch to Arduino programming. Just to get the LEDs to turn on and to gather the light sensor values I helped the group write the pictured Arduino code. Adding nested conditionals was much harder to follow, much less know how to write for anyone with limited to no experience with Arduino coding. We finished our project with Arduino only because I have a lot of experience with it.


Ardublock is an add-on to the Arduino IDE. Once installed open the Arduino IDE and then open Ardublock through the Tools menu. I had dismissed Ardublock for a while because of some UI issues. There is an annoying double drag bug where you have to drag once to indicate you are dragging, then drag again to actually drag. Students get frustrated easily, so this is not good. They are slowly fixing things, though. I revisited Ardublock today and found it could actually have been a good option for my CMK team. It is not an environment that lets you go from the Scratch/Logo based concepts to Arduino, but really just simplifies and visualizes the Arduino environment, so that is some help for the novice programmer. As you can see from the program example, the blocks translate pretty well to readable code while allowing you to bypass the structural requirements of the setup function and declaring variables. I think the variable names could be more clear and extra punctuation, like those unnecessary nested parentheses, could be removed. Getting serial data is a little cumbersome. The "glue" block seems required just because they are concatenating print statements, but I would like to just send a variable value and you can't. Proper indenting doesn't happen automatically so you have to do that yourself, but that's a good habit anyway.

Tinker and GoGo Board

I've been using GoGo Boards for several years now after moving on from Super Crickets. They offer an open hardware experience for middle schoolers without the complexity and circuitry DIY of Arduino. A couple years ago a web-based Blockly environment was released that provides the visual interface for the Logo language. It requires a widget running locally on Mac or PC that connects the computer to the board. But the beauty of it is that students can play with the simplified language of Logo and make their board do what they want. 

Tinker.learninginventions.org blocks
Tinker Logo equivalent
Then they go to another tab and see what the text Logo equivalent is. Unfortunately they can't edit the Logo version, though that is possible in the locally run widget. So they could construct their program with blocks, then copy the Logo code and paste it in the widget window to edit further. That is complicated enough I haven't gone there with students. There is one big problem with GoGo Boards. You can't really get them as the old version 4 boards I have (pictured above) are only available through the dwindling inventory at the Slumberger Seed Store and the new version 5 is still in development.

Blockly/Python (Robot Mesh)

I did come across one exciting option recently, which I plan to pursue in the classroom with older (HS) students this year. Robot Mesh has a web based environment that allows you to use both Python (text) and Blockly (visual) code to make programs for the VEX IQ robot kit. The Blockly code allows you to "play" with program ideas and at the click of a button you can see the Python translation and begin to play with it as well.
Blockly Python


mBlock With Arduino

There's a new kid in town I discovered recently. mBlock is a Scratch 2.0 based download application that converts your Scratch scrips directly to Arduino code in the same window. You can download programs to the mBot robot or to several versions of Arduino. You can keep mBlock tethered to the robot so you can interact with screen elements and the robot, or you can download to the Arduino or robot and run it untethered. I have to play a bit more to see all the possibilities but so far it looks very promising. 

No comments :