microcontrollers for the model engineer

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

mklotz

Well-Known Member
Joined
Aug 29, 2007
Messages
3,047
Reaction score
27
Location
LA, CA, USA
I've long wanted to build a computer-controlled steam engine - to my mind the perfect marriage of antique and modern technology.

Now, I have some elementary theoretical and hands-on experience with electronics from my grad school days and years of building useful stuff - mostly with TTL chips (yes, I'm that old). However, I'm certainly no electrical engineer nor computer hardware expert and so I needed to educate myself about microcontrollers, which are the obvious choice for the project I'm contemplating.

So far, my efforts in that direction have been very rewarding and I wanted to pass along a bit of what I've learned to others who may be contemplating computer-controlled projects and are intimidated by the electronics involved in such an effort.

I bought the "BASIC Stamp Discovery Kit" from Parallax Corp. for $160.

http://www.parallax.com/Store/Micro...efault.aspx?SortField=ProductName,ProductName

Now before you stop reading because of the price, bear with me for a few paragraphs and you may come to understand why that's not as bad as it sounds.

This kit includes absolutely everything you'll need to hands-on learn about programming microcontrollers. It includes a manual (shown in the photo below) that will guide you through every step, even if you can't tell a resistor from a capacitor. (It's written at such a no-assumptions-about-the-reader level that it might even satisfy Zee.)

Before I get into the kit details, though, it's worth taking a few minutes to write about why you might want to know something about microcontrollers. Even simple timing and sequencing operations can require lots of components, serious electronic knowledge and some soldering skills to implement. Microcontrollers substitute simple programming skills for all that electronic know-how and solderless breadboards eliminate the need for soldering components plus, once a circuit has been built and evaluated, it can quickly be torn down and the components reused in the next exercise. The programming language is very similar to the old BASIC language - very conversational and easy to learn. The manual describes the language as simply and thoroughly as it describes the electronic details.

Ok, onward. Here's a photo of the board...

STAMP.jpg


At the lower left is a connector that is used to connect the board to your computer. My old computer had serial ports so my board has a serial connector. Since my current computer is all USB, I use a USB-to-serial port emulator cable. If you have USB ports, you can buy the board already set up to accept a USB cable.

To the right of the connector is the Stamp microcontroller. It looks like a small circuit board of its own and it plugs directly into the main circuit board. On this mini-board are a number of components - a clock generator, the interface to the computer cable, an EEPROM to store the program, some power control circuitry and, at bottom center, the actual microcontroller (the black rectangle about the size of a pencil eraser).

Aside: The mini-board is about the size of a large postage stamp, hence the name "Stamp" microcontroller.

At top left the large black rectangle is a rechargeable 9V battery that supplies all power for the board. (An input jack for an external power supply is provided on the board but, for desktop programming, it's easier to use a battery.)

At far right, the white rectangle is a solderless breadboard where you plug-in components to perform the experiments in the manual. I'll write more later about the stuff you see plugged into it.

The red-white-black cable leads to an ordinary radio control servo as used in RC models.
The board has plugs for attaching four servos directly and more can be added using the breadboard.

Some connectors, a power switch and a power-on LED round out the complement of stuff on the board.

How do you use it? The kit supplies you with a programming editor that you install on your computer. Using that editor, you write a program to perform the task(s) you wish to accomplish. Press the editor "RUN" button and the program is automatically downloaded into the EEPROM and stored there. Press the "RESET" button on the board and the program runs. My programs always run perfectly the first time out :) but, if you need to make corrections, simply make them in the editor and repeat the process.

I wrote a simple demo program to show a few things. The code looks like this...

Code:
' {$STAMP BS2}
' {$PBASIC 2.5}

'MICROCONTROLLER DEMO PROGRAM

p CON 15
s CON 12
d CON 250
i VAR Word
duration VAR Word
frequency VAR Word

DEBUG CLS
LOW 1

'Blink red LED seven times

FOR i=1 TO 7

DEBUG ? i

HIGH p
PAUSE d
LOW p
PAUSE d

NEXT

GOSUB switch_wait  'wait for the carbon-based computer

'operate bi-color LED ten times

FOR i=1 TO 10

HIGH 14  'red
LOW 13
PAUSE d

LOW 14  'green
HIGH 13
PAUSE d

LOW 14
LOW 13

NEXT

GOSUB switch_wait  'wait for the carbon-based computer

'operate the servo

DEBUG CLS,"CCW 10 o'clock",CR

FOR i=1 TO 150
PULSOUT s,1000
PAUSE 10
NEXT

DEBUG "CW 2 o'clock",CR

FOR i= 1 TO 150
PULSOUT s,500
PAUSE 10
NEXT

GOSUB Center

DEBUG "Continuous CCW motion",CR

FOR i=500 TO 1000
PULSOUT s,i
PAUSE 10
NEXT

GOSUB Center

GOSUB switch_wait  'wait for the carbon-based computer

'make some sounds with the piezoelectric speaker

FOR duration=15 TO 1 STEP 1
 FOR frequency=2000 TO 2500 STEP 20
 FREQOUT 9, duration, frequency
 NEXT
NEXT



DEBUG "all done"     'indicate program completed

END

'--------------------------------------------------------

switch_wait:      'wait for switch to be pushed

HIGH 1         'light yellow LED to indicate waiting

agin:
IF (IN0 = 1) THEN
 LOW 1
 RETURN
ELSE
 PAUSE 100
 GOTO agin
ENDIF

'-------------------------------------------------------

Center:       'drive the servo to its centered position

DEBUG "Center 12 o'clock",CR

FOR i=1 TO 150
PULSOUT s,750
PAUSE 10
NEXT

RETURN

Don't attempt to understand the entire program but do glance at the code so that you can see how natural the programming language is. It only has about fifty commands so learning it is a weekend's work.

The program is exercised in the video below. Once the program is started, it flashes the red LED in the upper right of the breadboard exactly seven times.

Aside: Building a circuit to flash an LED is no big accomplishment but building one to flash exactly a prime number of times would require some rather clever circuitry.

After flashing the LED, the controller waits for me to push the sequencing switch in the bottom center of the breadboard. It indicates that it's waiting by lighting the yellow LED at lower right.

When the switch is pushed, it flashes the two color (red/green) LED at upper left exactly ten times. (It's a bit hard to see the two colors in the video but they're there.) Then it waits on the sequencing switch again.

Next it exercises the servo, moving it to its extremes and center point and then executing a slow sweep (as would be used in an optical search implementation).

Finally, it plays a few sounds through the piezoelectric speaker - the round black cylinder in the middle of the breadboard.

[ame]http://www.youtube.com/watch?v=NI7-0pGZmTw[/ame]

Now think about it. That's a lot of controlling and manipulating for a breadboard that contains little more than five resistors, a few wires, and the controlled circuit elements. Try duplicating that level of control without a microcontroller and you'll get a feel for just how useful this device can be in your shop.

A few more words in this (already lengthy) monologue...

The Stamp has sixteen I/O ports, each separately programmable, so the capacity for controlling a serious number of operations simultaneously exists.

You will have noted that, during the video demo, the board was not connected to the computer. The board can be run in stand-alone mode - think of controller embedded in a project. Also, the Stamp can be removed from the board (carrying its program with it) and used in other breadboards or projects.

You can buy more Stamps from Parallax and use the board to program them. This makes the $160 price tag a bit more palatable.

When connected to the computer, the microcontroller can "talk back" to your computer, displaying messages, counts, and information it's acquired on a "debug screen" that is part of the editor. This raises the possibility of using it as a data acquisition or monitoring device.

I'm certainly not an electronic expert but I'll try to answer any questions you might have. There are certainly others on this board who know far more than I on this subject. Please feel free to correct any mistakes I've made or add to the information presented here.

Finally, I hope at least a few of you find this information useful.
 
Yeah, I love the microprocessors. I used a Basic Stamp several years ago to build an automatic controller for a surface grinder. It had a step motor on the table, you would push one button to move the table to one end of travel, then push a 'remember' button. Next jog to the other end of travel and push the remember button. The when you pressed GO it continued to oscillate between the two set positions.

If you get into Stamps be sure to look at the PICAXE series- they are essentially stamps, but in single chip form and cost between $2 and about $10.

I do agree parallax is a great source, and their docs are all free on the next and are all excellent.

 
mklotz said:
(It's written at such a no-assumptions-about-the-reader level that it might even satisfy Zee.)

Nicely hidden Marv. Found it anyway. ;D I like to read your stuff.

Seriously though, these kinds of kits are great introductions into programming, electronics, control systems, and many other facets of electrical and software engineering. They support the idea that students should experience success early and relatively easily so that they're more likely to continue.

You can also get systems that include some form of a STAMP controller so you can have some excitement early on. Marv's example using a servo is perfect. People love seeing things move. You can get robot kits with STAMP processors. It's also what made MindStorms so successful.

The vendors I see at work seem to recognize that there's a kiddie in each of us engineers...they're providing evaluation kits with motor controls, speakers, color LCD display...radio...all sorts of goodies!!!
 
It's so easy, a dentist can do it. :big: Here is the link to a website, one of a few which inspired me to take on Rolling Ball Sculptures some time ago. The author has taken much time and care to illustrate how he uses two Basic Stamps in his RBS as well as other ingredients in his sculptures. There's a little bit of machining effort in his "art" as well. You might enjoy it, very well written.

http://www.chaneyproductions.com/marbellos.htm

-Trout
 
Marv,
Thanks for that info, Pretty cool stuff, Perfect for electrical dolts like me.

Pete
 
mklotz said:
Finally, I hope at least a few of you find this information useful.

Actually, though I confess I have an almost negative interest in anything 'lectronical, right away I find something that this gadget may accomplish. A big part of getting me to even read this is the way you wrote it, Marv.

I've been interested in using a small stepper on the X axis of my milling machine. I have no desire for CNC operated machinery, but it would be handy to have a truly simple jog function on that one axis to make long steady cuts. Something that would just turn on whenever I held down the button, and had an easy reverse function. Will this thing do that? Do the instructions present a similar scenario (regarding stepper control)?


mklotz said:
It includes a manual (shown in the photo below) that will guide you through every step, even if you can't tell a resistor from a capacitor. (It's written at such a no-assumptions-about-the-reader level that it might even satisfy Zee.)

And it didn't take a forklift to deliver it?
Hmm.

Dean
 
Yes, good one marv...

I can relate to this... I was introduced last year to the art (through my mentor)... I started with a BASIC stamp, and moved on to PICs...

In fact I bought my lathe and my mill to built the hardware for my self balancing robot project... (I do have a prototype using the BASIC stamp...) But got sidetracked with projectitis and model engines :) ... oh well...

tom
 
many thanks Marv for showing us this little jewel
I was always tempted to learn how to use these controllers, but it scared me to try
now you have presented them in a way that seems almost accessible to me
I'll browse the parallax site to understand better what is the matter

 
interesting Marv. I probably will not buy one soon lots of other projects to get finished etc. But I am interested . I bought my son mind storm a a couple years ago and we found a dacta (Lego computer pre-dating mind storm)
Tin
 
ariz said:
many thanks Marv for showing us this little jewel
I was always tempted to learn how to use these controllers, but it scared me to try
now you have presented them in a way that seems almost accessible to me
I'll browse the parallax site to understand better what is the matter

If your at all interested in finding out about these wonderful devices I strongly recommend you look at the Parallax documentation and the Picaxe documentation at http://www.picaxe.com The Picaxe stuff is aimed at the educational market and is very approachable. I have used 1000's at school over the past 10 years or so.

Picaxe chipe are also much cheaper - although some wouls argue in some cases a little slower than other offerings, BUT have the advantage of very easy programming with free downloadable software to facilitate this.
 
This is a great idea. The marriage of electronics with model engineering. :idea:
If anyone is interested in 555 timers for Pulse width modulation control of little motors...

pwmmtrcntrl.gif


small 5 and 12 volt motors (1 amp or less current draw) can be driven by this simple controller.

Kermit

 
I keep looking at them and one of these days need to buy one... Looking at one of them sure makes it hard to justify building a circuit using the old Z80... What I am thinking about using one for is a home made DRO. Homemade means I could put all the fancy options I would like so I could have multiple homes, bolt circles and other "programming" options that might be nice.

In that regard - Anyone ever scrapped out a injet printer and salvaged the linear encoder parts and tried to use them? they have a long plastic ribbon and a reader module in the slider that holds the prinheads. I recently scrapped one out and I need to figure out wha the resolution is. Then play with some of my other junk and make a DRO.. Just need 2 more printers to scrap out.
 
Who could forget the bizarre dancing penguin robots from parallax:

[youtube=425,350]LpH3ZsNwBn8[/youtube]

Cheers,

BW
 
Hey Marv,

Thanks for the nice, informative post. I keep thinking about something like this for a learning experience. Why did you finally decide on the Stamp? I see several other microcontrollers out there that are advertised as a lot cheaper. The PICAXE comes to mind. Just wondered what decided it for you?

Thx...
Chuck
 
cfellows said:
Hey Marv,

Thanks for the nice, informative post. I keep thinking about something like this for a learning experience. Why did you finally decide on the Stamp? I see several other microcontrollers out there that are advertised as a lot cheaper. The PICAXE comes to mind. Just wondered what decided it for you?

Thx...
Chuck

Not answering for Marv, but his post covered some of the same things that got me to buy the same unit. It had a serial interface on it and a breadboard area. Made it a very quick and easy project to get completed. It is easy to program and is ready to run as-is. For learning it is great because you can easily reconfigure it and do labs and experiments.
 
Chuck et al,

Understand, there's nothing special about the STAMP in my estimation. I had heard of it and it looked like it would satisfy my needs. I'm not recommending it above other microcontrollers which, I'm sure, are just as useful. My intention was to learn, not to necessarily pick the optimum electronic match to a particular project. Probably any microcontroller learning package would have satisfied that objective.
 
Been looking at those for a long time myself - just never got a round-tuit to get there and try it.

For thse more experienced - I have an ancient digital logic lab I picked up as a convenient breadboard for doing ciircuit prototyping (did the electronics thing for a living back in the good old TTL days...)

What does the Stamp actually need for interface? Reason I ask is that there are a lot of editors and such out there freeware - seems ot me I could save more than a few $$$ using what I have and just getting a stamp chipset or one of the single-chip alternatives.

Opinions?

Alan
 
Thanks for that info, Pretty cool stuff, Perfect for electrical dolts like me.

Actually, though I confess I have an almost negative interest in anything 'lectronical, right away I find something that this gadget may accomplish. A big part of getting me to even read this is the way you wrote it, Marv.

Pete, Dean,

Thanks for the kind words. I wrote it for the express reason of reaching folks like you, folks who are a bit intimidated by things electronic.

Modern electronics has brought us a myriad of useful stuff but, more importantly, it's brought us the means to simplify the use of those capabilities without the need to understand the minutiae of the electronic engineer's world.

Since I fall into that category of people both awed and confounded by intimate details of electronic wizardry, I thought that writing a review from that viewpoint might encourage others to get their feet wet, learn a bit, and, hopefully, go on to build useful stuff for their hobbies.
 
Personally,I prefer pics...

The 16F628A which replaced the F84, only has 32 instructions so the learning curve isnt as long as for whichever dialect of BASIC you choose.

ASM can also produce much more compact code.

I built a tach for my lathe with an lcd readout...I just need to install it all... another tuit job!

PicAxe chips are pic based with an internal bootloader, needing a minimum of hardware to program using just a usb lead to a laptop or pc...re-programming can be done more or less on the fly...

Horses for course really...depends what you want to do....
 
What makes the Basic Stamp series attractive besides the simplicity of the electronics and programming is the level of support and add-ons made available by Parallax itself. It's very easy to add GPS, sonic sensors, light sensors, altitude and angle sensors plus much more. A major reason for Parallax's success is the attention to customer support.

They happen to be just across the river from me.
 

Latest posts

Back
Top