Shop OBEX P1 Docs P2 Docs Learn Events
Scribbler S2 & Ping question. — Parallax Forums

Scribbler S2 & Ping question.

MarkPorterMarkPorter Posts: 9
edited 2012-08-13 15:53 in Robotics
Hi all,

I've read much about the possibilities of hacking the S2, adding additional sensors etc, yet so far the only hack I've come across is the pen lifter?

I noticed from reading the Ping manual that the signal line requires a 1k ohm resistor on it when using with the Propellor, yet other threads I've read on this forum conflict with this information (although in fairness these were general propellor threads & not specific S2 threads)

Has anyone actually added a ping to an S2 yet? If so can you offer me some advice / guidance?

Cheers

Mark
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-29 07:26
    The hacker port on the S2 already has a 3.3V to 5V level translator as well as connections to ground (Vss) and +5V, so you should be able to just connect the PING))) directly to the hacker port. I don't have an S2, so I haven't tried it myself, but I've connected a PING))) directly to a Propeller (using a 1K resistor in the signal line) and it works fine (see Propeller BoeBot).
  • ercoerco Posts: 20,256
    edited 2011-12-29 09:14
    Mike Green wrote: »
    I don't have an S2, so I haven't tried it myself...

    Ken, get an S2 to Mike and step on it! :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 12:08
    MarkPorter wrote: »
    Has anyone actually added a ping to an S2 yet? If so can you offer me some advice / guidance?

    Mark,

    I just tried adding a Ping to my S2. It did not work. Darn!

    I had just tested the Ping code and sensor with a QuickStart board and it worked fine. When I connected the Ping to the S2, nothing.

    I'm pretty sure the level shifter is to blame.

    I'll break out my oscilloscope and see if I can figure out a way of getting the Ping to work with the S2. I know from experience the level shifter can't transmit and receive signals as fast as a bare Prop IO pin. I'd bet a couple of delays in the Ping object should get things to work.

    I'll report back here once I have some more info. It might take a couple of days to find the time to do this.

    BTW, welcome to the forum!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 12:51
    I'm starting to doubt there is an easy way of interfacing the Ping with the S2.
    I think the Ping's pulse low is too short to make it through the level shifter.
    This is the code I used to trigger the Ping:
    repeat
        outa[PING_Pin]~~                                                                   
        dira[PING_Pin]~~                                                                   ' Make Pin Output
        outa[PING_Pin]~                                                                  
        dira[PING_Pin]~                                                                    ' Make I/O Pin Input
        waitcnt(clkfreq / 200 + cnt)                                                                            
    

    This is what it looked like with the oscilloscope. (The blue line is the channel connected to the Ping. The red channel wasn't connected to anything.)


    attachment.php?attachmentid=88028&d=1325191167

    The long low pulse is from the Prop. I think it's odd it wasn't pulled very low. It looks like it was low enough to trigger the Ping though. The short down blip is the Pings response (I assume). I think the low blip is too short to make it through the level shifter.

    Anyone have any suggestions?
    556 x 545 - 18K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 13:06
    The long pulse is not pulled lower because you're not pulling it low. It occurs during the waitcnt when dira is set to input on the pin. The very low, narrow pulse is from the Prop, during that short interval between outa[PING_Pin]~ and dira[PING_Pin]~.

    Hmm. Now that I think of it, that doesn't quite make sense either, given your program's timing. In any event, be sure to read the Ping))) documentation regarding how it responds to the start pulse and how long that pulse has to be.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 13:14
    Thank you Phil. That helps a lot. I'll get back to playing with it.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 13:30
    I starting to be optimistic again.

    Looking at the Ping with a QuickStart board, I see the pulse from the Ping should be long enough. I just need to compensate for the S2's pull-up resistors (I think).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 13:39
    I'm back to being lost.

    The Ping replies with a high pulse based on how long it takes for it to hear an echo.

    How do I monitor the pin as an input watching for a high pulse when the signal line is pulled high?

    Could I pull the line low harder than it's being pulled high?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 13:58
    Using a QuickStart board, I ran the normal Ping object's code:
    outa[Pin]~                                                                    ' Clear I/O Pin
      dira[Pin]~~                                                                   ' Make Pin Output
      outa[Pin]~~                                                                   ' Set I/O Pin
      outa[Pin]~                                                                    ' Clear I/O Pin (> 2 µs pulse)
      dira[Pin]~                                                                    ' Make I/O Pin Input
      waitpne(0, |< Pin, 0)                                                         ' Wait For Pin To Go HIGH
      cnt1 := cnt                                                                   ' Store Current Counter Value
      waitpeq(0, |< Pin, 0)                                                         ' Wait For Pin To Go LOW 
      cnt2 := cnt                                                                   ' Store New Counter Value
      Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1                ' Return Time in µs
    

    This is what the oscilloscope saw (again, this is with a QuickStart board).

    attachment.php?attachmentid=88032&d=1325195663

    It looks like the Ping's reply is plenty long enough, I just don't know how to read it with the S2 since the S2 has pull-up resistors on the signal line.
    556 x 545 - 17K
  • MarkPorterMarkPorter Posts: 9
    edited 2011-12-29 14:01
    Duane, thank you so much for all you have done so far.

    Cheers

    Mark
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 14:52
    Duane,

    You're right. I've got a Ping))) connected to my S2 now, and it looks like more of a challenge with the level converter than I thought it would be. I'm sure it can be made to work, though.

    -Phil
  • MarkPorterMarkPorter Posts: 9
    edited 2011-12-29 14:52
    Duane, just noticed that the design schematics are available for download http://www.parallax.com/go/S2

    Just getting my head around the schematics now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 15:29
    Duane,

    Give this code a try:
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      PING          = 0
    
    OBJ
    
      pst   : "Parallax Serial Terminal"
    
    PUB  start | time
    
      pst.start(9600)
    
      repeat
        dira[PING]~~
        waitcnt(cnt + clkfreq / 100)
        outa[PING]~~
        waitcnt(cnt + clkfreq / 1000)
        outa[PING]~
        time := -cnt
        'waitcnt(cnt + clkfreq / 10000)
        dira[PING]~
        waitpeq(0, constant(1 << PING), 0)
        time += cnt
        pst.dec(time / (clkfreq / 1_000_000) * 1000 / 2903)
        pst. str(string(" mm", 13))
    

    Here's what my output looks like on the scope (Ping side):

    attachment.php?attachmentid=88047&d=1325205008

    The level translator's internal pullups are the issue here, I believe. As a consequence, you have to hold the pin low before you pulse it to provide adequate setup time to the Ping))). At least I think that's what's happening. Also, you can't measure time beginning at the rising edge of the return pulse, since it goes high right away. So the echo times will all be too long by a constant amount (the part marked "normal low time", which my code above does not yet account for).

    -Phil
    640 x 480 - 22K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 16:22
    Phil,

    Thanks for the suggestions and the code. It looks like it should work but so far it doesn't with my S2 and Ping.

    It appears the waitpeq is never met. My logic analyzer makes it look like it should be work.

    Edit: The logic analyzer does not detect the low pulse from the Ping. The pulses shown are all from the Prop.

    attachment.php?attachmentid=88046&d=1325204008

    I've got to help with dinner, so I'll need to look at this some more later. I don't know why my S2 isn't seeing the low signal? I bet this does the trick with just a bit more tweaking.

    It wont be hard to figure out how much time to subtract. I'll just use the Ping with a different Propeller board and measure the delay.

    @Mark, You're welcome. Yes, I've downloaded the schematics already. I've fiddled with the S2 a bit in the past. Now that Phil is helping out, I bet this gets figured out soon.
    784 x 156 - 14K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 16:50
    Duane,

    I had mislabeled the start pulse as "Pulse from Ping)))" in my scope trace. The label has now been corrected.

    Part of the difficulty in interfacing the S2 to the Ping))) is that the level translator circuitry uses 4.7K pullup resistors on the open-drain +5V side. This works fine for low-true logic, but the Ping))) uses high-true logic, with a 10K pull-down resistor. That's why you see an intermediate value on the +5V side when it's not being driven high by the Ping))). Fortunately, at least with the unit I've tested, the Ping))) asserts the output low briefly, when the echo returns, before tri-stating the pin and having it pulled high again by the S2's pullups. This produces a very narrow low pulse that, theoretically, the Prop should be able to catch if it's waiting for it with a waitpeq. At least, that's how it works for me.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 18:04
    Mark,

    Phil posted the datasheet to the level shifter here.

    There are other S2 links in post #12 of my index thread in the test forum (link in signature).


    Phil,

    For some reason my S2 isn't seeing the low pulse. I'll try a few variation to see if I can get it to work.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 18:57
    I appears my Ping isn't pulling the signal line low enough for the S2 to detect it. Darn.

    attachment.php?attachmentid=88053&d=1325212876

    The small dip on the right should be the pulse low from the Ping.

    I'm guessing this might be Ping dependent. I don't know if it matters or not, but my Ping says REV A on it. I don't know if there are any later versions or not.

    My ealier post (#15) with the logic analyzer only showed the pulse from the Propeller. It does not show the pulse from the Ping as I had originally thought. (I need to start measuring these time periods, so I can tell which pulse is which, better than I have been lately.)
    556 x 545 - 18K
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2011-12-29 19:04
    erco wrote: »
    Ken, get an S2 to Mike and step on it! :)

    Gotcha Chief! S2 to be dispatched to Mr. Green on Tuesday morning!

    Thanks for keeping me on track erco!

    Ken Gracey
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 19:24
    Phil,

    I just took a look at the Ping))) webpage. It looks like there's a REV B. I'm curious, is yours a REV A or a REV B?

    Duane
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2011-12-29 19:52
    Duane Degn wrote: »
    Phil,

    I just took a look at the Ping))) webpage. It looks like there's a REV B. I'm curious, is yours a REV A or a REV B?

    Duane

    Duane, the difference [85% certain] is that Revision A uses the SX's internal oscillator and the Revision B uses an external clock.

    Not sure if this will be useful to your research or not.

    Ken Gracey
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-29 20:27
    Ken Gracey wrote: »
    Duane, the difference [85% certain] is that Revision A uses the SX's internal oscillator and the Revision B uses an external clock.

    Not sure if this will be useful to your research or not.

    Ken Gracey
    Thanks for the information Ken.

    I'm curious to see if the version of Ping makes a difference in whether or not it will work with the Scribbler 2.

    I'm hoping others will test their Pings with Phil's code in post #14 and let us know if their Ping works with their S2 and what revision their Ping is.

    If I could be sure Revision B Pings will work with the S2, I'll probably add one or two on to my next Parallax order.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 21:42
    Duane Degn wrote:
    The small dip on the right should be the pulse low from the Ping.
    That pulse should be detectable by the Propeller without a problem. Nevermind: I was mistaking the trigger level for the zero level. Are you using the exact code that I provided in post #14? (FWIW, my Ping)))s are all Rev. A.)

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2011-12-29 21:50
    Using a rev B Ping))), The code from post #14 works with my S2... :thumb:

    It seems the minimum range is about 330 mm, I might have seen it drop to 320 mm, with my hand covering the ping,
    but the numbers scroll very fast, other than that, the mid and max distance numbers seem reasonable...(whatever an mm is...:smile:)


    -Tommy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 22:14
    I'm beginning to get a better feel now for the issue. The return pulse, as the Propeller sees it through the level shifter, may or may not go low enough to detect. The root of the problem is that the Ping))) tri-states the pin too quickly after the echo for the voltage on the pin to go all the way to zero before surrendering it to the pullups. Here's what the return pulse looks like on my scope. The yellow trace is form the Ping))) side of the level shifter; the blue trace at the Propeller pin:

    attachment.php?attachmentid=88060&d=1325225481

    As you can see, the low point of the pulse at the Propeller pin is right at the logic threshold, so it may or may not register.

    This is not a design defect per se but, rather a conspiracy of otherwise good design objectives that appear to be at odds with each other:
    1. From the Ping))) side: release the line as soon as possible to avoid bus conflicts.

    2. From the S2 side: put a cap on the level shifter output to reduce the effects of noise and/or to increase rise times enough to pass FCC emissions requirements.

    Frankly, I do not see a pure software fix for the problem on the S2 side. It could probably be "fixed" in the Ping))) firmware by holding the pin low longer before tri-stating it. Additional circuitry between the S2 and Ping))) is also a possibility. I tried additional pull-down resistance, though, without success.

    -Phil
    640 x 480 - 9K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 22:59
    Duane,

    If you're comfortable doing some soldering on the Ping))), you can probably work around the problem. Here is what the circuitry looks like at the S2/Ping))) interface:

    attachment.php?attachmentid=88062&d=1325228285

    Notice that 510-ohm resistor in series with the Ping))) signal lead. That resistor, in combination with the 1nF cap on the S2, determines the fall time of the pulse from the Ping))) and, hence, how low it will go before the pin is tri-stated. I piggy-backed a 470-ohm resistor on top of the 510-ohm resistor (top of Ping))) PCB, next to the SIG pin), effectively halving the output pulse's fall time. Here's what the two signals look like now:

    attachment.php?attachmentid=88061&d=1325228285

    The signal at the Propeller pin goes all the way down to 0.5V now, rather than being on the hairy edge of the logic threshold.

    -Phil
    640 x 480 - 11K
    494 x 267 - 2K
  • MarkPorterMarkPorter Posts: 9
    edited 2011-12-30 00:10
    Duane, Phil & Ken,

    Many thanks for all the work you've done since I asked my original question, I had hoped it would be an easier task to hack the S2.

    Although the side of S2 box states that the S2 is user-hackable & would allow you to add ultrasonic sensors etc, I hadn't imagined it would such 'mission'. Shame I drilled a hole in the upper case of my S2 & added nice grommet & red mini breadboard to the top of the chassis - LOL.

    Part of me wishes I'd have purchased a Boe-Bot this Xmas, as making the jump from Arduino to the Propeller S2 hasn't been quite an easy transition as I had hoped for. The user guide included with the S2 is more of a guide to the Demo Programs, rather than a true user guide to the S2.

    Don't get me wrong, so far I love the S2 for what it does with the demo program's, but I want to go beyond the demo programs & I'm finding that information regarding both programming & hacking the S2 is thin on the ground & I'm beginning to think I jumped in too deep before I knew what I was letting myself in for.

    I need to go back to basics and play with the S2 GUI then learn to program in spin before I even consider hacking my S2. So sorry to have put to so much trouble.

    I need to find both decent guide to both the S2 GUI & the Propeller tool code editor, can anyone point me in the right direction for resources?

    Regards,

    Mark
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-30 00:23
    MarkPorter wrote:
    I need to find both decent guide to both the S2 GUI & the Propeller tool code editor, can anyone point me in the right direction for resources?
    When running the GUI, click on the large ? to bring up a help page in your browser. In addition to the GUI topics, you can click on the "S2 Spin Object Documentation" link at the bottom of the left-hand panel to get info on programming the S2 in Spin.

    -Phil
  • MarkPorterMarkPorter Posts: 9
    edited 2011-12-30 01:37
    When running the GUI, click on the large ? to bring up a help page in your browser. In addition to the GUI topics, you can click on the "S2 Spin Object Documentation" link at the bottom of the left-hand panel to get info on programming the S2 in Spin.

    -Phil

    Thanks Phil, had a minor issue as my default browser is Chrome & doesn't display. Switched my default browser back to IE8 & the help page is now working perfectly,

    Thank you

    Mark
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-30 07:26
    If you're comfortable doing some soldering on the Ping))), you can probably work around the problem. Here is what the circuitry looks like at the S2/Ping))) interface:

    Phil, Thanks for the new information. I'll likely try your mod with my Ping.

    I notice there are four test points on the Ping. I'm guessing those can be used to update its firmware. I wonder how hard it would be to load new firmware into the Ping?

    I still have some wires soldered directly to my S2's Prop chip. I might just use one of those to interface with the Ping. I'd rather use a method that would be easy for others to reproduce though (in case I come up with some cool application for using the Ping with the S2).

    Thanks again for your help.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-30 08:35
    MarkPorter wrote: »
    So sorry to have put to so much trouble.
    Mark, You're mistaking "fun" for "trouble". Thanks for the fun.
    MarkPorter wrote: »
    Although the side of S2 box states that the S2 is user-hackable & would allow you to add ultrasonic sensors etc, I hadn't imagined it would such 'mission'. Shame I drilled a hole in the upper case of my S2 & added nice grommet & red mini breadboard to the top of the chassis - LOL.
    Yeah, I'm a bit disappointed not to be able to easily use a Ping with the S2. Your hole in the top is probably a good idea. I've stripped all the screw holes in my S2 from taking off the cover so many times.

    There should be lots of other sensors that can be used with the S2. One of these ultrasonic sensors will likely work without modification. I have one and I'll try it with my S2 (as soon as I can find the sensor (I saw it a couple of days ago so I know it's somewhere around here)). Servos should be easy to use with the S2. If you have other sensors there's a good chance I'll also have one. I'll help you get any other sensors (if I have one) working with the S2. If you're thinking of purchasing a sensor, again, it's likely I already have one and I can try it out with my S2 before you purchase one yourself.
    MarkPorter wrote: »
    Part of me wishes I'd have purchased a Boe-Bot this Xmas, as making the jump from Arduino to the Propeller S2 hasn't been quite an easy transition as I had hoped for. The user guide included with the S2 is more of a guide to the Demo Programs, rather than a true user guide to the S2.
    <snip>
    I need to find both decent guide to both the S2 GUI & the Propeller tool code editor, can anyone point me in the right direction for resources?

    Mark, Make sure you download the full Propeller Tool. It's the first download on this page. It has the Propeller Education Kit (PEK) and Propeller Manual (and other stuff) under the help menu. I think the Propeller Tool that comes with the S2 GUI doesn't have all the help documents since it's just intended to show the Spin file generated by the GUI (which is very useful and cool).

    The PEK walks your through using the Propeller. Not all of it will apply to the S2 though.

    You might want to consider getting a QuickStart (QS) board as part of your Propeller education. It's an easy way to start programming the Propeller.

    The Prop takes a bit of learning to use well, but it is really (IMO) the perfect microcontroller for robots.

    Make sure and keep asking questions here or in the robot forum.
Sign In or Register to comment.