Adventures in Science: Arduino Control Flow

We examine the computer science concept of how a single-threaded, sequential program flows in Arduino.

Favorited Favorite 3

This week, we examine a slightly different type of science: computer science! We will cover concepts like what a compiler does (in a broad scope), what is meant by sequential programming, and how to use a flow chart to diagram a program.

I found it difficult to discuss many of these concepts without showing examples, which meant picking a programming language. Given the popularity of Arduino with beginners and our audience (especially as an introduction to embedded systems), the Arduino language (OK, it’s really C and C++ inside a framework) seemed like a good fit.

In the video, I go over how an Arduino program executes sequentially and how it can be visualized in flowchart form. My hope is that these programming videos can be used as supplemental material in a student’s computer science class or by people learning on their own.

If you would like to follow along, here is an in-depth guide on installing the Arduino integrated development environment (IDE):

Installing Arduino IDE

March 26, 2013

A step-by-step guide to installing and testing the Arduino software on Windows, Mac, and Linux.

I know that many of you are likely well-versed in programming, so the video will be a rehashing of the absolute basics. Do you have any suggestions for teaching computer science concepts to beginners? Which terms are important to be defined, and what analogies would you use?


Comments 5 comments

  • Hi Shawn!

    I think it is a pretty good place to start. A thought just occurred to me as a simple exercise to introduce more complex ideas: blink once, wait, then blink twice, wait, blink three times, wait, then start over. You can do this “straight line”, or you can do this with loops and variables (to count the blinks), which is more “advanced”.

    My biggest complaint is with the Arduino IDE, in that it is missing what I consider to be by far the best teaching tool for the beginner, and that’s any provision for “single stepping” through the code. In terms of debuggers, it has all the modernity of the mid-1970s. It can be wonderfully instructive to “watch” a few variables, and have the debugger single step through the program – it really allows the beginner to see exactly what’s happening in their program.

    Back when I was working on my Computer Science degree (1970s), we spent many an hour with either a white (or black) board, or some scratch paper, “manually” single stepping through the actions in compilers, keeping track of all the variables, to understand how they worked.

    BTW, I’ve since written several (highly specialized) compilers. The best description I’ve come up with for beginners is that “it takes something a human can read and translates it into the ones and zeros that the computer can understand.”

    • Good idea with the example, thanks! I think it’s a good on loops (for, while).

      I agree that the lack of step-through debugger is a problem. In fact, it’s why a number of colleges refuse to use Arduino in their embedded courses (based on my conversation with professors). I know that many of the microcontrollers on the popular Arduino platforms (e.g. ATmega328p) do not have an in-circuit debugger, so it wouldn’t be possible anyway. However, I’m surprised that an emulator hasn’t been created that allows for it (if you know of one, please let me know!).

      • Not having hardware support for a debugger puts a lot more load on the software side of the debugger, but it does not preclude it. Basically, the debugger has to be set up to “update” the program in the target device for each and every statement “stepped” through – and returning variable values to the debugger. The only real hardware requirement is a connection to the host at runtime, e.g., the USB serial port of the Arduino. (Yeah, that would be a problem for things like the Trinket that don’t have a “real” serial port, but things like Uno, RedBoard, or ProMini do support the serial monitor would work.) When using this approach, it’s usually a lot faster to set “software breakpoints” at various key points in the program, but it’s still the same approach. We can fake this manually by using a whole slew of Serial.println() and Serial.read() statements (the latter being looped on until non-negative), but this is WAY beyond the capabilities of the beginner who needs the “single step” the most.

        Off on a different tangent: A few minutes ago I thought of a suggestion for a future episode: The value of keeping some sort of “notebook”/“log book”/“journal”/“diary” with notes on the projects and experiments, so you can go back and review them later. (I have a tendency to have a lot of different projects going at once, and it’s a BIG help to be able to review my “journal” notebook to see what I last did on each project, or be able to look back and say “oh, yeah: that was the command I used to accomplish that”, etc.)

  • Nice video. I’m going to see if we can use it with any classes for our maker group. Flow charts like this make more sense to me for simple, single threaded platforms than state machine diagrams.

Related Posts

Recent Posts

Tags


All Tags