SMILEY’S WORKSHOP ☺
We test the code by intentionally sending scripts
with errors. When we click on each error macro, we see
the output shown in Figure 2. Note that the third line
shows that the first command was handled correctly since
it has no errors. Further note that the ‘Sixth test, no
terminator’ macro results in nothing showing on the
Receive Text box since the command_line_demo has no
way of knowing that we think we have sent it a valid
script. So, it sits spinning its wheels waiting for the
TERMINATOR character (hint — it isn’t a former governor
of California). This is not a rigorous validation of the code.
For one thing, it won’t catch improper use of the
SEPARATOR and TERMINATOR characters, but it is
certainly good enough for now. If you find a problem,
well, you’ve got the source code.
If we want to convert the demo to a real application
like the robot pick and drop we mentioned above, we
would modify the COMMANDS array as shown next:
const CMDS COMMANDS[] PROGMEM = {
{“UP”,move_up},
{“DOWN”,move_down},
{“LEFT”,move_left},
{“RIGHT”,move_right},
{“PICKUP”,close_gripper},
{“DROP”,open_gripper},
{“HELP”,help},
{0,NULL}
}
■ FIGURE 2. Catching script errors.
buy my C Programming book, Butterfly projects kit, and
the Virtual Serial Port Cookbook from the Nuts & Volts
shop mentioned previously. NV
We would write the indicated
functions: move_up(), move_down(),
move_left(), move_right(),
close_gripper(), and open_gripper().
Now, all you have to do is call them
with a command-line script. Simple,
huh? Well, I think so, and you are
going to see this thing a lot in the
coming months where I’ll use it for
lots of software and hardware micro
machinations.
Questions? As usual, if you want
to be helpful when you find a
problem or have a question, you’ll
need to put on your biohazard suit
and start a thread on
www.avrfreaks.net with the word
‘avrtoolbox’ in the title. This way, I’ll
probably see it. (First, read my blog
entry that will tell you why you need
the biohazard suit: http://smiley
micros.com/blog/2011/01/24/using-
an-internet-forum.)
;;; ;;;;
Cana Kit
www.canakit.com
;;; ;;;
USB-LOGIC
;;;; ;;;;;; ;;;;;;;;
DSO-NANO-V2
;;;;;;;;;;;;; ;;;;;;;; ;;;;;;;;;;;;
;;; ;;;
ASSEMBLED
Next month, I think we are going
to take a look at digital input and
output, so stay tuned and find out. If
you just can’t wait and want to get a
leg up on all this serial stuff and real
C programming for the AVR (while
helping support your favorite
magazine and technical writer), then
;;; ;;;
;;;;;;; ;;;; ;;;;;; ;;;;;;;;;;; ;;;;;
;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;
UK1104
;;; ;;;;;;;;;;;;; ; ;;;;;;; ; ;;;;;; ;;;;;;;;;; ; ;;;;;; ;;;;;;;;;;;; ; ; ; ; ;; ;;;;;;; ;;;;;;;
ARDUINO-STK
;;;;;;;; ;;;; ;;;;;;;; ;;;
September 2011 63