BASIC Stamp board review

While browsing through a local Radio Shack the other day, I noticed some BASIC Stamp boards in stock. Since new dev boards are always interesting — and since I’ve been programming in BASIC since the days of the dinosaurs early ’80s, I decided it was time I tried one. I certainly like microcontrollers, and for better or worse, BASIC is still my “native” programming language. A BASIC Stamp board is therefore a no-brainer, right?

Well, yes and no…

Setup:

Physical setup of the board is pretty straightforward. To save on cost and packaging, no software is included; you download it from Parallax’s site. Bonus points for environmental responsibility: check.

The BASIC Stamp 2 "Home Work Board USB" in its package. (Click for larger.)

Unfortunately, Parallax’s site doesn’t have a very intuitive process for locating the board drivers. The directions on the package steer you to www.parallax.com/rt (which I won’t link to and add to the confusion), but that page just offers vaguely-helpful instructions on how to find your product number and type it in. Doing so lets you locate the product page for the specific board you have. Hunting around on that page turns up a link to Parallax’s common software download page for most or all of their BASIC stamp boards (begging the question, why did I have to enter in the product number??)

Once you locate the BASIC Stamp software download page, things fortunately get a lot easier. The page has an easy, obvious “1-2-3” chart front and center. Nice! Click on the first link, install the software, and connect up the board. Simple.

The box contains the board, a cable, jumper wires, and non-skid feet. (Click for larger.)

Download the software? Check.

Run the installer? Check.

Plug in the device? Check. (The USB drivers loaded nicely on  Windows 7/64bit.)

Launch the software? Check.

Run examples? Uh oh. Unlike the easy “Examples” menu in the Arduino IDE, Parallax’s Basic Stamp Editor software starts up with its default directory in C:\Windows. This is not only useless (that’s not where the examples are or where your programs ought to go) — but potentially dangerous if people start digging around in the Windows directory structure. These boards are marketed to primary and secondary-school students, and this is asking for trouble.

Guessing that the correct location was in the “Program Files (x86)\Parallax” directory (it was), I soon was in more or less the right place. The next challenge was to determine which version of BASIC stamp the board had. This, again, wasn’t specified. A quick check of the packaging turned up a reference to a “BASIC Stamp 2 chip,” so I went with that. (The actual chip turns out to be a garden-variety PIC, presumably with special firmware.)

 

The star of the show turns out to be a Microchip PIC16F57. (Click for larger.)

I fired up a random example from the “BS2” folder — a “connection test” program. It ran, but reported no boards found (even though the board’s lights blinked when programming it.) I tried a few more examples with the same result — no board found.

At that point, I decided to try applying 9V to the battery terminals, theorizing that the board didn’t get its power from USB (like the Arduino boards do.) This worked, and the board was soon running the connection-test example correctly.

Programming

I loaded up another example — “HIGH_LOW.BS2” — and ran it. A LED that I had connected between P0 and Ground blinked dutifully at 1Hz. Success. I modified the delay times to 100ms instead of the default 500ms, and the LED was soon blinking at 5Hz. So far, so good.

Performance

I decided to see what the board could do with the throttle wide open. I commented out the “pause” lines (the board’s dialect of BASIC uses the usual apostrophe-for-comment convention), and re-ran the program. The LED came on dimly (as expected), and the oscilloscope showed a high-frequency output. Dialing in the ‘scope readout showed an output at roughly 1.775kHz, with a 25% duty cycle.

The output from a simple "high, then low, then repeat" program. (Click for larger.)

Writing this code in native PIC assembly would produce the same 25% duty cycle: One instruction would be needed to raise the output; one more would lower it, and a “GOTO” instruction to loop back to the beginning would take two cycles (due to the way the PIC uses a simple two-stage pipeline to execute code.)

A PIC clocked at 8MHz would execute code at two million instructions per second (2 MIPS), counting GOTOs and such as two instructions. If this high/low/repeat code were written in assembly, it would take four instruction cycles to execute, resulting in one cycle every two microseconds, or a frequency of 500kHz. The observed frequency, by comparison, is some two hundred eighty times slower than this theoretical maximum. (…and most PICs, including the 16F57, can run much faster than 8MHz if need be.)

That’s not merely slow — that’s glacial! Even the Arduino executes naive C++ code faster than that. Unless the PIC is being clocked extraordinarily slowly, either it’s running the BASIC code as an interpreter (a bad idea), or the compiler is very inefficient.

This calls for more investigation, but my guess is that performance is not high on the priority list for the BASIC Stamp.

 

Posted in BASIC, Coding, Digital, Electronics, PIC Microcontrollers, Reviews, Toys | Leave a comment

Drill Bits Of Unusual Smallness

One of the fun things about technology is that there are so many diverse subfields that nobody can stay current with all of them. Occasionally, you come across a tool or process commonly used in another field that seems amazing to those not used to it.

One of the students where I work recently brought in a set of micro-sized drill bits. These are a fraction of a millimeter in diameter; the smallest chuck for my Dremel tool wouldn’t hold them. Even the drill bits for the LPKF PC board milling machine that we use are larger.

I don’t know what they’re generally used for (pilot holes for micro-sized screws?), but whatever it is, it involves extraordinary precision!

The set of micro-size drill bits. (Click for larger.)

A detail view of one of the smaller bits. (Click for larger.)

Thanks for sharing, Mike!

 

Posted in Metalworking, Tools | 1 Comment

A Confusion of COM Ports

I like serial-port communications, but this is ridiculous.

Whenever a new USB serial device is connected to a Windows computer (and/or apparently whenever an existing USB serial device is moved to a new USB port), Windows assigns it a new COM port number. Back in the good old days, there was generally COM1 and COM2 — typically for a mouse and modem — and the addresses were set in hardware with jumpers or DIP switches.

Fast-forward to today’s environment, including Arduinos, Bluetooth serial devices, USB-to-serial cables, and others. I’m up to COM29 with no end in sight. Most of these are the ghosts of various devices plugged in to various USB ports. The drivers are all still installed, and they’ll be redetected when plugged back in.

Deleting unused COM ports in Windows isn’t as straightforward as perhaps it should be, since Device Manager doesn’t list non-present COM ports by default. Fortunately, an article on Microsoft’s Knowledge Base shows how to change this. Here’s how:

  • Open a command prompt
  • Type      set devmgr_show_nonpresent_devices=1    <enter>
  • Type      start devmgmt.msc  <enter> to start Device Manager
  • Click     View –> Show Hidden Devices.
  • The COM ports are listed under “Ports (COM & LPT).” Have at ’em!

Incidentally, this solved the mysterious   “avrdude: stk500_getsync(): not in sync: resp=0x86” error message I was getting when uploading an Arduino sketch. Apparently even the Arduino IDE had had enough.

 

Posted in Arduino, HOW-TO, System Administration | Leave a comment

Electoral College Reckoner

The US Presidential election system is not the most straightforward thing in the world. The President is not directly elected by popular vote, but is instead elected by the members of the Electoral College. These members are chosen by the individual states, with each state receiving as many electors as it has members of Congress. Most states select their electors on a winner-takes-all basis. Maine and Nebraska use a split system whereby some electors are determined by popular vote and others are determined by the popular vote winner in specific electoral districts.

Since there are five hundred thirty eight members in the Electoral College and a clear majority is needed, two hundred seventy electoral votes are needed for a victory. This has various effects on the Presidential campaigns — mostly involving candidates spending a lot of time and money courting votes in large “swing states” (states with a large number of electors where the outcome is uncertain.)

Various pollsters and pundits have tried to predict the outcome of the election. Nate Silver’s “Five thirty eight” blog has come up with an estimate of the odds of each candidate winning each state’s electoral votes (including Congressional districts in Maine and Nebraska.) From this, it’s possible to predict the outcome of the election, using Monte Carlo analysis.

Using Five Thirty Eight’s data (text file contains district abbreviation, odds of a Democratic victory in that district, and its number of electors for this year), I ran the simulated 2012 Presidential election (FreeBASIC code) one billion times. (Hey, if it’s worth doing, it’s worth overdoing!)

The results are encouraging for a secular, liberal/libertarian geek like me:

Runs: 1,000,000,000
Democratic victories: 960,093,075
Electoral College ties: 2,608,646
Republican victories: 37,298,279

Democratic victory %: 96.01%
Electoral College tie %: 0.26%
Republican victory %: 3.73%

Here’s a histogram of the relative probability of each number of electoral college votes for President Obama. (Anything 270 or greater is a Democratic victory.)

A histogram of the projected probabilities of the Electoral College outcomes, according to the simulation. (Click for larger.)

I hope Mr. Silver’s analysis is correct. We really don’t need another four years of corporate cronyism and Bible-thumping anti-intellectualism.

Posted in BASIC, Coding, Current Events, Digital Citizenship, Math, Science | Leave a comment