Category Archives: BASIC Stamp

How to Actually Take My Course

I was reading through my blog earlier today and to my horror, I realized that there is really no direct link from my blog to my course. Considering the amount of time and effort I poured into “Introductory Electronics,” I think it’s important that there’s some sort of easy-ish way (read: step-by-step directions) to access my course on the blog.

So here they are:

  1. Make an account on Global Classroom’s K12Virtual section.
  2. Go to my course.
  3. Buy a Basic Stamp Activity Kit.
  4. Learn lots and lots of cool things in very little time!

So now I suppose you’re wondering if my course is right for you. The answer is yes. Okay, that seems a little broad. You’ll probably enjoy the course a lot if you:

  • Are interested in how computers and other modern electronic devices work
  • Want to build your own electronic devices
  • Have little previous experience with electronics and circuitry
  • Would rather learn from video than from text
  • Are a savvy computer user

Regardless, there’s no risk in watching a few videos before you buy a BASIC Stamp Kit: the course is absolutely free.

Summer Synopsis

This summer, I spent most of my time at work creating a thirteen-part video course about electronics. I became quite comfortable in front of a camera and even though I didn’t have a teleprompter, I came up with a fairly engaging final product. The company president asked me to do a presentation to anyone willing to listen about the four projects I’ve worked on over the past two summers. To present my course, I decided to make a video about what I’d done. It highlights some of the best parts. You can watch it here:

Better yet, if you want to take my course, you can at the K12 Global Classroom once I make it publicly available.

Cloning ThinkGeek’s Annoy-a-tron with a BASIC Stamp Homework Board

I’m working on a course at work right now that aims to get people (high school students in particular) interested in electronics. The project uses a BASIC Stamp homework board for projects, and one of the ideas I had for a project was a copy of ThinkGeek’s Annoy-a-tron. The kit I bought came with a piezo buzzer and PBASIC (the language used to program the Stamp) just so happens to have a FREQOUT command that you can use with it. I quickly got to work, coming up with this schematic:

Pin 11 is connected to the anode of the piezo buzzer. The cathode (which should cross the center of your homework board’s breadboard) is connected to Vss (the ground). Here’s what it actually looks like once it’s wired up:

With the (extremely simple) wiring complete, we can change our attention to the (almost equally simple) code. The Annoy-a-tron beeps once every 2-8 minutes at a frequency of either 2kHz or 12kHz. The speaker that came with the kit seems to perform best at around 4.5kHz so we’ll use that. As for the time, we have a problem. Why not just randomize a variable with time in it, pause for that long, then loop back again?

The trouble is that the largest data type that the Stamp I have supports is a 16-bit word, which has a maximum unsigned value of 65,535. The PAUSE command accepts an argument in milliseconds. Now what? Loop.

The solution I devised is able to replicate the Annoy-a-tron’s 2-8 minute random interval quite well. Here’s how it works:

  • The RANDOM command is used to obtain a random 16-bit value.
  • We then convert it to a value between 10,000 and 40,000 (in intervals of 10,000). How? The modulo (mod) operator, which is // in PBASIC. The modulo operation finds the remainder when one number is divided by another. A // N can have any value from 0 to N-1, so (A // N) + 1 can have any value from 1 to N. If that gets multiplied by 10,000, the result is any number from 10,000 to N(10,000).
  • Therefore, to get a random number from 10,000 to 40,000 in intervals of 10,000, we use the modulo operator on the random with an “N” value of 4, add 1 to it, and multiply by 10,000.
  • This number is used in a PAUSE command.
  • This pause command is looped 12 times.
  • The result can be 2, 4, 6, or 8 minutes.
After the delay, a beep is played for a enough time to be annoying but not long enough to be discovered. I decided on 1.5 seconds (1500ms). The code was easy to write once I figured out how the loop would work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Running." ' Avoid error on some PCs' debuggers.
time VAR Word ' Used to store time interval.
i VAR Nib ' Used for the FOR...NEXT loop.
FREQOUT 11, 1500, 4500 ' I like having a startup beep.
DO
  RANDOM time ' Store a random 16-bit value in time
  time = ((time // 4) + 1) * 10000 ' Get the random interval. Will be between 10 and 40s
  FOR i = 1 TO 12 ' We start at 1 because 12 is included; this will be executed 12x.
    PAUSE time ' We pause for the same 10-40 second interval 12 times to yield 2-8 min.
  NEXT
  FREQOUT 11, 1500, 4500 ' Play the annoying tone.
LOOP ' Start the whole thing over.
END

There you have it! Run this code on your BASIC Stamp, hide your enormous board, and hope nobody smashes it! I have not used this long enough to know how long a 9v battery can power it, but I am sure it is a more-than-adequate amount of time to get your point across. The biggest issue I have seen with this code is that the Stamp’s pseudo-random number generator isn’t very good. In fact, it generates numbers in the same exact order every time. You’ll never be surprised. Still, for being so simple, this circuit is a heck of a lot of fun. Happy annoying!