by Jon Williams
Stamp
Putting the Spotlight on BASIC Stamp Projects, Hints, and Tips
Stamp Applications
No More Coffee Spills
Ideas more crazy than this have
become successful products!
Many times, it’s worth doing a project just for the
experience of doing it.
Leaning To and Fro
Have you ever noticed yourself when you’ve noticed
yourself? I seem to do it all the time, suddenly
noticing some behavior I had that — until that
very moment — had been completely unconscious of.
Often times, the thing I notice is quite humorous. Like
most humans, I’m a creature of habit. My typical daily
habit is to wake up, check Email quickly (in case there’s
been an overnight customer emergency), jump on the
treadmill for about 30 minutes, grab a bite to eat, and
then pop by the neighborhood Starbucks for a cup of
coffee and a quick chat with a very pleasant lady named
Lindsay.
On a recent return trip from Starbucks, I noticed
myself doing something that actually made me laugh.
While steering with my left had, I would reach down with
my right hand to adjust the coffee spout such that coffee
would not slosh out while I was cornering. Honestly, I
laughed out loud, then immediately thought that, if I had
an accelerometer, a stepper motor, and a BASIC Stamp,
I could keep both hands on the wheel. An idea was
born ...
Was it a practical idea? Well, probably not — and I’m
certainly not going to tear apart the center console on my
new SUV to install such a device — but the exercise in
designing the circuitry and code to
solve my coffee sloshing problem is
still worthwhile. I receive a lot of
Emails asking how one gets “so
good” at programming the BASIC
Stamp microcontroller. Like getting to
Carnegie Hall, it takes practice,
practice, practice. Imagine how many
tens of thousands of practice shots
Michael Jordan shot before and
during his career; every one of them
served to prepare him for all those
championships. I guess my point is
not to wait for a “real” project to
improve your programming skills.
SEPTEMBER 2004
If you’re new to the BASIC Stamp microcontroller or
weren’t around for my article in the November 2003 issue
on using GPS, you may be wondering how we’re going to
take the output from an accelerometer and use it to point
the spout of a coffee cup lid.
To be honest, it’s dirt simple: We’re going to use the
ATN function. ATN (arctangent) returns the angle (in
binary radians: 0 to 255) that points to the intersection of
two vector values.
The first thing to do, then, is to read the
accelerometer outputs (x and y axis) to establish the
g-force vectors. You may remember from our previous
work with the MEMSIC 2125 that a 0g output is a five
millisecond pulse. Negative g-forces are shorter than five
milliseconds; positive g-forces are longer. Reading the
pulse outputs is no trouble; we can use PULSIN to do it.
Here’s the trick: The resolution of PULSIN gets better as
BASIC Stamp modules get faster. Code that will work
properly with a BS2 module will not return the correct
results when using the BS2p.
You know where I’m going with this: conditional
compilation. I covered it briefly in the past and I think it’s
good to remind ourselves that this feature is now available
in the Version 2.1 compiler. So, what are we going to do
Figure 1. Memsic 2125 Connections.
Figure 2. ATN Output.
89