Shop OBEX P1 Docs P2 Docs Learn Events
Programming for BS2 to run an H bridge for a 9V DC motor and a Ping — Parallax Forums

Programming for BS2 to run an H bridge for a 9V DC motor and a Ping

NubyNuby Posts: 18
edited 2009-09-08 05:00 in Robotics
Information;
I having been flip flipping between what controller to start my learning programming for robotics and think I have finally landed on the BS2. I have the software downloaded, have a "Stamp in Class" Rev D board, have a BS2 module. Also have been learning other areas of robotics and built a chaises with wheels, have a 9V DV motor to run it, H bridge is built an works, have a ping I would like to use to make an avoidance bot to start with.

Questions;
1) Programing
·····a) interfacing the H-bridge to the BS2?
·····b) Getting the signals form ping to run the motor?
·····c) Are there programs that I can get an just modify for my hardware?
2) In general how do I go forward to put it together?
3) Any input I am not far along enough to ask about? (I know big question!)

Thanks Much
Nuby·

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-08-30 19:05
    1a) Depends on the H-Bridge. Did you build it yourself using discreet transistors? Did you use a driver chip? Some more information (including circuit diagram and datasheet, if appropriate) would be helpful.
    1b) You'll have to use the BS2 to interface between the two.
    1c) Look on the ping product page at parallax for demo code for that. That code will produce a variable with the distance value in it, which you can then pass to a routine to interpret that for your motor.
    2) Read the various Stamps in class texts, even if they don't do what you need. The idea is to learn how to program first, then try your hardware. Read the Basic Stamp Syntax and Reference guide too, cover to cover. A general introduction to programming book would also be a good place to start, even if the languages don't match. It's the principles that are there, not the syntax.
    3) Always look for resources. There are lots of them on the web, and Parallax is a great host (both on the main site and these forums). Also, be sure to take things step by step and not rush. Document all code that you produce, and don't use magic numbers.
  • GeorgeCollinsGeorgeCollins Posts: 132
    edited 2009-08-30 22:27
    I can definitely say this will work, if you have the right H-Bridge circuit. One of the first robots I built was a stamp running an H-Bridge and two tamiya motors. Until you show us the H-Bridge chip, board or kit you are planning on using, we will be spinning our wheels trying to tell you how it can work-- but in general yes it can work.

    A ping and an H-Bridge work well with a stamp, because in general you just set a pin high or low to drive a motor, you don't have to pulse it like you do a servo. So you can set the pins for drive wheels and measure pulses from the ping sensor. Works great.

    If you are thinking of driving your Stamp with a 9V transistor battery, and you have a 9V DC motor, you probably need a separate power supply for the motors. Motors tend to require more current then a stamp, but I am only speculating because I don't know what motor you are working with. One cardinal rule I advocate in robots is that you should try to run your drive train off a separate power supply then your microprocessor. If you don't, your drive train can brown out the microprocessor and cause you endless unpredictable problems.

    It would be great if you could explain a little more about the H-Bridge and a little more about the motor, but in general what you are trying to do is possible and not hard to program if you are comfortable with stamps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Robots
  • NubyNuby Posts: 18
    edited 2009-08-30 22:28
    H Brdge parts
    1a)
    4 - SPST 5VDC Reed Relays (Radioshack Model: 275-232 Catalog #: 275-232)
    1 - SPDT 5VDC Reed Relay (Radioshack Model: 275-240 Catalog #: 275-240)
    1 - package of 9V battery clips (Radioshack Model: 270-324 Catalog #: 270-324)
    1 - Toggle or slide switch (SPST)
    1 - 7805 Voltage Regulator (Radioshack Model: 7805 Catalog #: 276-1770)
    1 - PC Board (Radioshack Model: 276-150 Catalog #: 276-150)
    1b&c)
    I know but where can i gat a sample and how do i nest it into the motor running programm?
    2) Was looking for a starter program to use and experiment with.
    3) Can you be more specific?

    Thanks
    Nuby
  • NubyNuby Posts: 18
    edited 2009-08-30 22:42
    Oh Yea about the motor(s) I have options Tamiya kits Planetary gear boxes as well as dual motors.

    Thanks
    Nuby
  • FranklinFranklin Posts: 4,747
    edited 2009-08-31 02:10
    You'll need to start off by attaching a drawing or schematic of the H bridge as built. We will need the specs on the reed relays for the input side. Parallax sells several Hbridges and there is code specific to them you can look at for ideas.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • NubyNuby Posts: 18
    edited 2009-08-31 03:20
    The h-Bridge is built i need program linking it all up.

    thanks
    Nuby
  • FranklinFranklin Posts: 4,747
    edited 2009-08-31 20:00
    How is the the H bridge built (SCHEMATIC) ? the code depends on how the hbridge is connected to the stamp, the motors and power. Please help us help you. Otherwise here is some code.
    ' =========================================================================
    '
    '   File...... Stepper_27964.BS2
    '   Purpose... Simple Stepper Motor Demo
    '   Author.... Parallax, Inc. (Copyright (c) 2004, All Rights Reserved)
    '   E-mail.... [url=mailto:support@parallax.com]support@parallax.com[/url]
    '   Started...
    '   Updated... 18 MAR 2004
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    ' Simple stepper motor (Parallax #27964) demonstration rotates motor one
    ' full revolution clockwise, pauses, then rotates one full revolution
    ' counter-clockwise. After another short pause, the process repeats.
    '
    ' Connections:
    ' -----------------------------------------------
    ' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Black)
    ' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Orange)
    ' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Brown)
    ' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
    '
    ' Note: Do NOT connect stepper motor wires directly to the BASIC Stamp.
    '       See Parallax documentation for complete connection schematic.
    
    ' -----[noparse][[/noparse] Revision History ]------------------------------------------------
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    Phase           VAR     OUTB                    ' phase control outputs
    
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    idx             VAR     Byte                    ' loop counter
    stpIdx          VAR     Nib                     ' step pointer
    stpDelay        VAR     Byte                    ' delay for speed control
    
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    Steps           DATA    %0011, %0110, %1100, %1001
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    Setup:
      DIRB = %1111                                  ' make P4..P7 outputs
      stpDelay = 15                                 ' set step delay
    
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Main:
      FOR idx = 1 TO 48                             ' one revolution
        GOSUB Step_Fwd                              ' rotate clockwise
      NEXT
      PAUSE 500                                     ' wait 1/2 second
      FOR idx = 1 TO 48                             ' one revolution
        GOSUB Step_Rev                              ' rotate counter-clockwise
      NEXT
      PAUSE 500                                     ' wait 1/2 second
      GOTO Main
      END
    
    ' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
    ' Turn stepper clockwise one full step (7.5 degrees)
    Step_Fwd:
      stpIdx = stpIdx + 1 // 4                      ' point to next step
      GOTO Do_Step
    
    ' Turn stepper counter-clockwise one full step (7.5 degrees)
    Step_Rev:
      stpIdx = stpIdx + 3 // 4                      ' point to previous step
      GOTO Do_Step
    
    ' Read new step data and output to pins
    Do_Step:
      READ (Steps + stpIdx), Phase                  ' output new phase data
      PAUSE stpDelay                                ' pause between steps
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen

    Post Edited (Franklin) : 8/31/2009 8:06:32 PM GMT
  • ercoerco Posts: 20,256
    edited 2009-08-31 20:32
    Nuby: Your Radioshack 275-240 is a good relay to use, although it's not a reed relay. You can use two of them in a simple H-bridge circuit I sketched up in the thread at http://forums.parallax.com/showthread.php?p=749676

    Best, Erco

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • NubyNuby Posts: 18
    edited 2009-09-08 05:00
    How does the the basic stamp interface with the H Bridge?

    560 x 420 - 47K
    560 x 332 - 20K
Sign In or Register to comment.