Shop OBEX P1 Docs P2 Docs Learn Events
First project ever. Where do i begin? — Parallax Forums

First project ever. Where do i begin?

annonymousannonymous Posts: 14
edited 2012-02-12 20:15 in Propeller 1
Hey y'all i am new to micro controller programming. I have been programming in C for a few years and just recently started to program in 32 bit Linux Nasm. So I just went to radio shack and bought a bunch of goodies! A spdt(Single Pole Double Throw) relay, 22g wire, a general purpose micro controller, and a 5 button keypad. I am going to hook up the 5 button keypad to the micro controller. the MC to the relay and the spdt relay to my ignition switch. So if i enter the correct code, the relay will close the circuit and enable the ignition. Without the code the car will not start. Where do i start? Where can i get diagrams or turorials, or what ports are for what? Do i need to write a serial server first? I just downloaded the BST IDE.I run Ubuntu as an OS and gcc for my compiler.

what i would like to know is where do i start with the micro controller programming?

The development board i have is the Propeller P8X32A QuickStart # 4000-RT
«1

Comments

  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-05 14:36
    annonymous wrote: »
    ... Where do i start? ... The development board i have is the Propeller P8X32A QuickStart # 4000-RT

    Welcome to the forum.

    The best place to start is at the beginning - this link should get you started Propeller General Information

    The Propeller can be programmed in various languages but a beginner my want to start with SPIN, the language Parallax developed for the Propeller - and then maybe PASM.

    Propeller Manual v1.1
  • Mike GreenMike Green Posts: 23,101
    edited 2012-02-05 14:51
    A caution about relays ... They usually take much more current to operate than any microcontroller I/O pin can supply and the QuickStart Board is no exception. You will need some kind of switching transistor, like a MPS2222A or 2N3904, both of which are available from RadioShack. You'll also need a 1N4001 diode and a 150 to 220 Ohm resistor. Look at the Nuts and Volts Columns. Column #6 deals with controlling relays and small motors using a Stamp, but it applies to the Propeller as long as you take into account the difference in operating voltage (5V for the Stamps and 3.3V for the Propeller).
  • annonymousannonymous Posts: 14
    edited 2012-02-05 15:22
    i walked into radio shack thinking this would be an intermediate project. I was wrong lol The relay that i bought Mike is a single pole double throw PC relay. It has a 12VDC coil And is rated at 10A @ 120VAC/24VDC. This project is turning out to be a lot more complex than i originally thought it would be! But the documentation you provided Ron is not helpful. Thank you though! I am looking for documentation on which ports are used for what; An elaborate diagram i mean. Some insight on the spin code. Everything i need to get started! Would it be easier to write my own serial server in C or is there a lot more to it than i think? Like flashing eeprom manually. Needing to write code to do that? I am so overwhelmed at the moment! Would the audrino be better for me? Is it more beginner friendly or will i get the same result no matter the brand of MC?
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-05 15:37
    annonymous wrote: »
    i walked into radio shack thinking this would be an intermediate project. I was wrong lol The relay that i bought Mike is a single pole double throw PC relay. It has a 12VDC coil And is rated at 10A @ 120VAC/24VDC. This project is turning out to be a lot more complex than i originally thought it would be! But the documentation you provided Ron is not helpful. Thank you though! I am looking for documentation on which ports are used for what; An elaborate diagram i mean. Some insight on the spin code. Everything i need to get started! Would it be easier to write my own serial server in C or is there a lot more to it than i think? Like flashing eeprom manually. Needing to write code to do that? I am so overwhelmed at the moment! Would the audrino be better for me? Is it more beginner friendly or will i get the same result no matter the brand of MC?

    Actually it is quite complex. If you intend to learn how to program a Propeller, you need to understand the basics of how the microcontroller works. There are eight processing "cogs" and it takes time to learn the hardware and programming tools.

    There are many links and tons of information available to you on the QuickStart product page

  • annonymousannonymous Posts: 14
    edited 2012-02-05 15:41
    Thank you Ron. Also i have found this PDF http://www.parallax.com/dl/docs/prod/prop/WebPM-v1.01.pdf for starters. As well as a diagram in PDF format of the MC ---> http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PchipBlockDiagramRevA-0109.pdf
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-05 15:51
    annonymous wrote: »

    There are easier to learn microcontrollers and all have pluses and minuses. The Propeller's multiple cogs give it advantages but with added complexity.

    Ultimately it depends on your goals. If you are looking for a quick and dirty one-time microcontroller project, the prop is probably not the best fit.
    If you plan on many more MCU projects and are looking for a powerful platform, the propeller offers a lot.

    Good luck.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-02-05 16:33
    annonymous,
    You will run into similar issues no matter what microcontroller you start with. As a C programmer, you will likely find the Arduino more familiar. On the other hand, you will run into the same issues with the Arduino and the push buttons and the relay and it's these issues that are unfamiliar and daunting. Parallax has a lot of educational material (manuals, tutorials, etc.) for its Basic Stamps and most of it is directly applicable to the Propeller (and the Arduino for that matter). Look at the "What's a Microcontroller?" tutorial for examples of interfacing pushbuttons. The Nuts and Volts Columns have similar examples. There are C compilers available for the Propeller. Catalina is free, stable, and quite good. There's a GCC C compiler in alpha testing that will be directly supported by Parallax. You still have to learn how the microcontroller works.
  • cavelambcavelamb Posts: 720
    edited 2012-02-05 16:50
    A blinky LED is the micro controller equal of Hello World.
    So start there.

    Wire up the LED and resistor and type in you code.
    Then play with it to make it do other stuff.

    Be advised that Spin uses indentation to control the structure of the program.

    Also, sometimes it's a PITA to get code to show properly here.
    Hence the dots in the example below. The indentation is that important.
    I've tried to fix it a few times but gave up in frustration and added the dots.
    Edit them back to spaces...

    An example really ought to be pinned to a Newbie thread.
    Just so guys can easily find it and get started.
    There are just too many variables trying to do it from a book!

    Anyway: See if this might get ya going...
    Blinky.jpg


    code
    {{ Jan 30, 2011
    Blinky51.spin
    }}

    CON
    _CLKMODE=XTAL1+PLL2X
    _XINFREQ =5_000_000

    HI = 1
    LO = 0

    SlowWait = 5_000_000
    FastWait = 1_000_000

    PinOut = 07 ' has an LED
    PinIn = 06 ' has a switch wit a 10K pull up resistor

    PUB MAIN

    dira [PinOut] := 1 'output bit for LED
    outa [PinOut] := 0
    dira [PinIn] := 0 'input bit for button

    repeat
    if ina[PinIn] == 1 ' if button IS NOT pressed
    ..repeat 1 'blink it fast
    ....outa[PinOut] := HI
    ....waitCNT (FastWait+cnt)
    .... outa[PinOut] := LO
    .... waitCNT (FastWait+cnt)
    ..else ' button IS pressed
    .... repeat 2 'blink it slow
    .... outa[PinOut] := HI
    .... waitCNT (SlowWait+cnt)
    .... outa[PinOut] := LO
    .... waitCNT (SlowWait+cnt)
    /code
    1024 x 1092 - 56K
  • annonymousannonymous Posts: 14
    edited 2012-02-05 16:51
    Here is a question Mike. Lets say i want to program this prop without the BST IDE. How would i do it? I have the BST software installed but it is extremely buggy! Crashes way to much and freezes. Kind of aggrevating! i might switch to the Adriuno tho. I am very comfortable with C and I am running Linux. i figured it has to be more suitable anyway.
  • cavelambcavelamb Posts: 720
    edited 2012-02-05 17:01
    Ya ain't learning if you're comfortable.

    Learn Spin.
    Then learn Assembly.

    Once you learn Assembly on ANY processor, it's easy to learn Assembly on any other processor.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-02-05 17:24
    I'm surprised that BST doesn't work reliably under Linux. I use the MacOS version of BST all the time and that OS is really Unix underneath. You could also try the Linux version of Catalina and use C.

    Remember, you'll still have to learn about the Propeller's hardware and how it works since, even with Catalina, you have to manipulate the hardware with library routines. The Arduino programming environment does the same sort of thing and does it differently.
  • KyeKye Posts: 2,200
    edited 2012-02-05 17:57
    If you're a C guy you might want to check out propGCC. It has all your command line happiness and works reasonably well. However, its still in alpha right now. But, you can blink LEDs with it and whatever very quickly.

    http://code.google.com/p/propgcc/
  • w8anw8an Posts: 176
    edited 2012-02-05 20:56
    If you can program in any higher level language (like C), then spin should not be a problem. A keypad lock sounds like a pretty simple application. I would recommend that you study the physical structure of the propeller and look at code samples in the tutorials so you understand its operation and capabilities.

    There are hundreds of pre-written modules available at the obex.parallax.com page. This only simplifies your work.

    Steve
  • Heater.Heater. Posts: 21,230
    edited 2012-02-06 04:16
    @annonymous

    Welcome to the forum, whoever you are:)

    Lets say i want to program this prop without the BST IDE.

    I'm very surprised that you are having BST crashing on you. I have been using
    it exclusively for Spin/PASM development on Debian for ages with no such issues
    and no one else has popped up here with BST problems.

    BradC the author of BST also created command line versions of the compiler and
    loader, BSTC and BSTL, perhaps they work well for you. If so then you could try
    the PZST graphical IDE which makes use of those programs.
    http://code.google.com/p/pzst/

    If that does not work out there is also the HomeSpun compiler/loader
    http://propeller.wikispaces.com/Homespun+Spin+Compiler. HomeSpun is
    command line only. It is written in C# and runs very well under mono on Linux.

    As a C programmer you might like to try the new prop-gcc. Despite being in alpha
    test state it has been working very well for me.

    @Ron Czapala
    There are easier to learn microcontrollers and all have pluses and minuses

    Are there, which ones? Having been through a bunch of MCU since the 80's from
    8051 through to PIC's AVR's and ARM's I would say the Prop and Spin is one of
    the easiest to get started with.
    The Propeller's multiple cogs give it advantages but with added complexity.

    Can do, but when starting out you hardly have to worry about the parallel
    processing. Just drop your serial, video, whatever ready made drivers you need
    in to your program and away you go. With the bonus that there are no interrupts
    to worry about.
    If you are looking for a quick and dirty one-time microcontroller project, the
    prop is probably not the best fit.

    As you see, I totally disagree:)
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-06 05:46
    Heater. wrote: »
    @Ron Czapala
    There are easier to learn microcontrollers and all have pluses and minuses.

    Are there, which ones? Having been through a bunch of MCU since the 80's from
    8051 through to PIC's AVR's and ARM's I would say the Prop and Spin is one of
    the easiest to get started with.

    You think the Prop and Spin are easier than a Basic Stamp? I think most people would disagree.
    For someone with no previous microcontroller experience, the BS2 is much simpler.

    Heater. wrote: »
    The Propeller's multiple cogs give it advantages but with added complexity.
    Can do, but when starting out you hardly have to worry about the parallel
    processing. Just drop your serial, video, whatever ready made drivers you need
    in to your program and away you go. With the bonus that there are no interrupts
    to worry about.

    Continuing with your premise that you don't have to "worry about parallel processing" with the Propeller,
    you don't have to worry about interrupts with the Arduino initially - you can do many projects without interrupts.

    With a BS2 you don't have to worry with either one.
  • LeonLeon Posts: 7,620
    edited 2012-02-06 05:57
    Other devices generally have in-circuit debug, which helps beginners (and other users) a lot.
  • Heater.Heater. Posts: 21,230
    edited 2012-02-06 06:07
    Ah, Ron, you got me there.

    I have never used or seen a Basic Stamp. Probably because I have been avoiding BASIC since tech school back in 1974 and would never have imagined it being useful on a micro-controller.

    I always thought that firing up a Prop Tool and getting ones first few lines of Spin running was about as easy as it gets. If the Basic Stamp is even easier, well, jolly good.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-06 06:36
    Leon wrote: »
    Other devices generally have in-circuit debug, which helps beginners (and other users) a lot.

    I like the PICAXE "Simulate" debugging capability where you can set break points and single step through your code. It doesn't work well with all scenarios but it can really be helpful.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2012-02-06 06:46
    Heater. wrote: »
    Ah, Ron, you got me there.

    I have never used or seen a Basic Stamp. Probably because I have been avoiding BASIC since tech school back in 1974 and would never have imagined it being useful on a micro-controller.

    I always thought that firing up a Prop Tool and getting ones first few lines of Spin running was about as easy as it gets. If the Basic Stamp is even easier, well, jolly good.

    The "Getting Started with Parallax" web page does a good job comparing the Basic Stamp and Propeller.

    You'd be surprised how many large companies employ VBScript in web development when using Microsoft' IIS platform (Internet Information Server).
    It is often used in the server-side components while javascript is used on the client-side components.
  • shimniokshimniok Posts: 177
    edited 2012-02-06 08:06
    Seems like it would be helpful if there were a standard list of the first few projects to do on an MCU :)

    You might try a progression something like this:

    1. Blinky light (side note: on ARM7 I have invested several weeks, still nothing; all other MCUs, 10 minutes)
    2. Turn blinky light on/off with a single button input
    3. Hello world over serial
    4. two blinky lights; each with a cog
    etc...

    Definitely helps to start very very simple and slowly work your way up. I personally prefer to learn programming languages with the "how do I..." approach -- by working projects and learning instructions/syntax/expressions as needed.

    You can break down your project into steps. Start with #1 blinky light (pin output and some basic syntax) move on to pin input #2 ... Look up debouncing and implement. Now you have the fundamental basis for your project.

    The rest you add on as you go. Next perhaps learn serial so you can debug. Then work on decoding a numeric keypad. Then you're very close. Work out how to check the entered code against the password. Use # to terminate input to keep it simple. Add a status LEDs: green solid for "OK" and red (that you blink) after wrong code entered.

    Now all that's left is to figure out how to drive a relay. That requires some electronics. Best bet is to look around the internet for examples and try them and ask questions on forums. You may need to find an automotive forum or two for help as well. You'll probably want to think about an opto-isolator to prevent damage to the Prop and you'll also need to start thinking about a really good power supply as the vehicle power is rather hostile, ranging in voltage and with spikes and noise and whatnot from what I understand.

    Best of luck.
  • annonymousannonymous Posts: 14
    edited 2012-02-10 21:16
    I ended up going with the Arduino Uno. I have everything set up and running. I have all the components. The matrix keypad, the 12v 30A spdt relay, the NPN BJT(2N3904), 5 1k ohm resistors, 5 220 ohm resistors, 2 1N4004 and 2 1N4001 diodes, printed circuit board, 2 leds, and some other goodies.

    Questions; What size resistor do i but at the base of the transistor? I laid down a 1k ohm 1/4watt 5% tolerance. Should i have laid down the 220?

    heres is a schematic i laid out on fritzing for linux --->
    mcu4.jpg
    1024 x 584 - 38K
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-10 22:37
    Depends on the relay. Measure the resistance of the relay coil and report back if you can.
  • annonymousannonymous Posts: 14
    edited 2012-02-10 22:46
    The measured resistance on the coil reads 0.08
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-10 23:19
    0.08 KOhms? In that case, up to 1.8K should work, but 1K will be safe and easier. Don't want to go any lower than 220ohms, though.
  • annonymousannonymous Posts: 14
    edited 2012-02-11 00:05
    Circuitsoft, please explain to me how you calculated that?
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-11 00:20
    12V / 0.08K ohms = 150mA

    Arduino could be either 3.3v or 5v. Prop is 3.3v. Base-Emitter drop of a transistor is 0.7v

    3.3-0.7 = 2.6v

    Transistor current gain (hFE) is at least 100. Base current should be ~1.5mA.

    2.6v / 1.5mA = 1.73 kOhms
  • annonymousannonymous Posts: 14
    edited 2012-02-11 02:58
    thanks! So here's another question for ya before i fire this up. How do i tell what pin on the coil is positive and what pin is negative? Is there a way to test for it? Will it make a difference?
  • LeonLeon Posts: 7,620
    edited 2012-02-11 03:53
    It doesn't make any difference. You should have a diode across the coil, and that needs to be the right way round.
  • Mark_TMark_T Posts: 1,981
    edited 2012-02-11 05:26
    annonymous wrote: »

    heres is a schematic i laid out on fritzing for linux --->
    mcu4.jpg

    That circuit is seriously wrong. Can you see the problem?
  • LeonLeon Posts: 7,620
    edited 2012-02-11 05:28
    It won't work very well. :)
Sign In or Register to comment.