[ click here for a printable version (PDF) of this page ]

PROP-1 101 :: Episode Four: The Beginning

Welcome again to our "Prop-1 101" series. In this fourth installment, we'll be covering what we were supposed to cover in the first installment. It's our first prequel, and we hope you like it. Unlike other prequels, we won't be going back and inserting a bunch of crappy CGI into the first how-tos, and then making you buy them all over again. George Lucas, up yours.

Before we can begin this tutorial, you need to spend some hard earned cash.

Warning!

An informal survey was performed in the Greater Providence Rhode Island area, and it was confirmed that spending a bunch of money on micro controllers caused a significant decrease in a spousal libido. Continue at your peril!

As a side note, I recommend having everything shipped to your work. If you time your purchase correctly this can buy you a month of sucking up to your spouse before the credit card statement comes in. This can be a critical step to maintaining the structural integrity of your skull, and/or testicles.

Part One - What to order?

Now then, onto the goods you'll need to purchase:

First off, as this is your first foray into using a Prop-1 micro controller your best bet is to purchase a starter kit. T his will not only net you the Prop-1 controller, but it will get you some important accessories.

Head over to our friends at EFX-TEK and snag the following:

Prop-1 Starter Kit, stock # 31001 http://www.efx-tek.com/topics/prop-1_starter.html

The starter kit comes with:

  • A Prop1
  • Prop-1 Trainer
  • Serial Cord
  • 12V 1Amp power adapter
  • Serial Adapter

If you don't have a serial port on your PC/Laptop then you'll need a USB to serial converter. What's a serial port? It's the one that looks like the port you plug your monitor into only it's got pins sticking out.

Serial port

The part number for the USB to Serial converter is stock # 28030, found at http://www.efx-tek.com/topics/usb-serial.html

That's it for now. This is everything you need to get your Prop-1 mojo working, and get some learning going.

Part 2 - Hooking it up

You'll notice that your Prop-1 comes with a ULN 2803 stuck onto it. As referenced below:

The ULN is the part of the operation that handles the higher voltage/amperage loads that are hooked up to the screw type output pins, such as 12V pneumatic solenoids. There are two types of ULNs you'll use with the Prop-1: the ULN 2803A, and the shorter ULN 2003A.

What's the difference? Well not much except for the important fact that that 2003A is one set of pins shorter. This is important because when you move on to the forthcoming how tos you'll be using serial commands to control devices like the RC4, FC4, and AP8. The ULN can interfere with serial commands, so by using the shorter 2003A, it allows pin seven to be free of any potential ULN interference.

See below for a picture of the shorter ULN 2003A installed:

One very nice thing about the Prop-1 series of controllers is that the ULN isolates the controller from higher loads. So let's say you - oh I don't know - create a miniature mushroom cloud out of the ULN by hooking things up completely wrong. Well, your Prop-1 will be fine again once you pop in a new ULN.

I'm sure there's a way to kill a Prop-1, but I haven't found it yet - and that's saying a lot.

Come to think of it, the ULNs are so cheap (about $2 bucks a pop) that you might as well buy some extra ones now. If you're as dumb as I am, you'll eventually need one.

So with all that said, lets hook this sucker up!

First off, connect the serial cable to your PC (using the USB adapter if you need it) and then connect the other end to the supplied Prop-1 serial adapter, and slide the connector in the Prop-1 as referenced below:

Now then, turn the Prop-1 on to the switch setting marked "1" (the middle of the three position switch). Why are there three settings on the power switch (0, 1, 2)? The middle setting will only power the 5V pins as referenced below:

These pins are for hooking up inputs like switches, sensors, and the like, and also for outputting 5V to power things like LED's and Servo's. When you slide the switch all the way over, you can send power to the screw type "high" voltage outputs as well.

For now, we're not concerned with that.

With the Prop-1 all connected up to your PC, and the power on, go ahead and download the STAMP BASIC editor, available free here: http://www.parallax.com/ProductInfo/Microcontrollers/BASICStampSoftware/tabid/441/Default.aspx

Part 3 - Programming

Install, and run the STAMP editor and you'll see this interface:

Welcome to your new world. This blank page is where all the magic happens. The Prop controllers are based on Parallax's line of "STAMP" micro controllers. Why do they call them STAMP? Well, because they're about the size of a stamp. Honest.

The first thing we need to do when writing a new program is tell the brains what type of STAMP core we'll be loading this program into. For the Prop-1, this will be BS1, using PBASIC version 1.

How do we do this?

Go to "Directive" in the editor:

Now click through as follows to insert the first line: Directive > Stamp > BS1

Then click through the following:

Directive > PBASIC > Version 1.0

When you're done, you'll see this:

Now we're ready to write our first program. As is programming tradition, we'll write a "Hello World" program. This will validate that the Prop-1 is functioning, and that it and the PC are communicating. If you're nerdy enough, this will also make you yell out "Sweet!" At that point your spouse will ask "What?" and you'll attempt for about 30 seconds to articulate your sense of accomplishment. Then you'll shrug your shoulders and your spouse will mutter "Nerrrd" under their breath and move on.

Don't cheat yourself out of this moment. It's a right of passage.

So, write the following lines of code after the directives:

Main: Debug "Time to Get Evil!!"

Now lets plop this nugget of goodness into the Prop-1 by hitting the "Run" button. Doing this will compile and "Tokenize" the code, then load it into the Prop-1.

First, make sure your Prop-1 is on, then hit "Run" here:

If you got a error message that said "no STAMPs found, you need to pay attention, and make sure the Prop-1 is on. Don't feel bad, I do this to myself all the time.

Voila! The Prop-1 is alive, and it's talking to you via the terminal screen, because that's what DEBUG does. It tells the Prop-1 that you, the programmer, needs to know something, so let's give the schmuck a portal into what the Prop-1 is really doing. In this case, we used quotation marks in our DEBUG command, and when you do that, it says "I'll print whatever is in between the quotation marks, and send that out to the terminal screen.

Which means you saw this:

You'll learn that the DEBUG command is essential for getting a peek into the goings on beneath the hood. I would rather parachute naked into a Bulgarian women's prison then try to troubleshoot without DEBUG.

In case you're wondering about the line "Main:" it's just that, it's the main area of the program where you'll writing the bulk of all the magic it takes to make your prop do it's thing. They'll be sections before it, and possibly routines after it, but we're getting ahead of ourselves.

Part 4 - Installing the Prop-1 Trainer

Time to break out the Prop-1 Trainer. This little board is a great tool to learn the basics.

Before installing the Trainer, now is a great time to swap out the 2803 ULN for a 2003A. While using the Trainer we won't be sending anything through the high outputs, but once again that pesky pin 7 on the 2803 could potentially mess with things.

Most likely you'll eventually end up playing around with serial communications, so you might as well just do this now. The only thing you'll lose is the ability to make pin 7 a high load OUT, and I doubt you'll ever absolutely need to do this anyway. Besides, it's not permanent, you can always just swap the 2803A back in.

Very carefully (and patiently) pry the 2803 out of the socket. I can't recommend it, but a very small flat head "jewelers" type screwdriver worked for me. A little on each side at a time and it will free before you know it. Once its out insert the 2003A like so:

The circled area illustrates that pin 7 is no longer occupied by a ULN circuit.

Now install the Trainer of the pins, like so:

And that's that. Lets get on to the fun stuff.

Part 5 - Programming to make stuff happen

Basically you can break down prop programming into two camps, or a combination thereof:

  • Timed events
  • Conditional events

Timed event programming is essentially like making a player piano roll for a player piano. The Prop-1 reads your code, setting off the events as it reads your commands. It's no different than a player piano roll, where each hole punch triggers a corresponding piano key.

In timed event programming, each command will trigger a pin of your choosing to activate, which in turn powers what you hook up to it. Then you insert pauses as you go along to control the timing of the sequence.

Conditional programming takes it a step further; it allows things to be activated based on certain conditions being met. For instance, as long as you don't hit a button, nothing happens, but as soon as you do, the code sends the program to a sequence of events.

FYI: The controller will read code just like you do: left to right, top to bottom. The controller doesn't care about upper or lower case, but you should be try to be neat about things anyway (why not, right?).

At this point, you're probably wondering why I'm boring the hell out of you. Well be bored no more! With everything connected, lets write our first bit of a timed event program!

Note:

Using a single quotation mark before text makes the Prop-1 ignore whatever follows it in a line of code. This is used for "commenting". Use comments whenever you can so you can go back to a program and remember why you did what you did. Also notice I use Tab to indent some of the code sections. Make things easier to follow in larger programs.

Enter the following:

' {$STAMP BS1} ' {$PBASIC 1.0} Main: HIGH 0 'make pin 0 and output and send power to it PAUSE 1000 'pause 1 second LOW 0 'remove the voltage from pin 0 PAUSE 1000 'pause 1 second GOTO Main 'go back to main and start over

Now hit "Run" again to load the code into your Prop-1

Look at the Trainer! P0 is now blinking away at you. This may not seem like much, but it's the foundation for everything else.

To give you an idea what that blinking LED could mean, who said you have to have the Trainer installed? If you take it off, hook up a 12V solenoid to OUT0 and move the switch to it's third position, then that blinking LED is suddenly a Pneumatic cylinder pulsing up and down.

Side note:

Even after you get good at this stuff, the Trainer will come in handy for testing, because at the end of the day, all we're doing is making outputs happen on the pins of our choosing, at the time of our choosing.

So as you can see, the "HIGH" command means make the pin an output, and sends 5V to that pin, or in the case of having the power switch in the 3rd position, sends 12V to that screw terminal (assuming you're using a 12V power supply, if your using a 24V supply, it will make a 24V connection).

Note: In the case of the OUT terminals, its not "sending" voltage, but actually completing a ground, thus completing the circuit. Same outcome as far as we're concerned but I figured I mention it before some egghead writes me a scathing email.

So because we're using the Prop-1 on power switch position 1, "HIGH 5" means send 5V to pin 5.

Three very important things about this program example:

(1) In the "Main:" statement we used a colon after "Main"

This makes "Main" what is called a "Label". As long it's a Label, commands like GOTO and their brethren will be able to send the program to it. A Label is a pushpin in a map; you've made note of that location, and you can send routines to it by referencing that Label with the right commands.

Commands like…

(2)The "GOTO" statement This sent the program back to the "Main:" label, which created a loop. This will keep the program doing its thing. As you can see in the program, when referencing a label, you don't need the colon after it. You only need the colon after it to create the label.

(3) The Pause statement Pause does just that, stops the presses for whatever amount of time you tell it to. In Prop-1 world, 1000 is a second, 500 half a second and so.

Try this addition to your code:

' {$STAMP BS1} ' {$PBASIC 1.0} Main: HIGH 0 'make pin 0 and output and send power to it PAUSE 1000 'pause 1 second LOW 0 'remove the voltage from pin 0 PAUSE 1000 'pause 1 second HIGH 1 'make pin 1 and output and send power to it PAUSE 1000 'pause 1 second LOW 1 'remove the voltage from pin 1 PAUSE 1000 'pause 1 second GOTO Main 'go back to main and start over

You made the lights on pins 5 and 4 alternate. Now we're going places!

Using Symbols

This is a good time to mention symbols, as we need to start using them. Symbols allow you to give meaningful names to something. You can use any name you want for a symbol, so long as it's not an actual PBASIC command (i.e. HIGH, or PIN). In the example below I've used the "symbol" deceleration before my main section to setup a naming scheme for pins 5 and 4. In this example let's pretend I'm building a prop with two pneumatic cylinders. Once I use symbol to name them my code starts to make more sense, and if I have to move a cylinder to a new output I don't have to change every line of code that involves that cylinder, I only need to change the pin in the symbol declaration.

' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Cylinder1 = 0 SYMBOL Cylinder2 = 1 Main: HIGH Cylinder1 'raise cylinder 1 PAUSE 1000 'wait a second LOW Cylinder1 'lower cylinder 1 PAUSE 1000 'wait a second HIGH Cylinder2 'raise cylinder 2 PAUSE 1000 'wait a second LOW Cylinder2 'lower cylinder 2 PAUSE 1000 'wait a second GOTO Main 'go back to main and start over

Using Variables

Now that you're starting to feel pretty smart, lets take you down a peg.

What is a variable?

For our purposes, it's a number (a value) that can vary. A variable begins its life as zero, and then through programming we manipulate that using our friend math. A variable is stored in the Prop-1's memory, and because of that we need to let our Prop-1 know where in its virtual file cabinet to put it.

A variable needs to be declared with a symbol, before the Main section like so:

SYMBOL Led = B1

So in the example above we called our variable "Led" and we told the Prop-1 to store it in memory location "B1". The Prop-1 knows we're saying it's a variable because of the "B1".

Why "B1"?

Let's look at a simplified table of how the Prop-1 stores its memory:

W0B0
B1
W1B2
B3
W2B4
B5
W3B6
B7
W4B8
B9
W5B10
B11
W6B12
B13

Calm down! Pull yourself together soldier!!! I know this makes no sense it all, but it will.

Here's the deal: we know a variable begins its humble life as zero, but how big can it grow? Well, it can either get as big as 255, or as big as 65,535. The smaller version is called a byte sized (B) variable, the larger is a word sized (W) variable. If you decide you need a word sized variable and you declare it like so:

SYMBOL Led = W0

Can you then use B0, or B1 in the same program? Nope, refer back to the table, you just burned up that memory address. That file drawer is now full, or at least reserved.

If you need a byte sized variable and you declare it like so:

SYMBOL Led = B0

Can you then use B1 in the same program, yep! But can you use W0? Nope. Well technically you could, but you're just gonna screw things up. So don't. Basically, every larger W sized variable burns up two smaller B sized variables. If you declare W0 and B0 in the same program, they'll step on each other and could mess things up. Again, refer to the table to see how it all lays out.

So now we know: if you need a variable in between 0 and 255, use a B variable. If you need one bigger than 255, use a W sized variable.

Reference the table to make sure the variables you declare don't step on each other. To make things easier I start with the smaller variables at address B2, and work up. For the bigger variables I need I start at W6 and work down. Why didn't I use B0 and B1 first? You'll find out as you get better at this, for now just take my word for it.

Whew!

That was really painful! Lets have some fun again. Don't sweat it if you're not quite in tune with variables yet. The upcoming example will help illustrate what I'm talking about.

So not that long ago, we made an LED on the Trainer blink on and off, then we made two blink in sequence. Well the Trainer will let us use pins 0 through 5 as outputs, so why not make them all go on and off in sequence? We could of course just write a bunch of HIGH and LOW commands. It would work, but lets instead lean on our good buddy the variable to help lighten the load.

Enter the following into the editor:

' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Led = B2 Main: Led = 0 FOR Led = 0 TO 5 HIGH Led PAUSE 1000 LOW Led NEXT GOTO Main

What was that all about? Besides the cool scrolling Leds of course…

First off, allow me to introduce our good friend FOR/NEXT.

FOR/NEXT works like this: You make the FOR statement, let the Prop-1 know what variable you'll use to keep track of the changing (varying) number, then set the range of how high you count up.

After setting up the FOR, you nest what you want to happen in between the NEXT command. The NEXT command sends it back to FOR until the desired range is met.

After that it goes to the next line of code, in this case the GOTO command, which sends it back to the Main Label, and off we go again.

I created the Led variable using B2, because it won't be getting bigger than 255. As you can see, I then not so cleverly re-used the Led variable to set the pin for the HIGH and LOW commands. That's a lot easier than dealing typing all those HIGH and LOW commands. With each trip around the FOR/NEXT loop, the FOR/NEXT command incremented the Led variable by one for me. The Prop-1 kept track of the changing variable in memory address B2. The first time around pin 0 lit, then the next time, pin 1 lit, and so one until it hit the end of the range (5), then the FOR/NEXT sequence ended, and went to the next line GOTO, thus beginning it all again.

Conditional Programming

Fun as FOR/NEXT is, to reinforce how variables work lets try to do the same thing in a different way, and lets add a condition to the program:

' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Led = B2 Main: HIGH Led PAUSE 1000 LOW Led Led = Led + 1 IF Led > 5 THEN Start_Over GOTO Main Start_Over: Led = 0 GOTO Main

Holy Crap! Did you see all the cool stuff you just did there?

Let me run it down for you:

  • You don't need FOR/NEXT, its too easy for a genuis coder like you! After it went through the first pass (a variable starts at zero, so it lit pin zero) you told it to add one to the Led variable, thus on the second pass "Led" was stored as "1" and pin one lit up.
  • You made a program with a conditional element to it! You said that IF the variable "Led" got bigger then 5 (the alligator eats the bigger number) THEN send the program to a Label, in this case "Start_Over". Then once it got there, you took charge again and said "Led = 0".
  • After setting the Led variable back to zero, you sent the program to the Main Label with the GOTO command.

And just like that, the circle of code was complete.

You my friend, are drinking Prop-1 gasoline, and crapping Prop-1 dynamite. Believe it.

Now, lets get even cooler. Let's do the same thing, but add another condition and lets control it with a switch. It just so happens the Prop-1 Trainer has a little push-button on it, its on pin 6.

You'll notice the following:

  • In the symbols, I don't say that Push_Button is on 6, I say its on PIN6, that's how we roll when we're declaring inputs. For inputs its PINX, not just the pin number like the outputs.
  • For our purposes when an input pin is dormant, the Prop-1 see's a "0", when it's active, a "1". Pressing the switch makes PIN6 read "1".
  • We also cut down PAUSE to 100, or one millisecond. Why not, it looks cooler seeing the Leds go faster.
    ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Led = B2 SYMBOL Push_Button = PIN6 SYMBOL Is_Off = 0 Main: IF Push_Button = Is_Off THEN Main HIGH Led PAUSE 100 LOW Led Led = Led + 1 IF Led > 5 THEN Start_Over GOTO Main Start_Over: Led = 0 GOTO Main

    Pretty cool huh? Once again, imagine these examples working beyond the Trainer. And once you feel comfortable, get uncomfortable! Open up the Help file and look at all the cool commands available to you!

    Did we even scratch the surface? Not even close. There are a huge amount of commands and programming techniques that relate to Prop-1 (STAMP BS1) programming. Your next step should be to head to EFX TEK and poke around the forums. Much of everything you're itching to know has been itched before. Read the responses, run the programs you see there and take the time to play with them, learning what makes them work. The Prop-1 can control virtually anything you can imagine, you just need to take the time to learn how.

    Try not to hurt yourself.

    If you find yourself stuck, head here for help



    AddThis Social Bookmark Button Vote for us at Best Of Halloween!





    This page was last modified on: May 11, 2008 03:16:08 pm

Join the GARAGE OF EVIL!! Mailing List



Need Ambient Audio for your Haunt?