Shop OBEX P1 Docs P2 Docs Learn Events
Trail Plug to Basic Stamp ({$STAMP BS2} ' {$PBASIC 2.5}) Chip — Parallax Forums

Trail Plug to Basic Stamp ({$STAMP BS2} ' {$PBASIC 2.5}) Chip

Jeff2Jeff2 Posts: 46
edited 2010-04-05 02:41 in BASIC Stamp
What I am looking to do is, Use the pulses coming from the trailer plug, going into the Basic Stamp, if Brake Light is On. It will make A set of 6 Led's come on. If the Right Turn Light (flashing), it will make the same set of 6 Led's sequence or Left to right.

On your stander trailer plug there is, (USA) White wire, Brown wire, Yellow wire and Green wire). I am going to hook up the (Green wire is Brake Light and Right Turn Light In one wire) coming from the trailer plug to (Pin1) of the Basic Stamp. There will
Resistor's So the (V) will be right. What I don't know how to do is? Program the Basic Stamp, so it knows then the Brake Light is on, or the Right Turn Light is flashing.

So is there A way I can make A (Pulsin to tell the time from one to the other one.


Brake (111111111111111111111111111111) ((1=on and 0=off))
Right Turn Light (001001001001001001001) ((Brake and Turn pulses are coming from the same Wire, green))


This Is A program to Show you what I am looking for? I don't know how to find the time the brake light and turn light is on for.



'{$PBASIC 2.5}
time VAR Word(2)

FREQOUT 4, 2000, 3000
DO

DO
PULSIN 9, 1, time(0)
LOOP UNTIL time(0) > 1000
PULSIN 9, 0, time(0)
PULSIN 9, 0, time(1)



(Brake Light).......IF (time(1) < 500) AND (time(0) < 500) THEN
High Pin 4
High Pin 5
High Pin 6
High Pin 7
High Pin 8
(Right Turn Light)........ELSEIF (time(1) < 500) AND (time(0) > 500) THEN
Low Pin 4
Low Pin 5
High Pin 6
Low Pin 7
ENDIF
LOOP ' Repeat main loop.



if you can help great

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-02-18 01:10
    The PULSIN command is for much shorter durations than you need. You could do something like this instead;
    time  VAR   Byte
    i     VAR   Byte
    
    Timer:
    For i = 0 to 100
    IF Green = 1 Then time++
    Pause 10
    NEXT
    
    RETURN
    
    


    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 2/18/2010 1:16:19 AM GMT
  • JDJD Posts: 570
    edited 2010-02-18 01:19
    Jeff,

    No doubt there is more than one way to accomplish this; however are the values for brake (111111111111111111111111111111) and turn (001001001001001001001) the value you see on the signal pin? Is it always the same value? ie if the brake is pressed does the value always match 111111111111111111111111111111? or is the pin held HIGH for a certain period? If the values are the same, I would imagine you could use either·COUN or just take a small sample since (like W9FG0 suggested) the signal looks like it repeat and compare it to a known value for BRAKE, TURNL, TURNR, NONE and so on; If you can verify the signals are the same, then that would be a good point to build from.

    For the programming syntax, I would recommend downloading the BASIC Stamp Syntax & Reference Manual; the PDF has the commands, how to use them and even some samples to help learn faster. This will help with formatting the IF...THEN statements, HIGH/LOW command and many others.

    BASIC Stamp Syntax & Reference Manual:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • $WMc%$WMc% Posts: 1,884
    edited 2010-02-18 03:30
    Jeff2

    I think Your way over thinking this project.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA
  • W9GFOW9GFO Posts: 4,010
    edited 2010-02-18 04:52
    This is what I would try first - From the other thread;
    kf4ixm said...
    Another option to all this would be to take a stopwatch, time how long that your turn signal stays lit when blinking, then just concentrate on making the light sequence that you desire to execute within the 'on' time of your flash. the you wouldn't have to mess with programming all that logic, when the signal is high, the sequence for that pin starts, then finishes before the flash goes off, which turns the led's off, then on the next flash on, the sequence starts all over again. when you hit the brake, the sequence starts for both the left and right, finishes, then stays on as long as the brake is applied (as long as the input is high). then the turn signals would be 'self-resetting' as the sequence would start over everytime the flash input goes high.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-19 23:55
    I am looking at the (IR Remote For the Boe-Bot). I came to this Program. It is saving the
    duration as MS. Is there any way that I can save the time as Seconds? Then I can hook it up to my trail plug and tell the second's, and make A program to run. There is About 3 seconds between one flash to the next flash.

    The second Program I how I would know if it were the brake or Right Turn Light Flashing.

    
    ' IR Remote for the Boe-Bot - CountRestingStates.bs2
    ' Capture and count the number of 20 ms+ (high) resting states.
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    
    
    time VAR Word
    counter VAR Word
    
    
    DEBUG "RESTING STATE", CR,
          "Repetitions Current Duration", CR,
          "             (microseconds) ", CR,
          "----------- ----------------"
    
    
    DO
    
    PULSIN 9, 1, time
    IF (time > 1000) THEN
    counter = counter + 1
    DEBUG CRSRXY, 0, 4,
    DEC counter,
    CRSRXY, 13, 4,
    DEC5 time * 2
    ENDIF
    LOOP
    
    
    





    
    ' IR Remote for the Boe-Bot - 2BitRemoteBoeBot.bs2
    ' Control your Boe-Bot with an IR remote set to control a SONY TV
    ' with the 1-4 or CH+/- and VOL+/- keys.
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    time VAR Word(2) 
    DO ' Beginning of main loop.
    DO ' Wait for rest between messages.
    PULSIN 9, 1, time(0)
    LOOP UNTIL time(0) > 1000
    PULSIN 9, 0, time(0) ' Measure/store data pulses.
    PULSIN 9, 0, time(1)
    IF (time(1) < 500) AND (time(0) < 500) THEN ((((Brake))))
    high 1
    high 2
    high 3 
    ELSEIF (time(1) < 500) AND (time(0) > 500) THEN  ((((Right Turn Light)))))
    high 1
    low  2
    low 3
    high 4
    ENDIF
    LOOP ' Repeat main loop.
    
    
    






    Thank you very much
  • W9GFOW9GFO Posts: 4,010
    edited 2010-02-20 00:03
    Jeff2 said...
    Is there any way that I can save the time as Seconds? Then I can hook it up to my trail plug and tell the second's, and make A program to run. There is About 3 seconds between one flash to the next flash.

    Again, PULSIN will not work for pulses of such long duration. Look at this table - the maximum pulse length (for a BS2) is 131.07 mS.

    attachment.php?attachmentid=67937

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
    915 x 207 - 86K
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-20 00:06
    Thank you ............
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-21 00:01
    If I were to hook up, the trailer plug, A data pulse, then to the Basic Stamp, Could the Basic Stamp read the Brake Light or the Right Turn Light?

    The data pulse would be something like (Current Duration of 500 microseconds on and then off). So if you the brake light were on the data pulse
    would be on for a long time, and if the turn light were on, the data pulse would be on for 3 sec. and off for 3sec.

    Could the basic stamp tell if Brake was on or Right Turn was on....
  • JDJD Posts: 570
    edited 2010-02-22 17:14
    Jeff2,

    Do you·know what the voltage is of the signal pin? Is the signal·part·of the·cars·CAN protocol?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-23 01:09
    Is there some way that I can tell the pulses coming out of the trailer plug. So the Basic Stamp 2 can take A input, as A on or off.
    512 x 384 - 26K
  • JDJD Posts: 570
    edited 2010-02-23 01:30
    Jeff2,

    An option would be to use an opto-isolated circuit to use 12 V and BS2 safely. If the 12 V signal is used as the input the BS2 can watch an I/O pin to see if it's either high or low. That is just one option, no doubt there are many ways to tackle this situation. There is a module I used that was really easy to use but it was for higher voltages; but was still only about .25-.50 cents each. Do you have any opto-isolated IC?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-23 01:53
    I don't have one. But How do I make the BS2 know the difference between Brake pulse and Turn pulse.


    Brake and Right Turn, is one the same wire,

    Brake is (1111111111111111111111111111111) (1 = 12V) (0 = off)

    Right Turn is (1001001001001001001001001001) Both are on the same wire or input. So how does the BS2 read one from the other one.

    It may look like this from the green wire (1111111111111111111111Brake then it may switch to (100100100100111111111111111111).


    Thank you
  • JDJD Posts: 570
    edited 2010-02-23 02:02
    Jeff2,

    A option would be to watch the I/O pin and see if there is a transition in a known time frame; for example there is a timed transition that the blinker will have on and off time; since this time is slow enough to see the transition visually, you can take a sampling of that to see if the pin is always HIGH or toggling. Do you know the amount of time the pin takes to completed the transaction? For example, does the pin remain low for 1/2 second, then toggle, then remain high for 1/2 second and so on?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-23 02:14
    The Turn light is low for 3 Sec. before it light's up, to the next pulse. (00000000001 (3 Seconds) 100000000)
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-24 00:24
    Is there A easy way for the BS2, to know what the pulses that are coming into it are, so it will know how to switch the led's.

    I put A pic, of A Timing Diagram, to help people out, to know what I am trying to do.

    How do I program the BS2 to read the input, coming into it..........

    Post Edited (Jeff2) : 2/24/2010 1:24:21 AM GMT
    512 x 384 - 15K
  • JDJD Posts: 570
    edited 2010-02-24 19:36
    Jeff2,

    In that case you should be able to sample the signal pin to determine if the pin is toggling or remains at 12VDC. For example, once the I/O changes state (low/high); you can wait for 4 seconds and sample the I/O pin again; if it's HIGH then you can assume brake condition if it's low than a blinker condition. Would that delay be acceptable?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-02-25 02:29
    Thank you for your help, but
    could you send me some code for
    program this, just to help me
    get started, or tell me A place to
    look for this.


    Thank You. Jeff2

    Post Edited (Jeff2) : 2/25/2010 10:53:56 PM GMT
  • JDJD Posts: 570
    edited 2010-02-25 19:10
    Jeff2,

    Let me see if I can get an example up for you; it will be a little bit (day or 2) because of other projects, but I will try to have something up as an example by the end of this week.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-03-01 23:38
    Thank you for your help, but
    could you send me some code for
    program this, just to help me
    get started, or tell me A place to
    look for this.


    Thank You.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-03-02 13:18
    Hi Jeff2 , is it possible you could access the yellow wire (left turn) and use the yellow and green together·to form a truth table for the Stamp to base its conditions on.

    _G__Y__Out

    _0__0__Off

    _1__0__Right turn

    _0__1__Left turn

    _1__1__Brake

    Jeff T.
  • JDJD Posts: 570
    edited 2010-03-02 23:49
    Jeff2,

    Unsoundcode has a good idea, that actually would be much faster if you could use those wires. Can you verify if those wires can be used?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-03-03 01:21
    How about looking at both brake lights at the same time.
    If the right light is off and the left one is on, then the left one will be blinkig.
    If the right one is on and the left one goes off and on, then it is blinking.
    If both go on and off at the same time, then emergency flashers are on or the driver is pumping the brakes.

    I use a 4N32-Short opto to read up to 24 volt signals with my stamp designs.
    I think Toshiba makes them. They are not too fast, but rugged.
    A 1-2 k resistor will work fine.
    You can get them fom Dikey fairly cheap.

    Good Luck,



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alan Bradford ·N1YMQ

    Plasma Technologies
    Canaan NH 03741
    www.plasmatechnologies.com
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-03-03 01:22
    How aout 'You can get them from Digikey'
    www.digikey.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alan Bradford ·N1YMQ

    Plasma Technologies
    Canaan NH 03741
    www.plasmatechnologies.com
  • Jeff2Jeff2 Posts: 46
    edited 2010-03-03 23:08
    HI

    _G__Y__Out

    _0__0__Off

    _1__0__Right turn

    _0__1__Left turn

    _1__1__Brake

    I think this will work, but how do you program it, so when the (_1__0__Right turn) is on
    and the brake is off. Right turn light would be flashing, on and off, on and off, that
    mean's that the input to the 4N32 to the BS2, the data would be (0101010101) not A
    (1111111) like the Brake was on. So my LED-sequence, would be on for A bit and then off
    for A bit. I what them to run like A sequence. I think you still need A way that you can
    tell what the input is comming from the 4n32 to the BS2 is. So kind of timing program. That
    will tell the Brake light from the Right turn light. (Brake11111111) (Turn1 3sec. 1 3sec.)
    Maybe this will work......

    If the Brake is pushed on, it will send 12V on the green wire to the 4n32, From the 4n32 it
    will go to the BS2. From the BS2, it will tell if it is Brake or Right Trun. In this case
    it is Brake, so all led are on. Next if I turn on the Right Turn, it will allso send 12V to
    the 4n32, but it will be on 12v and off 12v and on 12v off 12v on 12v, and so on. From the 4n32 it will
    go to the BS2. The BS2 tell it is the Right Turn, becasue of the timming or the pulse. Then
    it would make the LED-sequence. That's what I need help with. Is there A Program or A way to program
    to tell the timming or pulse.



    So if I can get the Right side working, the other side willbe easy.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-03-04 00:58
    Hi Jeff , the truth table is a set of unique conditions , each output can only have one possible input combination. The input conditions are detected immediately.

    Once a condition has been met and the output detected then you can let your program go do something and then check back to see if the condition has changed or not.

    The above opens up a multitude of·possibilities for light sequencing.

    The 4 inputs to the truth table·could be converted to numerical values 0,1,2 & 3 and used in a simple program like the one attached , try entering those values in the debug panel.

    Jeff T.
  • Jeff2Jeff2 Posts: 46
    edited 2010-03-05 22:48
    Unsoundcode, your Trailer.bs2 work's great but, when you use the left Brake and Turn light at the same time, the program goes to Brake. Thank you for making the program. But is there A way that I can sample the signal pin to determine if the pin is toggling or remains at 3.3VDC. For example, once the I/O changes state (low/high); you can wait for 4 seconds and sample the I/O pin again; if it's HIGH then you can assume brake condition if it's low than a blinker condition.
  • TommmTommm Posts: 4
    edited 2010-03-11 03:35
    Thank you people for you'r help...
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-04 15:27
    Here try something like this

    '
    '   File...... SW21-EX14-Debounce.BS2
    '   Purpose... SCANNING AND DEBOUNCING MULTIPLE INPUTS More was Add
    '   Author.... Sam
    '   E-mail.... [url=mailto:sam1030@comcast.net]sam1030@comcast.net[/url]
    '   Started...
    '   Updated...
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    ' This program demonstrates the simultaneous debouncing of multiple inputs.
    ' The input subroutine is easily adjusted to handle any number of inputs.
    '
    ' -----[noparse][[/noparse] Revision History ]------------------------------------------------
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    '
    BtnBus        VAR          INB           ' four inputs, pins 4 - 7
    LedBus        VAR          OUTA          ' four output, pins 0 - 3
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    Led       VAR       Nib
    btns      VAR       Nib            ' debounced inputs
    idx       VAR       Nib            ' loop counter
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    DIRS = %1111111100001111
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Main:
    DO
    GOSUB Get_Buttons                 ' get debounced inputs
    IF btns ^ %0101  THEN             ' The two input must = 1 and the other inputs must = 0
                                      ' For this statement To be true
     led  = %0001.......>>>>>>>>>     ' HIGH OR LOW Command can not be used in these routines
    ELSE
    IF btns ^ %1111 THEN               
    led = %0000........>>>>>>>>>      ' HIGH OR LOW Command can not be used in these routines
    
    ENDIF
    ENDIF
    DEBUG HOME,
    " Inputs  = ", IBIN4 btns, CR,         ' display in binary mode
    " Outputs = ",IBIN4 Led
    PAUSE 5
    LOOP
    
    ' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
    Get_Buttons:
    btns = %1111 ' enable all four inputs
    FOR idx = 1 TO 5
    btns = btns & ~BtnBus ' test inputs
    PAUSE 5 ' delay between tests
    NEXT
    FOR idx = 5 TO 10
    Led = Led & ~LedBus ' test OutPut
    PAUSE 5 ' delay between tests
    NEXT
    RETURN
    

    _G__Y__Out

    _0__0__Off

    _1__0__Right turn

    _0__1__Left turn

    _1__1__Brake

    Main:
    DO
    GOSUB Get_Buttons                       ' get debounced inputs
     
    ' _G__Y__Out            Your truth table '_0__0__Off             %0000  any input pin 4,5,6,7 can be used 
    '_1__0__Right turn      %0100
    '_0__1__Left turn       %0001
    '_1__1__Brake           %0101
    
     
     
    IF btns ^ %0000  THEN                   ' OFF  The two input must = 1 and the other inputs must = 0
                                            ' For this statement To be true
    led  = %0000                            ' HIGH OR LOW Command can not be used in these routines
    ELSE
    IF btns ^ %0100 THEN                    ' RIGHT           
    led = %0100                             ' HIGH OR LOW Command can not be used in these routines
    ELSE
    
    IF btns ^ %0001  THEN                   ' LEFT
    led = %0001                             ' HIGH OR LOW Command can not be used in these routines
    ELSE
    IF btns ^ %0101  THEN                   ' BRAKE
    led = %0101                             ' HIGH OR LOW Command can not be used in these routines
     
    ENDIF
    ENDIF
    ENDIF
    ENDIF
     
    DEBUG HOME,
    " Inputs  = ", IBIN4 btns, CR,         ' display in binary mode
    " Outputs = ",IBIN4 Led
    PAUSE 5
    LOOP
    

    I am not sure how you·deal with this ....>>>>>>>
    IF the BRAKE and the TURN·SIGNAL on at the same time because you only have two wire
    This part is going to hard to deal with

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/4/2010 4:32:49 PM GMT
  • NWCCTVNWCCTV Posts: 3,629
    edited 2010-04-05 02:41
    Just a thought, but most brake light wires are only tied to the tail light together. Check your lights to see if that is how it is wired. You could use one pin for brake light and the other for the blinker.
Sign In or Register to comment.