Arduino programming basics
Chapter 9 of the Tutorial Kit Manual promise to deliver an introduction to the basics of programming in Arduino C. Where the previous chapter clocked in at a modest seven pages, this one covers 90! So I'll not be tackling it in one go, I guess.
It starts with a very fundamental introduction: bits and bytes (and nibbles). Important as they are, it's probably not where I would start off a complete beginner. It then rattles in short order through:
- bits and bytes
- procedural programming
- sequential programming
- interrupt-driven program flow
- Arduino program structure
complete with discussions of saving memory states and libraries - which if you feel you have to explain bits and bytes, are being introduced rather rapidly, and without examples! They do, though, stress the importance of inline documentation, which is a plus point.
Then the manual gets straight into a second program (
SecondArduinoProgram). This contains two statements that we might expect to produce some output:
Serial.print(). Running the program generates the expected flashing/blinking LED, but no visible output. This is a bit confusing. I happen to expect that you might need some more code to capture the Arduino's serial output and write to a file, but a beginner may not. There's also an (unmentioned)
Serial Monitor as part of the IDE, which sort of lets us see the output, but doesn't manage this perfectly:
It also closes every time you run a new program, and has to be recalled. This does not, as you can see, clear the previous output correctly.
The text then reminds the reader to "pay attention to parentheses, semicolons and correct spelling", so they probably are expecting a complete beginner, and this oversight is a bit of a pity, and may be discouraging.
Only then, in section 9.4, are we greeted with the section called "Getting Started with Arduino Programming", taking us through:
- comments, braces and semicolons
- data types and variables (distinguishing local and global), including a short program to demonstrate arrays (writing to serial out, again)
- program control
- functions and (sub)routines
- type casting
- a list of mathematical functions (
sin()and so on)
before telling us about the serial interface, and how to capture data from a UART (without defining a UART).
The manual then embarks on 30 pages of electronics experiments with the Arduino.
I'm a bit disappointed with the structure and teaching in this chapter. I'd have been looking for a "Hello World" type program to establish the student with some basics in input and output (and the
loop() Arduino model), with clear instructions on how to visualise the serial output from the Arduino, and then progressing through variables and program control up to functions. I can get quite a bit from the text, and live with the omissions and weird order because I have some experience in other languages, but I feel for anyone who tries their hand at programming for the first time, with this book.