Shop OBEX P1 Docs P2 Docs Learn Events
Expanding the BS2 Homework Board I/O — Parallax Forums

Expanding the BS2 Homework Board I/O

kleekrukleekru Posts: 32
edited 2011-05-01 17:41 in BASIC Stamp
Hello all,
I need·someone·to dumb things down for me a little if you have the patience. I am a complete beginner with high hopes.
I have the BS2 Homework board and I'm enjoying my new foray into the·world of microcontrollers.

I'm expecting to run 12 servos that could each receive different instructions based on one of 5 pedals being pushed. The 5 pedals will be configurable to represent a different combinations of servo instructions based on a grid of switches.

I think I know how to program this based on the PBASIC in the book but with the high number of inputs and outputs, it is clear I'll go beyond the existing breadboard.·Someone in another thread·mentioned "74HC595 is very good for output use and the 74HC165 is good for input use." I looked them up but I don't have a clue how to hook them up to the Homework board and translate them into additional I/O pins. I suspect I need an additional breadboard and a way to link the Homework board with the expanded breadboard?? Where do the two units you mention come in and how do I address the new I/O locations in the programming? I've been looking around for a rather elementary description of how to make this work without luck. Anywhere you can point me or any quick tips?

I also expect I'll need to address how I get power to the servos.· I doubt the 9V battery will provide what·is needed (I'm also new to electronics).· Each servo needs to press about a·pound of pressure and there could be·up to·6·engaged·with one pedal push.·

Any answers that don't sound too much like "stick to your day job" will be appreciated.· Thanks for your patience!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-14 14:38
    1) Please don't post duplicate messages. It's against forum rules and it doesn't get you faster or better answers. You've already got one thread going. Stick with that. If you want, you can change the title of a thread you've started by using the pencil icon that appears in the upper right hand corner of your first message..

    2) A single servo motor can draw up to about 1A when starting to move under mechanical load. While moving under light load, this drops to maybe 1/3A. An idle servo (just sitting there) would draw less yet. With 6 servos in motion at a time, that's 6-8A at 6V. Do you particularly want to run this off batteries? If so, how long does it have to operate before charging? How often would the pedals be actuated?
  • kleekrukleekru Posts: 32
    edited 2009-08-14 15:34
    Thanks Mike:
    1) I realized I may have taken the other thread off on a tangent after the fact and posted here... thanks for setting me straight!

    2) Regarding the power requirements, I expect to actuate the pedals roughly once every 5-10 seconds and it should be reliable for at least 30 minutes. The "What's a Microcontroller" book refers to an AC adapter that attaches to the 9V connections. Would that do the trick. I don't necessarily need batteries but having the option to run off only a battery for a period of time is nice.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-14 16:24
    Servos don't need a source of regulated power. Anything stable from around 4.5V to around 6V, maybe 7.2V will do. The Homework Board can run from a 6V to 7.2V supply as well.

    From your description, there are going to be 6 servos in motion anywhere from 25% to 50% of the time. That could be an average current of 1-3A.

    Something like a SLA (Sealed Lead-Acid) battery ([noparse][[/noparse]ur]http://www.radioshack.com/product/index.jsp?productId=3307865) would work well. There are all sorts of battery chargers available for something like this since they're common for motorcycle use and riding toys.

    The typical AC adapters you describe wouldn't work since you need much more current than they would have available. You really do need something that can supply 6A peak.
  • kleekrukleekru Posts: 32
    edited 2011-04-30 16:55
    Hello again... still trying... or I should say, I'm trying again after a break for the winter.
    I've incorporated 5 74hc595's and 4 74hc165's into a board. I've separately wired (and tested) a group of 18 switches and a separate board with 24 LED's. Generally, I would like the LED's to light differently based on which switches I flip...

    My problem is that the status of the switches do not seem to be going through the shift registers properly. I'm getting random values without changing the switches at all (and there seems to be some pattern at first that indicates some strange shifting.

    I've checked and re-checked my wiring and I'm rather confident it is following the schematic in the StampWorks experiment to tie and cascade the 595's and the 165's together (including the 4.7K Ohm resister between PIN 14 of the 595 and PIN 7 of the 1st 165).

    Here's the code I'm using (leveraged mostly from the StampWorks experiment)... and I've included the results after.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [ Program Description ]
    '
    ' This program demonstrates the ability to use the 74HC595 and 74HC165
    ' together with the fewest number of BASIC Stamp IO pins. This is
    ' accomplished by placing a 4.7K resistor between the data out (pin 7) of
    ' the 74HC165 and the data in (pin 14) of the 74HC595. The serial data
    ' pin from the BASIC Stamp connects to the 74HC595.
    '
    [ I/O Definitions ]
    Clock PIN 0 ' shift clock (74hc595.11)
    SerData PIN 1 ' serial data (74HC595.14)
    Latch PIN 2 ' output latch (74HC595.12)
    Load PIN 3 ' input load (74HC165.1)
    '
    [ Constants ]
    DelayTime CON 1000
    '
    [ Variables ]
    xInputs1 VAR BYTE ' external inputs
    xInputs2 VAR BYTE ' external inputs
    xInputs3 VAR BYTE ' external inputs
    xInputs4 VAR BYTE ' external inputs
    '
    [ Initialization ]
    Reset:
    'LOW clock
    LOW Latch
    HIGH Load
    DEBUG CLS,
    "XInputs 76543210", CR,
    "

    ", CR,
    "Status ........"
    '
    [ Program Code ]
    Main:
    DO
    GOSUB Get_165 ' get inputs
    GOSUB Put_595 ' move to extended outputs
    DEBUG CRSRXY, 10, 2, BIN8 xInputs1, BIN8 xInputs2, BIN8 xInputs3, BIN8 xInputs4 ' display current status
    PAUSE DelayTime ' pad the loop a bit
    LOOP
    '
    [ Subroutines ]
    Get_165:
    PULSOUT Load, 5 ' load inputs
    SHIFTIN SerData, Clock, MSBPRE, [xInputs1, xInputs2, xInputs3, xInputs4] ' shift them in
    RETURN

    Put_595:
    SHIFTOUT SerData, Clock, MSBFIRST, [xInputs1, xInputs2, xInputs3, xInputs4] ' send inputs to 595
    PULSOUT Latch, 5 ' latch 595 outputs
    INPUT SerData ' float data I/O line
    RETURN


    And the Results:
    11111111111111111111111111111111
    11111111111111111111111111111111
    00000000111111111111111111111111
    00000000000000001111111111111111
    00000000000000000000000000000000
    00000000000000000000000000000000
    11110000000000000000000000000000
    11111111111111111111000000000000
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    11111111111111111111111111111111
    00000000111111111111111111111111
    00000000000000001111111111111111
    00000000000000000000000000000000
    00000000000000000000000000000000
    11000000000000000000000000000000
    11111111111111111111111100000000
    11111111111111111111111111111111
    11111111111111111111111111111111

    Any ideas what I'm doing wrong??

    Also, if anyone can explain the modes in the SHIFTIN and SHIFTOUT commands (i.e. MSBPRE, etc), I would like to understand what they do.

    Thanks!
    Kevin
  • ercoerco Posts: 20,256
    edited 2011-04-30 17:44
    Switching lots of LEDs is one problem, driving multiple servos is quite another. You don't simply "turn a servo on", you send it a constant stream of special pulsewidth pulses. I don't think those 74hc595s are going to help you. Realistically, a BS2 HW board is about maxxed out driving 4 servos. If you want to run more (or 12), you'll need more horsepower, like a specialized servo controller.

    Have you experimented with driving 2 or 3 servos yet? With a BS2, you have to pulse them all together in one continuous loop. Good programming stuff. Dive right in.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-30 20:58
    For the SHIFTIN modes, look at page 432 of the Basic Stamp Syntax and Reference Manual. For the SHIFTOUT modes, look at page 436 of the Manual. Both are pretty complete descriptions.

    Part of the problem may be a sometimes undefined clock state. Make sure that Clock is initialized to output low.

    How about trying the program first with some output test data. Try doing the SHIFTOUT with known constant data or known dynamic (changing) data, like an up counter rather than trying to copy inputs to outputs.

    The 5th 74HC595 is going to show weird results since the clock will cause it to shift in the 74HC165 data while you're trying to read the 74HC165s. Then, when you actually try to shift in data, the last 8 bits will get shifted to the 5th 74HC595.

    Do you have the clock inhibit input to the 74HC165 tied low?

    I think it's a bad plan to start off with this sort of pin "saving". It might work eventually, but you're trading ease of debugging and reliability for a single I/O pin. Get it working first with separate clock and data lines or a shared clock line, then try it with shared clock and data lines. I think you've wired something wrong or left a pin floating.
  • kleekrukleekru Posts: 32
    edited 2011-05-01 09:03
    Thanks Erco... Actually, I do have an SSC32 to drive the servos and a separate power supply... I've tested all the pieces separately and I'm fairly certain it will work... but putting it together I'm running into issues. I'm not at the point where I'm building the servos back in. I know enough to be dangerous but not enough to get myself out of a bind just yet...

    Getting better though.

    Mike, you're on top of it as usual. I was also thinking I should separate the 595 chain from the 165 chain... that's my next step. I'll also remove the 5th 595... I thought that might be another problem I would hit... but based on the read of the inputs, it didn't seem to be related to the pattern above. Nevertheless, I can manage without it. I'll let you know how it goes. Oh, and I'll take a closer look at the pages you mention. Thanks again!

    ... one last confirmation. "clock inhibit input to the 74hc165 tied low" means putting a resistor on pin 15 to VSS? (I'm half guessing on this).
  • kleekrukleekru Posts: 32
    edited 2011-05-01 10:10
    I split out the Input 165 chain from the Output 595 chain and now it is working perfectly! I might be using more pins than I need but is certainly easier to troubleshoot as you suggested.

    Here's the new code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [ Program Description ]
    '
    ' This program demonstrates the ability to use the 74HC595 and 74HC165
    ' together with the fewest number of BASIC Stamp IO pins. This is
    ' accomplished by placing a 4.7K resistor between the data out (pin 7) of
    ' the 74HC165 and the data in (pin 14) of the 74HC595. The serial data
    ' pin from the BASIC Stamp connects to the 74HC595.
    '
    [ I/O Definitions ]
    oClock PIN 0 ' output shift clock (74hc595.11)
    oSerData PIN 1 ' output serial data (74HC595.14)
    oLatch PIN 2 ' output latch (74HC595.12)
    iClock PIN 3 ' input clock (74hc165.2
    iSerData PIN 4 ' input serial data (74hc165.7
    iLoad PIN 5 ' input load (74HC165.1)
    '
    [ Constants ]
    DelayTime CON 50
    '
    [ Variables ]
    xInputs1 VAR BYTE ' external inputs
    xInputs2 VAR BYTE ' external inputs
    xInputs3 VAR BYTE ' external inputs
    xInputs4 VAR BYTE ' external inputs
    '
    [ Initialization ]
    Initialize:
    LOW iClock
    LOW oClock
    LOW oLatch
    HIGH iLoad
    DEBUG CLS,
    "XInputs 76543210765432107654321076543210", CR,
    "

    ", CR,
    "Status ................................"
    '
    [ Program Code ]
    Main:
    DO
    GOSUB Get_165 ' get inputs
    GOSUB Put_595 ' move to extended outputs
    DEBUG CRSRXY, 10, 2, BIN8 xInputs1, BIN8 xInputs2, BIN8 xInputs3, BIN8 xInputs4 ' display current status
    PAUSE DelayTime ' pad the loop a bit
    LOOP
    '
    [ Subroutines ]
    Get_165:
    PULSOUT iLoad, 5 ' load inputs
    SHIFTIN iSerData, iClock, MSBPRE, [xInputs1, xInputs2, xInputs3, xInputs4] ' shift them in
    RETURN

    Put_595:
    SHIFTOUT oSerData, oClock, MSBFIRST, [xInputs4, xInputs3, xInputs2, xInputs1] ' send inputs to 595
    PULSOUT oLatch, 5 ' latch 595 outputs
    INPUT oSerData ' float data I/O line
    RETURN

    Thanks Mike!!
  • ercoerco Posts: 20,256
    edited 2011-05-01 17:41
    Glad to hear you got her done! Another way (hardware intensive) would be to use 12 output pins with 6 servopals tro drive your servos, which would leave you 4 pins to read your 5 switches. Some "one pin, many switches" trickery could get you going.
Sign In or Register to comment.