# microcontrollers for the model engineer



## mklotz (Nov 19, 2009)

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... 







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...


```
' {$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.


----------



## RonGinger (Nov 19, 2009)

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.


----------



## zeeprogrammer (Nov 19, 2009)

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!!!


----------



## Troutsqueezer (Nov 19, 2009)

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


----------



## pete (Nov 19, 2009)

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

Pete


----------



## Deanofid (Nov 19, 2009)

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


----------



## ttrikalin (Nov 19, 2009)

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


----------



## ariz (Nov 20, 2009)

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


----------



## Tin Falcon (Nov 20, 2009)

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


----------



## rickharris (Nov 20, 2009)

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.


----------



## Kermit (Nov 20, 2009)

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...






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

Kermit


----------



## kf2qd (Nov 20, 2009)

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.


----------



## BobWarfield (Nov 20, 2009)

Who could forget the bizarre dancing penguin robots from parallax:

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

Cheers,

BW


----------



## cfellows (Nov 20, 2009)

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


----------



## black85vette (Nov 20, 2009)

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?
> 
> ...



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.


----------



## mklotz (Nov 20, 2009)

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.


----------



## Alan J. Richer (Nov 20, 2009)

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


----------



## mklotz (Nov 20, 2009)

> 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.


----------



## John Rudd (Nov 20, 2009)

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....


----------



## Troutsqueezer (Nov 20, 2009)

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.


----------



## shred (Nov 20, 2009)

Parallax has by far the best support structure for beginners to the micro world. I've got some AVR stuff as well and it can be cheaper, but it's a lot more hassle to get everything working well.


----------



## cfellows (Nov 26, 2009)

Further to Marv's post, I think I have a good microcontroller project to learn on and will yield a decent tool when finished.

I'm thinking that an electronic dividing heard or perhaps rotary table would be a good project. I have a bunch of different stepper motors and I also have a couple of stepper driver modules that would make the micro-controller part easy.

The stepper driver accepts input to designate stepper direction, mode (half step or full step) and, of course, step. All the micro-controller would have to do is accept user input and do the math to determine how many steps between divisions, and direction. 

Gonna have to give this some more thought.

Chuck


----------



## rickharris (Nov 26, 2009)

shred  said:
			
		

> Parallax has by far the best support structure for beginners to the micro world. I've got some AVR stuff as well and it can be cheaper, but it's a lot more hassle to get everything working well.



I may well dispute that statement - However as always in these complex areas individuals have their own preferences. 

I have used Picaxe and Parallax systems and by far chose the Picaxe both from the point of view of price and ease of use as well as their support structure - But then again I am in the UK.

They Picaxe have just announced a forthcoming 18 pin multi tasking device which promises to be very flexible in use, with up to 10 out puts available.

You pay your money and take your choice.


----------



## HYTECH (Nov 27, 2009)

Here is a good place for PIC, AVR, ARM, and 8051 (Newb freindly) http://www.mikroe.com/
There development boards are awsome and they have Pascal, Basic and C compilers that are fairly easy to use. They also have very good support and a good forum. I bought there EasyPic4 development board to learn to use Pics. They're based it the UK and there US distributor is http://www.circuit-ed.com/. 

 Free online book for Programing Pic in Basic. But they have many others. http://www.mikroe.com/en/books/picbasicbook/00.htm


----------



## HYTECH (Nov 27, 2009)

Here is a pdf of "What is a Microcontroller" from Parallax. It will teach you alot about Basic Stamps. 
http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf


----------



## cfellows (Nov 27, 2009)

Kind of stomping all over Marv's thread here, but I'll post one more... :

I found this website this morning and kind of had an "Ah Ha" moment. If you read the descriptions, there is a link to the basic code used on each of these projects. This guy really makes it look dirt simple. 

http://www.inklesspress.com/picaxe_projects.htm

Chuck


----------



## bdrmachine (Jul 24, 2022)

Here's my 10 cents worth.  ESP32 and Platformio.  They are around $10 US and they have multiple cores,  include bluetooth, Wifi and all the usually interface protocols.   PlatformIO  is free and allows realtime hardware debugging.  HUGE support base and besides the $10 board, all you need is a usb cable for most boards.


----------



## Peter Twissell (Jul 25, 2022)

+1 for ESP32.


----------



## bikr7549 (Jul 25, 2022)

I've used the Stamp quite a lot and learned a lot quickly. Advantages are that PBasic is very easy to get going with as it is very straightforward to use, and as mentioned, Parallax does offer lots of sensors and things along with the software needed to run them. Disadvantages that have made me move away from it was lack of a real time clock for timing, and the way that basic deals with floating point numbers was just a pain to deal with. I moved first to the Parallax propellor but have now switched over to the Arduino. Still learning that one, but found that if you can program something already, moving over to another isn't that big a problem. The Arduino driven rotary table seen on this site is on my list to do.

One other advantage (for me, initially) was that the Parallax microcontrollers are all made in the US, not so with the other brands, hence the price difference.


----------



## bikr7549 (Jul 25, 2022)

bikr7549 said:


> I've used the Stamp quite a lot and learned a lot quickly. Advantages are that PBasic is very easy to get going with as it is very straightforward to use, and as mentioned, Parallax does offer lots of sensors and things along with the software needed to run them. Disadvantages that have made me move away from it was lack of a real time clock for timing, and the way that basic deals with floating point numbers was just a pain to deal with. I moved first to the Parallax propellor but have now switched over to the Arduino. Still learning that one, but found that if you can program something already, moving over to another isn't that big a problem. The Arduino driven rotary table seen on this site is on my list to do.
> 
> One other advantage (for me, initially) was that the Parallax microcontrollers are all made in the US, not so with the other brands, hence the price difference.


And there was one other thing that did not work well for me in PBasic-trig. PBasic uses what are called binary radians (BRADS) in place if degrees, or real radians. Resolution was way off for anything of importance for me with this. I don't recall the numbers, but getting any accurate angular measurement seemed to be not possible. In this instance I was using their 2 axis accelerometer. If I can find the old data I'll put it up here if anyone is interested. Still, the PBasic knowledge I obtained was very helpful to me.


----------



## mattb.351 (Jul 26, 2022)

The MOST fun I ever had (with microcontrollers) was in the mid 1990's on a PIC16C84 writing a protocol converter. It had to convert commands over RS232 to a proprietary protocol for a mining machine (and back). Programming the PIC in assembly was really fun. The 12C508 (now I think it's 12F508) was the baby in the family and something you could rig up on a piece of vero-board in an afternoon and get programming. The biggest hurdle back then was getting access to an EEPROM eraser, something that the F version wouldn't need.


----------



## Toymaker (Jul 26, 2022)

This conversation about Micro Controllers wouldn't have been complete without at least mentioning Arduino; thanks [I]bikr7549[/I].  Like Parallax, Arduino has a family of different Micro Controllers which are quite easy to use and program.  I'm using Arduino's Mega 2560 to control my *Ambitious ORC Turbine*.   

Marv has given a wonderful intro to Micro Controllers; I will only add that equally important to selecting the right controller is selecting all the various sensors needed to tell the controller things like, steam pressure , water level, engine rpm, burner flame sensor, and servos needed to control fuel flow to the burner, any steam valves, etc.  

I find it helpful to draw a block diagram listing all the inputs and outputs of the Micro Controller.  I try to include at least max values I expect the sensors to see and what type of outputs the sensors have; analog, digital, voltage range, etc...whatever parameters help me decide what I need to buy to make this project work.  Once I actually buy the sensor, I like to fill in the actual specs for the various sensors.

Follow this link to see the *Block Diagram*.


----------

