Shop OBEX P1 Docs P2 Docs Learn Events
useing a BS-2 to drive 3 relays w/ commands from the com port... — Parallax Forums

useing a BS-2 to drive 3 relays w/ commands from the com port...

freekfreek Posts: 22
edited 2005-04-19 23:14 in BASIC Stamp
Hello fellow BS'ers smilewinkgrin.gif ,

I have an interesting project here at work that I would like to get some help on.

I opperate a CMM(coordinate measuring maching), and am trying to monitor its status.· I decided to use a 'christmas tree', a bunch of lights stacked on a pole, to visually show me whats going on.· I want to send 3 commands out the serial port of the cmm to the BS-2: scaning, finished, error.

1st, shut all lights off before lighting any light, then when the stamp gets the 'scaning' command, i want it to flash a yellow light, 'finished' flash a white light, 'error' flash a red light.· the stamp can do the flashing, or just close a relay to a strobe/flasher unit.

i looked at Ex31 - PollStamp.BS2, and tried to hack it to my needs.· needless to say that didn't work very well.

If you guys could point me in the right direction, that would be great.· sample code is great, but no compleate projects please.· i would like to try this myself.

i'll put what i have sofar..

thanks a lot.

Will

Comments

  • Shawn LoweShawn Lowe Posts: 635
    edited 2005-04-05 23:11
    On your lookdown command, you must have a serperate variable for the results of your command. You cant put that back in cmd variable.
    Shawn Lowe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    Remember - No matter where you go
    There you are.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-05 23:21
    Sorry, Shawn, but you're mistaken on that point about LOOKDOWN -- you CAN in fact use the same variable for input and output.· I'm betting, actually, that Will's program was derived from one of mine (the code is very familiar) and I use this technique quite a lot as it's an easy way to validate a value in the list.

    Will: Use PBASIC 2.5 syntax and the PIN definition so that you can use the "= On" and "= Off" constructs with the LEDs.· See my edits (attached).


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Shawn LoweShawn Lowe Posts: 635
    edited 2005-04-06 03:09
    Well-
    Ummm, why yes....right there in the help file....hem *cough*.
    Your right, of course, silly me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    Remember - No matter where you go
    There you are.
  • freekfreek Posts: 22
    edited 2005-04-06 14:42
    Thanks Jon, the PINS definition worked. Now I'm going to try to get the stamp to respond to text rather than hex.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 14:54
    That's a bit trickier, but doable.· Here's a strategy I've used:

    Say you·want to respond to "G", "Y" or "R"

    Get_Cmd:
    · SERIN Sio, Baud, [noparse][[/noparse]cmd]
    · LOOKDOWN cmd, [noparse][[/noparse]"gGyYrR"], cmd
    · IF (cmd > 5) THEN Get_Cmd
    · cmd = cmd / 2

    At the end of this routine, cmd will contain a value from 0 ('G') to 2 ('R') that you can use in your BRANCH instruction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-06 15:55
    Thanks again. Now its best to do the flashing externaly because if i do it on the stamp it wont be able to process another command, right?

    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 17:45
    With a bit of programming you can handle the flashing too.· By incorporating the timeout capability of SERIN, you can use that as a flash timer.· As I needed a break from updating the SX/B help file, I've written a version of your program that does what you want.· I'll leave the rest to you.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 4/6/2005 5:55:02 PM GMT
  • freekfreek Posts: 22
    edited 2005-04-06 17:53
    Jon, I tried to d/l the code, but it said it does not exisit or permision denied...

    Will

    <edit> nevermind </edit>
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 17:55
    Sorry, I was looking at it and found some improvements could be made -- download the version that's there now; I'm done. I promise.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-06 20:08
    I revamp the whole thing, I decide to give it a binary number, the first 3 bytes are for the leds and the last is the flashing byte.
    I'll attach the file.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 20:43
    If by "binary input" you mean you're just banging 1s and 0s on your keyboard, you don't need four byte variabled. You can use a single byte for cmd and do the input like this:

    SERIN RxD, Baud, TmOut, Toggle_Leds, [noparse][[/noparse]BIN4 cmd]

    -- with PBASIC you can move the individual bits from cmd where the need to be used. With a small micro like the BASIC Stamp learning to conserve variable space is an importannt tool, even if you don't need it at the momemt.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-06 21:16
    Being very new at this, I thank you for all your help.· Now that it's prototyped, can i use the BASIC Stamp 2 OEM Module (Assembled)
    to get this ready for shop use, or is there a better board?

    I have also attached the final code.

    Thanks again,

    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 21:21
    The OEM BS2 is fine -- a BS2 module is a bit smaller. If you wanted to make it really small you could port the code to SX/B (would take a little effort) and run it on a $5 SX28.

    You've got a couple small errors in your program. Change....

    cmd(4) = 0 to cmd = 0

    and...

    DEBUG STR cmd to DEBUG BIN4 cmd

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-06 22:09
    thanks for catching that.· How much would it cost to start developing in SX?



    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 22:24
    About $90 -- that gives you a kit with the SX-Key programming tool, the SX-Tech board, a couple SX28 chips and a couple resonators. Included in the SX-Key software is a free PBASIC-like compiler called SX/B.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-15 22:10
    I just got the BS2 OEM module yesterday, and i got everything hooked up today.· I d/l the progam and tried to run it.· it didn't work.· i think it has something to do w/ the serial port.

    in my code i have:

    RxD             CON     14                      ' serial input - to INEX RxD
    TxD             CON     16                      ' serial output - to INEX TxD
    


    i can receive my "ready..." prompt, but the BS2 dosen't want to receive.

    is the serial port on the module only for programing...?


    thanks,

    Will
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-04-15 22:40
    No, the serial port on the BS2 can be used for I/O.

    However, you need to use "16" for both SERIN and SEROUT. Really, the I/O pins go from 0 to 15. The I/O pin 16 is only used for SERIN/SEROUT, and indicate that the BS2 should use the programming port.

    SERIN 16 ... reads the 'RX' pin (physical pin 2?). SEROUT 16 ... writes the 'TX' pin (physical pin 3?).
  • freekfreek Posts: 22
    edited 2005-04-18 18:17
    OK, I am driving a 5vDC relay with pin 0.· I can actuate it, but for some reason the relay hangs (stays on) w/ no voltage at the pin.· The relay is a Coto 9007-05-01.· specs @ http://www.cotorelay.com/9000_Series.pdf .· The relays are switching a 12vDC strobe light module.· Any ideas, or should i just switch it w/ a 2n2222?



    Thanks,



    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-18 18:20
    In my book, it's NEVER okay to switch a relay directly with a microcontroller, no matter what the specs. Use an buffer (transistor, MOSFET, whatever you like best) -- you may save a few cents connecting directly, but if you make an error you may blow-out a BASIC Stamp pin. Make sure that you put a diode (reverse biased) across the relay coil (this is standard practice).

    Have a look at this: http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-18 19:20
    More clarification:

    I had a 2n2222 to the relay, to protect the stamp, should I just use the transistor?· Maybe not the 2222, cause my load draws 150mA @ 12v.· Those relays have built in diodes.· I'm still trying to figure out why they are staying latched.



    Thanks again,



    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-18 19:28
    Are you driving the control pin low to turn off the transistor? If not, you'll need a pull-down to keep the transistor off when the Stamp pin floats.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • freekfreek Posts: 22
    edited 2005-04-18 19:38
    Jon,

    I am driving it high, w/ a 1k resistor in line w/ the base.



    p0---^^^^---base of 2n2222
           1k
    



    Will
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-18 19:42
    What are you doing to turn it OFF?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • KenMKenM Posts: 657
    edited 2005-04-18 19:47
    I believe Jon wants you to do something like the pic below.

    And of course as Jon mentioned, what are doing to turn off the transistor?
    440 x 221 - 7K
  • freekfreek Posts: 22
    edited 2005-04-18 19:49
    I turn the pin off.


    simpilied code:
    yellow          PIN     0
    

    DIR0 = %1
    

    yellow = 0
    

    1 = +5vDC and 0 = 0v, right...?

    ·
  • freekfreek Posts: 22
    edited 2005-04-18 20:02
    attached schematic, done in mspaint, i need to find a free schematic tool.
    307 x 263 - 11K
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-18 20:14
    Here's what I'm thinking -- a smaller base resistor to make sure the transistor saturates, and a pull-down that's not so stiff.

    You can use the schematic program that comes with ExpressPCB -- it's free, and will let you move your projects to a PCB more easily.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
    453 x 415 - 4K
  • freekfreek Posts: 22
    edited 2005-04-19 23:14
    Ok, I think I'm ready to wrap this up.

    Comments, thoughts...?





    Will
    1378 x 1276 - 24K
Sign In or Register to comment.