Main Site Documentation

Cerbuino + Parallax Ping


#1

About a year ago i posted about my troubles with this…wondering if anyone ever had success with getting this to work with a Cerbuino board? I’ve manged to get the ping going on just about ever board i have except for the Cerbuino.


#2

@ dizzy - I’m relatively new around here so maybe my search skills need some work, but I couldn’t find your old post. Can you provide a URL. Secondly, does this thread:

https://www.ghielectronics.com/community/forum/topic?id=1587&page=2

and this codeshare help any?

https://www.ghielectronics.com/community/codeshare/entry/123

What other boards than cerbuino have you tried?


#3

Hi Jeff…
this was the post where i raised the issue: https://www.ghielectronics.com/community/forum/topic?id=9009

I have tried that particular codeshare…but can not get it to work with a Cerbuino.


#4

interesting…the problem seems to occur only when i use a servo. if i comment out the code that initializes the Servo (which is using pin D9)…this issue goes away. I wonder if this happens with other boards as well or just the Cerbuino.
More importantly…why does this happen and how do i fix this or work around it?


#5

Can you elaborate on how everything is wired up, and the simplest code example you can find? When I hear things like that, I instantly think there’s a pin-use conflict (or possibly in this case, a PWM mismatch?)


#6

i will do so tonight when i get home. After some additional testing, it seems the issue is related to trying to get a reading from the Ping sensor while the servo is moving or has just completed moving. What’s strange is that i can reproduce without programmatically moving the servo…
my code initially centers the servo. if i then use my finger to apply just little pressure to the servo, i feel the the resistance (presumably the servo is trying to maintain the center positioning) and then try to take a reading from the Ping while doing this, the issue occurs. The issue here is that infinite do/while loop in the ParallaxPing implementation.

the signal pin for the Ping is d3, while the servo is D10 (PWM) pin.


#7

Let me see if I can work around it.


#8

thank you Architect. Does that mean you are able to reproduce the issue?


#9

I’ll dust off my Ping and will try it.


#10

power power power.

Can you elaborate on your failure again? Can you confirm that if you leave the servo centred after setup, then the ping))) works fine, but as soon as you start putting pressure on the servo your readings get thrown off?

To me that reeks of not enough power being supplied. As you torque down the servo, it draws more current and the voltage drops to the ping))) to a point that affects the readings


#11

The failure is…At times when the servo is moving or has just moved, and i attempt to take a distance reading from the Ping, the code below from the PrallaxPing class never exits:

 //Wait for start of the echo pulse.
            do
            {
                high = _pin.Read();
            }
            while (!high);

Here are some images. As you can see there is a bit going on here. But if you look at the close up in the last picture of the Cerbuino, D3 is the signal line for the Ping. D9 and D10 are the signal line for tor the Pan/Tilt servo.

Right now for testing purposes, i am powering the Cerbuino via usb. The cerbuino handles the sensors (2 IR, one Ping), the and the pan/tilt, and communicates with the arduino via serial. The arduino handles the motors/movement. The motor controller is powered separately and also powers the wifi camera.


#12

It can be a timing issue. Do you have multiple threads in your app?
Also if you have logic analyser can you check ping sensor line. There should be two pulses per measurement.


#13

I think Brett is correct, this is power related.
When i add an external power source (as opposed to USB only), the issue doesn’t happen nearly as much. It still occurs occasionally however when all components are connected and the servo hits its max range. I noticed when the servo at the far end of it’s movement range, there is a vibrating sound coming from the servo - my guess is the servo is drawing more current trying to push beyond what it can go physically.

Some other observations…
-I notice that while the servo is moving, the current draw is anywhere between 30-145ma.
-If no external power source is used, the voltage drop across the Ping is 4.53 on initialization. As soon as the servo is moved it drops to around ~4.38-4.45 and remains in that range.
-When an external power source is used, the voltage is ~4.67 on initialization and fluctuates between 4.64-4.67 while servo is moving.

To try and work around this…i think i may try to ensure that the servo does not move beyond it’s physical limits (as it seems that’s when most of the drop happens) and add some counter or timeout logic to ensure the do/while in the ParallaxPing implementation is never infinite - that will at least prevent blocking and allow retry logic.

Any other suggestions?


#14

@ dizzy - if your servo is buzzing or vibrating it generally means it has hit the mechanical stop.
if you continue to do that it will eventually cook it.


#15

@ justin - thanks. I notice that even when the servo is centered there is a slight vibration that can be heard.


#16

@ dizzy -

Try something like this.

Replace:


            //Wait for start of the echo pulse.
             do
             {
                 high = _pin.Read();
             }
             while (!high);

             //Measure current time
             long startTime = System.DateTime.Now.Ticks;

             // Wait for end of echo pulse.
             while (high) 
             {
                 high = _pin.Read(); 
             } 

with this (not tested):


                long startTime = System.DateTime.Now.Ticks;

                int timeout = 0;

                //Wait for start of the echo pulse.
                do
                {
                    high = _pin.Read();

                    timeout = (int)(System.DateTime.Now.Ticks - startTime) / TicksPerMicrosecond;

                    //Taking too long (3 seconds)
                    if (timeout > 3000000)
                        return -1;

                }
                while (!high);

                //Measure current time
                startTime = System.DateTime.Now.Ticks;

                // Wait for end of echo pulse.
                while (high)
                {
                    high = _pin.Read();

                    timeout = (int)(System.DateTime.Now.Ticks - startTime) / TicksPerMicrosecond;

                    //Taking too long (3 seconds)
                    if (timeout > 3000000)
                        return -1;
                }



#17

Thanks Architect. I opted for a completely non-blocking implementation using threading and call backs.

I do have a question regarding dealing with power issues like this…is there anyway to ensure that your components receive a constant and expected voltage? Would some capacitors or voltage regulator be of use in this case?


#18

the standard voltage regulators onboard these devices are capable of providing 800mA when they have a capable input voltage and current capacity. When you power the board thru USB, there’s a good chance that this is not “capable” of maxxing out the regulators but you’ll max out the current capability from USB first. USB only has to provide 500mA at 5v, but often times the tolerance on that drops the voltage down to a lower level. So adding additional regulators, capacitors or anything else will not assist - with a low input voltage, or a restricted current, you can’t generate more current than you have. The best solution is a powered hub, because they typically have capacity to provide much more current (they have a dedicated power supply, after all) or to use supplemental power using your barrel jack.


#19

Thanks brett. It sounds like i’ll the solution here is to use an external battery of atleast 7.2v.
I looked at the spec for the Ping and it requres 35ma of currents. That would explain the issues with not being able to get proper readings while the servo is moving…since i’m seeing amperage below that at times when using just USB and the servos are moving.


#20

it’s more likely the voltage sag when the servo draws what it needs that’s the cause of your issue. in this case, a capacitor over the power to the Ping))) might actually help buffer it from the sag - but really it seems your power supplied over USB is so close to the tipping point that you’ll only have additional headaches and an external supply with more grunt will just remove that as a concern.