PING)) Sensors.. Communication Help

PeterH:

husein06:

HazardsMind:
try this:

(duration1, duration) = pulseIn((pingPin2,pingPin), HIGH);

It didn't work!

Well of course it didn't work! It was complete nonsense.

I don't understand what you're trying to achieve or how multiple ping sensors helps you achieve it. Are you trying to detect obstacles in multiple directions, or something? If so, the easiest way to read from multiple receivers is to pretend you have one sender and one receiver and do one 'ping' in the usual way, then do exactly the same thing with the sender and the other receiver. This means you will send out a separate ping for each receiver, but I don't see any harm in that.

The alternative is to use a completely different method to get the response from the receiver, which enables you to receive from two inputs simultaneously. That's going to be much harder to do, and is not the approach I'd recommend. But if you have a remote sender and you're trying to use stereo receivers to determine the direction to the source, then you will need to read them both simultaneously to see which one receives the pulse first. In this case the exact timing might not matter (you can't determine range unless you know when the pulse was sent) and all you'd care about was which receiver picked the pulse up first. I suspect you could do that using interrupts and direct port access to grab the state of both inputs with minimal latency, but it's going to need an approach that's very different to the conventional ping range finder.

I'm not an expert at Arduino(how do you do direct port access), can you please help me figure out how to do that? Are you referring to something like this:(code)

The main goal is, I'm trying to figure out what's the distance(or time) difference of the 2 receivers that are located on the robot, so I can adjust the motors and drive.

pinMode(ultraSoundSignal1, INPUT); // Switch signalpin to input
pinMode(ultraSoundSignal2, INPUT); // Switch signalpin to input
val1 = digitalRead(ultraSoundSignal1); // Append signal value to val
val2 = digitalRead(ultraSoundSignal2); // Append signal value to val

while((val1 == LOW) || (val2 == LOW) ) { // Loop until pin reads a high value
 if (val1 == LOW){
   val1 = digitalRead(ultraSoundSignal1);
   }
 if (val2 == LOW){
   val2 = digitalRead(ultraSoundSignal2);
  }
}

while((val1 == HIGH) || (val2 == HIGH)) { // Loop until pin reads a high value
 if (val1 == HIGH){
   val1 = digitalRead(ultraSoundSignal1);
   timecount1 = timecount1 + 1;
 }
 if (val2 == HIGH){
   val2 = digitalRead(ultraSoundSignal2);
   timecount2 = timecount2 + 1;
 }
}

 
//  val1 = digitalRead(ultraSoundSignal1);
 // val2 = digitalRead(ultraSoundSignal2);
//  timecount1 = timecount1 +1;            // Count echo pulse time
//}


/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */

ultrasoundValue1 = timecount1; // Append echo pulse time to ultrasoundValue
ultrasoundValue2 = timecount2;
//ultrasoundValuee = timecountt; // Append echo pulse time to ultrasoundValue
serialWrite('S'); // Example identifier for the sensor
printInteger(ultrasoundValue2 - ultrasoundValue1);
serialWrite(10);
serialWrite(13);